feat: plugin support

feat: treesitter plugin support
This commit is contained in:
Young Xu 2023-02-12 01:44:33 +08:00
parent 47818963c1
commit 4a37ac120e
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
34 changed files with 722 additions and 221 deletions

32
README.md Normal file
View File

@ -0,0 +1,32 @@
## neovim
一个neovim配置
### usage
安装插件管理工具
```bash
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
```
安装依赖
```bash
sudo dnf install fd-find ripgrep -y
go install github.com/jesseduffield/lazygit@latest
```
### 记忆项
代码折叠
- zo - 在光标下打开折叠
- zc - 在光标下关闭折叠
- za - 切换光标下打开、关闭状态
- zr - 将所有折叠打开一层
- zm - 将所有折叠关闭一层
- zR - 打开全部折叠
- zM - 关闭全部折叠

View File

@ -19,22 +19,38 @@ require("plugins.notify")
require("plugins.telescope")
-- 缩进线
require("plugins.indent-blackline")
-- 重命名工具
require("plugins.renamer")
-- git管理
require("plugins.gitsigns")
-- 终端管理
require("plugins.terminal")
-- 错误列表
require("plugins.trouble")
-- 代码大纲
require("plugins.aerial")
-- 跳转
require("plugins.leap")
-- 代码高亮
require("plugins.treesitter")
-- LSP管理
require("plugins.mason")
require("lsp.init")
require("lsp.lua")
require("lsp.go")
require("lsp.yaml")
require("lsp.json")
require("lsp.toml")
require("lsp.protocol")
require("lsp.bash")
require("lsp.docker")
require("lsp.html")
require("lsp.volar")
require("plugins.lspsaga")
-- golang ide config
require("plugins.go")
-- 格式化
require("plugins.format")
-- 优化启动速度
require("plugins.impatient")
-- TODO 管理
require("plugins.todo")
-- 按键绑定
require("basics.keybinding")

View File

@ -3,19 +3,35 @@
"/home/x/.config/nvim",
"/home/x/.local/share/nvim/site",
"/home/x/.local/share/nvim/site/pack/packer/start/Comment.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/aerial.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/alpha-nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/auto-save.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/beacon.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/bufferline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/catppuccin",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-buffer",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-cmdline",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-path",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-vsnip",
"/home/x/.local/share/nvim/site/pack/packer/start/fine-cmdline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/flit.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/gitsigns.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/go.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/gruvbox.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/guihua.lua",
"/home/x/.local/share/nvim/site/pack/packer/start/impatient.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/indent-blankline.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lazygit.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/leap.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lspsaga.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/lualine.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/mason-lspconfig.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/mason.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/navigator.lua",
"/home/x/.local/share/nvim/site/pack/packer/start/nui.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/null-ls.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-autopairs",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-cmp",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-lspconfig",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-notify",
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-tree.lua",
@ -23,20 +39,30 @@
"/home/x/.local/share/nvim/site/pack/packer/start/nvim-web-devicons",
"/home/x/.local/share/nvim/site/pack/packer/start/packer.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/plenary.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/project.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/renamer.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/telescope.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/todo-comments.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/toggleterm.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/tokyonight.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/trouble.nvim",
"/home/x/.local/share/nvim/site/pack/packer/start/vim-illuminate",
"/home/x/.local/share/nvim/site/pack/packer/start/vim-vsnip",
"/home/x/.local/share/nvim/site/pack/packer/start/which-key.nvim",
"/usr/share/nvim/runtime",
"/usr/share/nvim/runtime/pack/dist/opt/matchit",
"/home/x/.local/share/nvim/site/pack/packer/start/catppuccin/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-buffer/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-cmdline/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-path/after",
"/home/x/.local/share/nvim/site/pack/packer/start/cmp-vsnip/after",
"/home/x/.local/share/nvim/site/pack/packer/start/go.nvim/after",
"/usr/share/vim/vimfiles/",
"${3rd}/luassert/library",
"${3rd}/luv/library",
"${3rd}/lfs/library"
],
"diagnostics.globals": [
"vim",
"lfs"
]
}
],
"workspace.checkThirdParty": false
}

View File

@ -70,5 +70,13 @@ vim.o.showmode = false
vim.opt.clipboard = "unnamedplus"
-- Some servers have issues with backup files, see #649
vim.opt.backup = false
vim.opt.swapfile = false
vim.opt.writebackup = false
vim.opt.undofile = true
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
-- 开启 Folding
vim.wo.foldmethod = "expr"
vim.wo.foldexpr = "nvim_treesitter#foldexpr()"
-- 默认不要折叠
-- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
vim.wo.foldlevel = 99

View File

@ -2,36 +2,175 @@ vim.g.mapleader = " "
vim.g.maplocalleader = " "
local map = vim.api.nvim_set_keymap
local noreopt = {noremap = true, silent = true }
local noreopt = { noremap = true, silent = true }
-- 友好正常模式命令框
map("n", ":", "<cmd>FineCmdline<CR>", noreopt)
-- 重置窗口大小
map("n", "<C-Up>", ":resize -2<CR>", noreopt)
map("n", "<C-Down>", ":resize +2<CR>", noreopt)
map("n", "<C-Left>", ":vertical resize -2<CR>", noreopt)
map("n", "<C-Right>", ":vertical resize +2<CR>", noreopt)
-- 窗口切换
map("n", "<C-h>", "<C-w>h", noreopt)
map("n", "<C-j>", "<C-w>j", noreopt)
map("n", "<C-k>", "<C-w>k", noreopt)
map("n", "<C-l>", "<C-w>l", noreopt)
-- 分屏
map("n", "<leader>sv", ":vsp<CR>", noreopt)
map("n", "<leader>sh", ":sp<CR>", noreopt)
-- 代码块移动
map("n", "<A-j>", "<Esc>:m .+1<CR>==gi", noreopt)
map("n", "<A-k>", "<Esc>:m .-2<CR>==gi", noreopt)
map("v", "<", "<gv", noreopt)
map("v", ">", ">gv", noreopt)
map("v", "<A-j>", ":m .+1<CR>==", noreopt)
map("v", "<A-k>", ":m .-2<CR>==", noreopt)
map("x", "J", ":move '>+1<CR>gv-gv", noreopt)
map("x", "K", ":move '<-2<CR>gv-gv", noreopt)
map("x", "<A-j>", ":move '>+1<CR>gv-gv", noreopt)
map("x", "<A-k>", ":move '<-2<CR>gv-gv", noreopt)
-- 快所退出
map("n", "q", ":wq<CR>", noreopt)
map("n", "qn", ":q!<CR>", noreopt)
map("n", "qq", ":qa!<CR>", noreopt)
map("i", "jk", "<ESC>", noreopt)
-- git 管理
map('n', '<leader>lg', ':LazyGit<CR>', noreopt)
map("n", "<leader>lg", ":LazyGit<CR>", noreopt)
-- 开关文件树
map('n', '<leader>t', ':NvimTreeToggle<CR>', noreopt)
map("n", "<leader>t", ":NvimTreeToggle<CR>", noreopt)
-- 文件页切换
map('n', '<leader>ll', ':BufferLineCyclePrev<CR>', noreopt)
map('n', '<leader>rr', ':BufferLineCycleNext<CR>', noreopt)
map("n", "<leader>ll", ":BufferLineCyclePrev<CR>", noreopt)
map("n", "<leader>rr", ":BufferLineCycleNext<CR>", noreopt)
map("n", "<leader>pc", ":BufferLinePickClose<CR>", noreopt)
-- 模糊搜索
map('n', '<leader>ff', '<Cmd>Telescope find_files<CR>', noreopt)
map('n', '<leader>fg', '<Cmd>Telescope live_grep<CR>', noreopt)
map("n", "<leader>ff", "<Cmd>Telescope find_files<CR>", noreopt)
map("n", "<leader>fg", "<Cmd>Telescope live_grep<CR>", noreopt)
-- 重命名
vim.keymap.set({'i','n','v'}, '<F6>', '<cmd>lua require("renamer").rename()<cr>')
vim.keymap.set({ "i", "n", "v" }, "<F6>", '<cmd>lua require("renamer").rename()<cr>')
-- 终端管理
map('n', '<leader>te', '<Cmd>ToggleTerm<CR>', noreopt)
map("n", "<leader>te", "<Cmd>ToggleTerm<CR>", noreopt)
function _G.set_terminal_keymaps()
local opts = {buffer = 0}
vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
local opts = { buffer = 0 }
vim.keymap.set("t", "<esc>", [[<C-\><C-n>]], opts)
vim.keymap.set("t", "jk", [[<C-\><C-n>]], opts)
vim.keymap.set("t", "<C-h>", [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set("t", "<C-j>", [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set("t", "<C-k>", [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set("t", "<C-l>", [[<Cmd>wincmd l<CR>]], opts)
end
function _G.set_terminal_keymaps_insert()
vim.keymap.set('n', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set('n', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set('n', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set('n', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
local opts = { buffer = 0 }
vim.keymap.set("n", "<C-h>", [[<Cmd>wincmd h<CR>]], opts)
vim.keymap.set("n", "<C-j>", [[<Cmd>wincmd j<CR>]], opts)
vim.keymap.set("n", "<C-k>", [[<Cmd>wincmd k<CR>]], opts)
vim.keymap.set("n", "<C-l>", [[<Cmd>wincmd l<CR>]], opts)
end
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
vim.cmd('lua set_terminal_keymaps_insert()')
vim.cmd("autocmd! TermOpen term://* lua set_terminal_keymaps()")
vim.cmd("lua set_terminal_keymaps_insert()")
-- 错误列表UI
map("n", "<leader>xx", "<cmd>TroubleToggle<cr>", noreopt)
map("n", "<leader>xw", "<cmd>TroubleToggle workspace_diagnostics<cr>", noreopt)
map("n", "<leader>xd", "<cmd>TroubleToggle document_diagnostics<cr>", noreopt)
map("n", "<leader>xl", "<cmd>TroubleToggle loclist<cr>", noreopt)
map("n", "<leader>xq", "<cmd>TroubleToggle quickfix<cr>", noreopt)
map("n", "gR", "<cmd>TroubleToggle lsp_references<cr>", noreopt)
-- 高亮跳转
map("n", "n", "n:Beacon<CR>", noreopt)
map("n", "N", "N:Beacon<CR>", noreopt)
map("n", "*", "*:Beacon<CR>", noreopt)
map("n", "#", "#:Beacon<CR>", noreopt)
-- markdown
map("n", "<leader>mp", ":MarkdownPreviewToggle<CR>", noreopt)
-- lspsage
function _G.set_lspsage_keymaps()
local keymap = vim.keymap.set
-- LSP finder - Find the symbol's definition
-- If there is no definition, it will instead be hidden
-- When you use an action in finder like "open vsplit",
-- you can use <C-t> to jump back
keymap("n", "cf", "<cmd>Lspsaga lsp_finder<CR>")
-- Code action
keymap({ "n", "v" }, "ca", "<cmd>Lspsaga code_action<CR>")
-- Rename all occurrences of the hovered word for the entire file
keymap("n", "rn", "<cmd>Lspsaga rename<CR>")
-- Rename all occurrences of the hovered word for the selected files
keymap("n", "<leader>rn", "<cmd>Lspsaga rename ++project<CR>")
-- Peek definition
-- You can edit the file containing the definition in the floating window
-- It also supports open/vsplit/etc operations, do refer to "definition_action_keys"
-- It also supports tagstack
-- Use <C-t> to jump back
keymap("n", "gd", "<cmd>Lspsaga peek_definition<CR>")
-- Go to definition
keymap("n", "gd", "<cmd>Lspsaga goto_definition<CR>")
-- Peek type definition
-- You can edit the file containing the type definition in the floating window
-- It also supports open/vsplit/etc operations, do refer to "definition_action_keys"
-- It also supports tagstack
-- Use <C-t> to jump back
keymap("n", "gt", "<cmd>Lspsaga peek_type_definition<CR>")
-- Go to type definition
keymap("n", "gt", "<cmd>Lspsaga goto_type_definition<CR>")
-- Show line diagnostics
-- You can pass argument ++unfocus to
-- unfocus the show_line_diagnostics floating window
keymap("n", "<leader>sl", "<cmd>Lspsaga show_line_diagnostics<CR>")
-- Show cursor diagnostics
-- Like show_line_diagnostics, it supports passing the ++unfocus argument
keymap("n", "<leader>sc", "<cmd>Lspsaga show_cursor_diagnostics<CR>")
-- Show buffer diagnostics
keymap("n", "<leader>sb", "<cmd>Lspsaga show_buf_diagnostics<CR>")
-- Diagnostic jump
-- You can use <C-o> to jump back to your previous location
keymap("n", "[e", "<cmd>Lspsaga diagnostic_jump_prev<CR>")
keymap("n", "]e", "<cmd>Lspsaga diagnostic_jump_next<CR>")
-- Diagnostic jump with filters such as only jumping to an error
keymap("n", "[E", function()
require("lspsaga.diagnostic"):goto_prev({ severity = vim.diagnostic.severity.ERROR })
end)
keymap("n", "]E", function()
require("lspsaga.diagnostic"):goto_next({ severity = vim.diagnostic.severity.ERROR })
end)
-- Toggle outline
keymap("n", "<leader>o", "<cmd>Lspsaga outline<CR>")
-- Hover Doc
-- If there is no hover doc,
-- there will be a notification stating that
-- there is no information available.
-- To disable it just use ":Lspsaga hover_doc ++quiet"
-- Pressing the key twice will enter the hover window
keymap("n", "K", "<cmd>Lspsaga hover_doc<CR>")
-- If you want to keep the hover window in the top right hand corner,
-- you can pass the ++keep argument
-- Note that if you use hover with ++keep, pressing this key again will
-- close the hover window. If you want to jump to the hover window
-- you should use the wincmd command "<C-w>w"
keymap("n", "K", "<cmd>Lspsaga hover_doc ++keep<CR>")
-- Call hierarchy
keymap("n", "<Leader>ci", "<cmd>Lspsaga incoming_calls<CR>")
keymap("n", "<Leader>co", "<cmd>Lspsaga outgoing_calls<CR>")
-- Floating terminal
keymap({ "n", "t" }, "<A-d>", "<cmd>Lspsaga term_toggle<CR>")
end
vim.cmd("lua set_lspsage_keymaps()")

View File

@ -1 +1,2 @@
vim.cmd[[colorscheme tokyonight]]
vim.o.background = "dark" -- or "light" for light mode
vim.cmd([[colorscheme gruvbox]])

View File

@ -1,9 +1,69 @@
local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
mapping = {
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" }, -- For vsnip users.
}, {
{ name = "buffer" },
}),
})
local capabilities = require("cmp_nvim_lsp").default_capabilities() --nvim-cmp
require("lspconfig")["golangci_lint_ls"].setup({
on_attach = common_lsp_on_attach,
flags = common_lsp_flags,
})
require("lspconfig")["gopls"].setup({
cmd = { "gopls" },
on_attach = common_lsp_on_attach,
flags = common_lsp_flags,
capabilities = capabilities,
settings = {
gopls = {
experimentalPostfixCompletions = true,
analyses = {
unusedparams = true,
shadow = true,
},
},
},
init_options = { usePlaceholders = true },
})

View File

@ -6,6 +6,20 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true
require("lspconfig").html.setup({
capabilities = capabilities,
})
require("lspconfig").cssls.setup({
capabilities = capabilities,
})
require("lspconfig").tsserver.setup({
capabilities = capabilities,
})
require("lspconfig").eslint.setup({
on_attach = function(client, bufnr)
vim.api.nvim_create_autocmd("BufWritePre", {
buffer = bufnr,
command = "EslintFixAll",
})
end,
})

View File

@ -1,37 +1,12 @@
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.keymap.set("n", "<space>e", vim.diagnostic.open_float, opts)
vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, opts)
vim.keymap.set("n", "]d", vim.diagnostic.goto_next, opts)
vim.keymap.set("n", "<space>q", vim.diagnostic.setloclist, opts)
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
common_lsp_on_attach = function(client, bufnr)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local bufopts = { noremap = true, silent = true, buffer = bufnr }
vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts)
vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts)
vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts)
vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts)
vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
vim.keymap.set("n", "<space>wl", function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, bufopts)
vim.keymap.set("n", "<space>D", vim.lsp.buf.type_definition, bufopts)
vim.keymap.set("n", "<space>rn", vim.lsp.buf.rename, bufopts)
vim.keymap.set("n", "<space>ca", vim.lsp.buf.code_action, bufopts)
vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts)
vim.keymap.set("n", "<space>f", function()
vim.lsp.buf.format({ async = true })
end, bufopts)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
end
common_lsp_flags = {

View File

@ -1,4 +1,4 @@
require("lspconfig").sumneko_lua.setup({
require("lspconfig").lua_ls.setup({
settings = {
Lua = {
runtime = {

View File

@ -5,3 +5,7 @@ capabilities.textDocument.completion.completionItem.snippetSupport = true
require("lspconfig").jsonls.setup({
capabilities = capabilities,
})
require("lspconfig").taplo.setup({})
require("lspconfig").yamlls.setup({})

View File

@ -1 +0,0 @@
require("lspconfig").taplo.setup({})

3
lua/lsp/volar.lua Normal file
View File

@ -0,0 +1,3 @@
require("lspconfig").volar.setup({
filetypes = { "typescript", "javascript", "javascriptreact", "typescriptreact", "vue", "json" },
})

View File

@ -1 +0,0 @@
require("lspconfig").yamlls.setup({})

10
lua/plugins/aerial.lua Normal file
View File

@ -0,0 +1,10 @@
require("aerial").setup({
-- optionally use on_attach to set keymaps when aerial has attached to a buffer
on_attach = function(bufnr)
-- Jump forwards/backwards with '{' and '}'
vim.keymap.set("n", "{", "<cmd>AerialPrev<CR>", { buffer = bufnr })
vim.keymap.set("n", "}", "<cmd>AerialNext<CR>", { buffer = bufnr })
-- You probably also want to set a keymap to toggle aerial
vim.keymap.set("n", "<leader>ol", "<cmd>AerialToggle!<CR>", { buffer = bufnr })
end,
})

View File

@ -1 +1 @@
require("auto-save").setup {}
require("auto-save").setup({ trigger_events = { "InsertLeave" } })

View File

@ -1,14 +1,16 @@
require("bufferline").setup{
options = {
-- 使用 nvim 内置lsp
diagnostics = "nvim_lsp",
always_show_bufferline = false,
-- 左侧让出 nvim-tree 的位置
offsets = {{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
text_align = "left"
}}
}
}
require("bufferline").setup({
options = {
-- 使用 nvim 内置lsp
diagnostics = "nvim_lsp",
always_show_bufferline = false,
-- 左侧让出 nvim-tree 的位置
offsets = {
{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
text_align = "left",
},
},
},
})

View File

@ -0,0 +1,5 @@
require("catppuccin").setup({
integrations = {
lsp_saga = true
}
})

View File

@ -1,22 +1,22 @@
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local null_ls = require("null-ls")
require("null-ls").setup({
sources = {
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.stylua,
},
-- you can reuse a shared lspconfig on_attach callback here
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
-- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end,
sources = {
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.stylua,
},
-- you can reuse a shared lspconfig on_attach callback here
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_buf_create_user_command(bufnr, "LspFormatting", function()
vim.lsp.buf.format({ bufnr = bufnr })
end, {})
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
command = "undojoin | LspFormatting",
})
end
end,
})

View File

@ -1,40 +1,92 @@
require('gitsigns').setup({
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
require("gitsigns").setup({
signs = {
add = { text = "" },
change = { text = "" },
delete = { text = "_" },
topdelete = { text = "" },
changedelete = { text = "~" },
untracked = { text = "" },
},
signcolumn = true, -- Toggle with `:Gitsigns toggle_signs`
numhl = false, -- Toggle with `:Gitsigns toggle_numhl`
linehl = false, -- Toggle with `:Gitsigns toggle_linehl`
word_diff = false, -- Toggle with `:Gitsigns toggle_word_diff`
watch_gitdir = {
interval = 1000,
follow_files = true,
},
attach_to_untracked = true,
current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame`
current_line_blame_opts = {
virt_text = true,
virt_text_pos = "eol", -- 'eol' | 'overlay' | 'right_align'
delay = 1000,
ignore_whitespace = false,
},
current_line_blame_formatter = "<author>, <author_time:%Y-%m-%d> - <summary>",
sign_priority = 6,
update_debounce = 100,
status_formatter = nil, -- Use default
max_file_length = 40000, -- Disable if file is longer than this (in lines)
preview_config = {
-- Options passed to nvim_open_win
border = "single",
style = "minimal",
relative = "cursor",
row = 0,
col = 1,
},
yadm = {
enable = false,
},
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
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})
-- 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})
map("n", "[c", function()
if vim.wo.diff then
return "[c"
end
vim.schedule(function()
gs.prev_hunk()
end)
return "<Ignore>"
end, { expr = true })
-- Actions
map({'n', 'v'}, '<leader>hs', ':Gitsigns stage_hunk<CR>')
map({'n', 'v'}, '<leader>hr', ':Gitsigns reset_hunk<CR>')
map('n', '<leader>hS', gs.stage_buffer)
map('n', '<leader>hu', gs.undo_stage_hunk)
map('n', '<leader>hR', gs.reset_buffer)
map('n', '<leader>hp', gs.preview_hunk)
map('n', '<leader>hb', function() gs.blame_line{full=true} end)
map('n', '<leader>tb', gs.toggle_current_line_blame)
map('n', '<leader>hd', gs.diffthis)
map('n', '<leader>hD', function() gs.diffthis('~') end)
map('n', '<leader>td', gs.toggle_deleted)
-- Actions
map({ "n", "v" }, "<leader>hs", ":Gitsigns stage_hunk<CR>")
map({ "n", "v" }, "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line({ full = true })
end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function()
gs.diffthis("~")
end)
map("n", "<leader>td", gs.toggle_deleted)
-- Text object
map({'o', 'x'}, 'ih', ':<C-U>Gitsigns select_hunk<CR>')
end
-- Text object
map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end,
})

9
lua/plugins/go.lua Normal file
View File

@ -0,0 +1,9 @@
require("go").setup()
local format_sync_grp = vim.api.nvim_create_augroup("GoImport", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require("go.format").goimport()
end,
group = format_sync_grp,
})

View File

@ -0,0 +1 @@
require("impatient")

View File

@ -1,10 +1,10 @@
vim.opt.list = true
vim.opt.listchars:append "space:⋅"
vim.opt.listchars:append "eol:↴"
vim.opt.listchars:append("space:⋅")
vim.opt.listchars:append("eol:↴")
require("indent_blankline").setup {
show_current_context = true,
show_current_context_start = true,
show_end_of_line = true,
space_char_blankline = " ",
}
require("indent_blankline").setup({
show_current_context = true,
show_current_context_start = true,
show_end_of_line = true,
space_char_blankline = " ",
})

12
lua/plugins/leap.lua Normal file
View File

@ -0,0 +1,12 @@
require("leap").add_default_mappings()
require("leap").opts.highlight_unlabeled_phase_one_targets = true
require("flit").setup({
keys = { f = "f", F = "F", t = "t", T = "T" },
-- A string like "nv", "nvo", "o", etc.
labeled_modes = "v",
multiline = true,
-- Like `leap`s similar argument (call-specific overrides).
-- E.g.: opts = { equivalence_classes = {} }
opts = {},
})

6
lua/plugins/lspsaga.lua Normal file
View File

@ -0,0 +1,6 @@
require("lspsaga").setup({
ui = {
colors = require("catppuccin.groups.integrations.lsp_saga").custom_colors(),
kind = require("catppuccin.groups.integrations.lsp_saga").custom_kind(),
},
})

View File

@ -1,3 +1,6 @@
require('lualine').setup({
options = { theme = 'tokyonight' }
require("lualine").setup({
options = {
theme = "gruvbox",
component_separators = { left = "|", right = "|" },
},
})

View File

@ -1,15 +1,33 @@
require("mason").setup({
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = ""
}
}
ui = {
icons = {
package_installed = "",
package_pending = "",
package_uninstalled = "",
},
},
})
require("mason-lspconfig").setup {
ensure_installed = { "sumneko_lua", "rust_analyzer", "gopls", "golangci_lint_ls" },
automatic_installation = true,
}
require("mason-lspconfig").setup({
ensure_installed = {
"lua_ls",
"rust_analyzer",
"gopls",
"golangci_lint_ls",
"tsserver",
"volar",
"taplo",
"lemminx",
"yamlls",
"sqlls",
"jsonls",
"jdtls",
"bashls",
"cssls",
"dockerls",
"docker_compose_language_service",
"eslint",
"html",
},
automatic_installation = true,
})

View File

@ -1,29 +1,36 @@
require("nvim-tree").setup({
auto_reload_on_write = true,
sort_by = "case_sensitive",
view = {
width = 30,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
}
auto_reload_on_write = true,
sort_by = "case_sensitive",
sync_root_with_cwd = true,
respect_buf_cwd = true,
update_focused_file = {
enable = true,
update_root = true,
},
filters = { custom = { ".git" } },
view = {
width = 30,
mappings = {
list = {
{ key = "u", action = "dir_up" },
},
},
},
renderer = {
group_empty = true,
},
})
local function open_nvim_tree(data)
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
if not directory then
return
end
-- change to the directory
vim.cmd.cd(data.file)
-- open the tree
require("nvim-tree.api").tree.open()
-- buffer is a directory
local directory = vim.fn.isdirectory(data.file) == 1
if not directory then
return
end
-- change to the directory
vim.cmd.cd(data.file)
-- open the tree
require("nvim-tree.api").tree.open()
end
vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree })

4
lua/plugins/project.lua Normal file
View File

@ -0,0 +1,4 @@
require("project_nvim").setup({
patterns = { "project.md" },
exclude_dirs = { ".git", "node_modules", "dist", "target" },
})

View File

@ -1,7 +1,8 @@
return require("packer").startup(function(use)
use({ "wbthomason/packer.nvim" })
-- 主题
use({ "folke/tokyonight.nvim" })
use({ "catppuccin/nvim", as = "catppuccin" })
use({ "ellisonleao/gruvbox.nvim" })
-- 文件树
use({
"nvim-tree/nvim-tree.lua",
@ -77,4 +78,81 @@ return require("packer").startup(function(use)
})
-- 格式化
use({ "jose-elias-alvarez/null-ls.nvim" })
-- 项目管理
use({ "ahmedkhalf/project.nvim" })
-- 优化启动速度
use({ "lewis6991/impatient.nvim" })
-- TODO 管理
use({
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
})
-- golang ide
use({
"ray-x/go.nvim",
"ray-x/guihua.lua", -- recommended if need floating window support
})
use({
"glepnir/lspsaga.nvim",
branch = "main",
requires = {
{ "nvim-tree/nvim-web-devicons" },
--Please make sure you install markdown and markdown_inline parser
{ "nvim-treesitter/nvim-treesitter" },
},
})
-- 自动完成相关
use({
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-vsnip",
"hrsh7th/vim-vsnip",
})
-- 代码大纲
use({ "stevearc/aerial.nvim" })
-- 错误列表
use({
"folke/trouble.nvim",
requires = "nvim-tree/nvim-web-devicons",
})
-- 上下高亮跳动
use({ "danilamihailov/beacon.nvim" })
-- markdown lsp
use({
"iamcco/markdown-preview.nvim",
run = "cd app && npm install",
setup = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
ft = { "markdown" },
})
-- 跳转
use({ "ggandor/leap.nvim" })
use({ "ggandor/flit.nvim" })
-- normal command line
use({
"VonHeikemen/fine-cmdline.nvim",
requires = {
{ "MunifTanjim/nui.nvim" },
},
})
-- key帮助
use({
"folke/which-key.nvim",
config = function()
vim.o.timeout = true
vim.o.timeoutlen = 300
require("which-key").setup({
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
})
end,
})
-- 高亮当前关键词
use({ "RRethy/vim-illuminate" })
vim.opt.completeopt = { "menu", "menuone", "noselect" }
end)

View File

@ -1 +1,5 @@
require('telescope').load_extension("lazygit")
require("telescope").setup({
extensions = {
projects = {},
},
})

1
lua/plugins/todo.lua Normal file
View File

@ -0,0 +1 @@
require("todo-comments").setup({})

View File

@ -1,42 +1,54 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the four listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "help", "go" },
require("nvim-treesitter.configs").setup({
-- A list of parser names, or "all" (the four listed parsers should always be installed)
ensure_installed = {
"bash",
"c",
"css",
"dart",
"dockerfile",
"gitignore",
"go",
"gomod",
"gosum",
"gowork",
"help",
"html",
"java",
"javascript",
"json",
"lua",
"markdown",
"rust",
"toml",
"typescript",
"vim",
"vue",
"yaml",
},
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = true,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = {},
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
-- List of parsers to ignore installing (for "all")
ignore_install = { "javascript" },
---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!
highlight = {
-- `false` will disable the whole extension
enable = true,
-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
disable = { },
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<CR>",
node_incremental = "<CR>",
node_decremental = "<BS>",
scope_incremental = "<TAB>",
},
},
indent = {
enable = true,
},
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
},
})

1
lua/plugins/trouble.lua Normal file
View File

@ -0,0 +1 @@
require("trouble").setup()