dotfiles/data/nvim/init.lua

381 lines
8.6 KiB
Lua
Raw Normal View History

2023-03-12 03:28:32 +00:00
-- https://neovim.io/doc/user/lua-guide.html
vim.opt.completeopt = { "menuone", "noinsert", "noselect" }
2022-09-21 03:37:23 +00:00
vim.opt.swapfile = false
vim.opt.title = true
vim.opt.virtualedit = "block"
vim.opt.whichwrap = "<,>,[,]"
2023-05-19 09:43:12 +00:00
-- Case character
vim.opt.ignorecase = true
vim.opt.smartcase = true
2022-09-21 03:37:23 +00:00
-- Line number
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.scrolloff = 4
-- Tab
vim.opt.tabstop = 4
vim.opt.shiftwidth = 4
vim.opt.expandtab = true
-- Wrap
vim.opt.breakindent = true
2023-03-20 06:22:29 +00:00
-- Clipboard support
vim.opt.clipboard = "unnamedplus"
2023-03-20 06:22:29 +00:00
2022-09-21 03:37:23 +00:00
-- Truecolor
if vim.env.COLORTERM == "truecolor" then
vim.opt.termguicolors = true
end
-- Mouse support
vim.opt.mouse = "a"
-- Workaround
-- https://github.com/neovim/neovim/issues/16416
vim.keymap.set("i", "<C-c>", "<Esc>")
-- Keymap
vim.keymap.set("n", ";", "<leader>", { remap = true })
2023-05-14 14:05:33 +00:00
vim.keymap.set("n", "q", ":q<CR>")
2023-04-18 03:52:55 +00:00
-- Keymap for plugin
2023-06-12 07:30:44 +00:00
vim.keymap.set("n", "<leader>f", ":FZF<CR>")
2023-06-12 07:04:24 +00:00
vim.keymap.set("n", "<leader>rg", ":FZFRg<CR>")
vim.keymap.set("n", "<leader>cm", ":FZFCommands<CR>")
2022-09-21 03:37:23 +00:00
vim.keymap.set("n", "<C-n>", ":NvimTreeToggle<CR>")
vim.keymap.set("n", "<leader>n", ":NvimTreeFindFile<CR>")
vim.keymap.set("n", "<leader>tr", ":lua MiniTrailspace.trim()<CR>")
2023-07-01 14:58:55 +00:00
vim.keymap.set("n", "<leader>lr", ":LspRestart<CR>")
2022-09-21 03:37:23 +00:00
2023-06-12 07:04:24 +00:00
-- Use plugin fzf.vim
vim.g.fzf_command_prefix = "FZF"
2023-04-12 07:09:54 +00:00
-- Use plugin nvim-tree.lua
vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
2023-03-11 14:16:39 +00:00
-- Use plugin neoformat
vim.g.neoformat_basic_format_trim = 1
2023-03-11 14:16:39 +00:00
vim.g.neoformat_enabled_go = { "gofumpt" }
vim.g.shfmt_opt = "-ci"
-- Use plugin copilot
2022-09-21 03:37:23 +00:00
vim.g.copilot_filetypes = {
["*"] = false,
2023-06-02 16:43:22 +00:00
c = true,
cpp = true,
2022-09-21 03:37:23 +00:00
go = true,
2023-06-02 16:43:22 +00:00
java = true,
2023-02-25 14:35:42 +00:00
json = true,
2023-02-28 09:00:43 +00:00
lua = true,
2023-02-28 03:34:59 +00:00
make = true,
2023-06-02 16:43:22 +00:00
markdown = true,
2022-09-21 03:37:23 +00:00
proto = true,
2023-02-25 14:35:42 +00:00
python = true,
2023-02-28 09:00:43 +00:00
toml = true,
2023-03-06 04:25:25 +00:00
yaml = true,
2022-09-21 03:37:23 +00:00
}
2023-06-17 04:20:37 +00:00
-- https://github.com/folke/lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
2023-06-17 04:53:00 +00:00
"--branch=stable",
2023-06-17 04:20:37 +00:00
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
2022-09-21 03:37:23 +00:00
2023-06-17 04:20:37 +00:00
require("lazy").setup({
2023-06-30 08:08:46 +00:00
-- Colorschemes
-- https://github.com/catppuccin/nvim
2023-06-29 18:04:45 +00:00
{
2023-06-30 08:08:46 +00:00
"catppuccin/nvim",
name = "catppuccin",
lazy = false,
priority = 1000,
2023-06-29 18:04:45 +00:00
config = function()
2023-06-30 08:08:46 +00:00
require("catppuccin").setup({
flavour = "mocha",
integrations = {
mini = true,
},
})
vim.cmd("colorscheme catppuccin")
2023-06-29 18:04:45 +00:00
end,
},
2023-04-18 03:52:55 +00:00
-- https://github.com/junegunn/fzf.vim
2023-06-19 03:33:50 +00:00
"junegunn/fzf",
2023-06-17 04:20:37 +00:00
"junegunn/fzf.vim",
2022-09-21 03:37:23 +00:00
-- https://github.com/nvim-lualine/lualine.nvim
2023-06-17 04:20:37 +00:00
{
2022-09-21 03:37:23 +00:00
"nvim-lualine/lualine.nvim",
config = function()
require("lualine").setup({
options = {
icons_enabled = false,
2023-03-26 16:39:01 +00:00
theme = "auto",
2022-09-21 03:37:23 +00:00
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
},
extensions = { "fzf", "nvim-tree" },
})
2022-10-31 16:01:33 +00:00
-- Disable showmode when use lualine
vim.opt.showmode = false
2022-09-21 03:37:23 +00:00
end,
2023-06-17 04:20:37 +00:00
},
2022-09-21 03:37:23 +00:00
2023-04-12 07:09:54 +00:00
-- https://github.com/nvim-tree/nvim-tree.lua
2023-06-17 04:20:37 +00:00
{
2023-04-12 07:09:54 +00:00
"nvim-tree/nvim-tree.lua",
2022-09-21 03:37:23 +00:00
config = function()
require("nvim-tree").setup({
renderer = {
2023-04-12 07:09:54 +00:00
group_empty = true,
2023-07-01 08:07:07 +00:00
root_folder_label = false,
indent_width = 1,
2023-02-07 10:10:22 +00:00
icons = {
show = {
file = false,
folder = false,
folder_arrow = false,
git = false,
modified = false,
},
},
2022-09-21 03:37:23 +00:00
},
2023-05-24 07:10:08 +00:00
filters = {
2023-06-29 03:28:18 +00:00
custom = {
2023-07-01 08:07:07 +00:00
"^.git$",
"^.DS_Store",
".out",
".class",
2023-06-29 03:28:18 +00:00
},
2023-05-24 07:10:08 +00:00
},
2022-09-21 03:37:23 +00:00
})
end,
2023-06-17 04:20:37 +00:00
},
2022-09-21 03:37:23 +00:00
2023-06-30 17:43:55 +00:00
-- https://github.com/hrsh7th/nvim-cmp
{
"hrsh7th/nvim-cmp",
event = "InsertEnter",
dependencies = {
"neovim/nvim-lspconfig",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
},
config = function()
local cmp = require("cmp")
cmp.setup({
mapping = cmp.mapping.preset.insert({
["<C-Space>"] = cmp.mapping.complete(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" },
}, {
{ name = "buffer" },
}),
})
end,
},
2022-09-21 03:37:23 +00:00
-- https://github.com/lukas-reineke/indent-blankline.nvim
2023-06-17 04:20:37 +00:00
{
2022-09-21 03:37:23 +00:00
"lukas-reineke/indent-blankline.nvim",
config = function()
2023-06-29 11:12:40 +00:00
require("indent_blankline").setup()
2022-09-21 03:37:23 +00:00
end,
2023-06-17 04:20:37 +00:00
},
2022-09-21 03:37:23 +00:00
-- https://github.com/lewis6991/gitsigns.nvim
{
"lewis6991/gitsigns.nvim",
config = function()
require("gitsigns").setup({
2023-07-01 09:02:34 +00:00
signs = {
untracked = { text = "" },
},
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then
return "]c"
end
vim.schedule(function()
gs.next_hunk()
end)
return "<Ignore>"
end, { expr = true })
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
end,
})
end,
},
2023-04-26 05:57:22 +00:00
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim
2023-06-17 04:20:37 +00:00
{
2023-06-21 09:35:14 +00:00
"echasnovski/mini.nvim",
2023-02-28 09:00:43 +00:00
config = function()
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-bracketed.md
2023-06-17 04:33:05 +00:00
require("mini.bracketed").setup({
comment = { suffix = "", options = {} },
})
2023-02-28 09:00:43 +00:00
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-comment.md
2023-06-17 04:33:05 +00:00
require("mini.comment").setup()
2023-03-01 09:19:40 +00:00
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-cursorword.md
2023-04-02 18:10:10 +00:00
require("mini.cursorword").setup()
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-surround.md
2023-04-02 18:17:38 +00:00
require("mini.surround").setup()
2023-06-21 09:35:14 +00:00
-- https://github.com/echasnovski/mini.nvim/blob/main/readmes/mini-trailspace.md
2023-05-03 17:12:34 +00:00
require("mini.trailspace").setup()
end,
2023-06-17 04:20:37 +00:00
},
2023-05-03 17:12:34 +00:00
2022-09-21 03:37:23 +00:00
-- Programming languages
-- https://github.com/sbdchd/neoformat
2023-06-17 04:20:37 +00:00
"sbdchd/neoformat",
2022-09-21 03:37:23 +00:00
-- https://github.com/nvim-treesitter/nvim-treesitter
2023-06-17 04:20:37 +00:00
{
"nvim-treesitter/nvim-treesitter",
2023-06-17 16:07:41 +00:00
build = {
":TSUpdate",
},
config = function()
require("nvim-treesitter.configs").setup({
ensure_installed = {
"go",
"json",
"yaml",
"toml",
"lua",
},
})
end,
2023-06-17 04:20:37 +00:00
},
-- https://github.com/nvim-treesitter/nvim-treesitter-context
2023-06-17 04:20:37 +00:00
{
"nvim-treesitter/nvim-treesitter-context",
config = function()
require("treesitter-context").setup({
enable = true,
max_lines = 2,
})
end,
2023-06-17 04:20:37 +00:00
},
-- https://github.com/neovim/nvim-lspconfig
{
"neovim/nvim-lspconfig",
config = function()
2023-07-01 08:49:15 +00:00
local lspconfig = require("lspconfig")
2023-06-29 11:26:53 +00:00
-- Go
-- https://github.com/golang/tools/blob/master/gopls/doc/vim.md
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md
2023-07-01 08:49:15 +00:00
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#gopls
lspconfig.gopls.setup({
settings = {
gopls = {
gofumpt = true,
semanticTokens = true,
},
},
})
2023-06-29 11:26:53 +00:00
-- Proto
2023-07-01 08:49:15 +00:00
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#bufls
2023-06-29 10:40:46 +00:00
lspconfig.bufls.setup({})
2023-07-01 08:49:15 +00:00
-- Lua
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#lua_ls
lspconfig.lua_ls.setup({
settings = {
Lua = {
runtime = {
version = "LuaJIT",
},
diagnostics = {
globals = { "vim" },
},
format = {
-- Prefer Neoformat with stylua
enable = false,
},
workspace = {
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false,
},
},
},
})
2023-06-30 17:27:29 +00:00
-- General
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next)
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("UserLspConfig", {}),
callback = function(ev)
vim.bo[ev.buf].omnifunc = "v:lua.vim.lsp.omnifunc"
local opts = { buffer = ev.buf }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, opts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, opts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, opts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, opts)
vim.keymap.set("n", "<F2>", vim.lsp.buf.rename, opts)
2023-06-30 17:27:29 +00:00
vim.keymap.set({ "n", "v" }, "<space>ca", vim.lsp.buf.code_action, opts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, opts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, opts)
end,
})
end,
},
2022-09-21 03:37:23 +00:00
-- https://github.com/github/copilot.vim
2023-06-17 04:20:37 +00:00
"github/copilot.vim",
})