Skip to content

Commit 710bf34

Browse files
committed
add neovim plugins
1 parent f8bafde commit 710bf34

File tree

13 files changed

+357
-14
lines changed

13 files changed

+357
-14
lines changed

.ideavimrc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
" options and mappings that are supported by both Vim and IdeaVim
2+
3+
if has('ide')
4+
" mappings and options that exist only in IdeaVim
5+
" set multiple-cursors
6+
set sneak
7+
8+
if &ide =~? 'intellij idea'
9+
if &ide =~? 'community'
10+
" some mappings and options for IntelliJ IDEA Community Edition
11+
elseif &ide =~? 'ultimate'
12+
" some mappings and options for IntelliJ IDEA Ultimate Edition
13+
endif
14+
elseif &ide =~? 'pycharm'
15+
" PyCharm specific mappings and options
16+
endif
17+
else
18+
" some mappings for Vim/Neovim
19+
" nnoremap <leader>f <cmd>Telescope find_files<cr>
20+
endif

init.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ echo 'source ~/vimrc/root/bashrc' >> ~/.bashrc
1010
# nvim
1111
ln -s ~/vimrc/root/.config/nvim ~/.config/nvim
1212
ln -s ~/vimrc/root/.vim/coc-settings.json ~/.config/nvim/coc-settings.json
13+
14+
ln -s ~/vimrc/root/.config/lazygit ~/.config/lazygit

root/.config/lazygit/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
os:
2+
editCommand: 'nvim'

root/.config/nvim/init.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@ if exists("g:vscode")
77
let g:loaded_netrwPlugin = 1
88
source ~/vimrc.d/plugin.vim
99
else
10+
let g:nvim_compatibility_with_vim = 0
1011
source ~/.vimrc
12+
if ! g:nvim_compatibility_with_vim
13+
runtime setup.lua
14+
end
1115
end

root/.config/nvim/lua/.luarc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"workspace.checkThirdParty": false
3+
}

root/.config/nvim/lua/lsp.lua

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
----------------------- hrsh7th/nvim-cmp ----------------------------
2+
local cmp = require 'cmp'
3+
4+
cmp.setup({
5+
snippet = {
6+
-- REQUIRED - you must specify a snippet engine
7+
expand = function(args)
8+
-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
9+
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
10+
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
11+
vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
12+
end,
13+
},
14+
window = {
15+
completion = cmp.config.window.bordered(),
16+
documentation = cmp.config.window.bordered(),
17+
},
18+
mapping = cmp.mapping.preset.insert({
19+
['<C-b>'] = cmp.mapping.scroll_docs(-4),
20+
['<C-f>'] = cmp.mapping.scroll_docs(4),
21+
['<C-Space>'] = cmp.mapping.complete(),
22+
['<C-e>'] = cmp.mapping.abort(),
23+
['<tab>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
24+
}),
25+
sources = cmp.config.sources({
26+
{ name = 'nvim_lsp' },
27+
-- { name = 'vsnip' }, -- For vsnip users.
28+
-- { name = 'luasnip' }, -- For luasnip users.
29+
{ name = 'ultisnips' }, -- For ultisnips users.
30+
-- { name = 'snippy' }, -- For snippy users.
31+
}, {
32+
{ name = 'buffer' },
33+
})
34+
})
35+
36+
-- Set configuration for specific filetype.
37+
cmp.setup.filetype('gitcommit', {
38+
sources = cmp.config.sources({
39+
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
40+
}, {
41+
{ name = 'buffer' },
42+
})
43+
})
44+
45+
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
46+
cmp.setup.cmdline({ '/', '?' }, {
47+
mapping = cmp.mapping.preset.cmdline(),
48+
sources = {
49+
{ name = 'buffer' }
50+
}
51+
})
52+
53+
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
54+
cmp.setup.cmdline(':', {
55+
mapping = cmp.mapping.preset.cmdline(),
56+
sources = cmp.config.sources({
57+
{ name = 'path' }
58+
}, {
59+
{ name = 'cmdline' }
60+
})
61+
})
62+
63+
-- Set up lspconfig.
64+
local capabilities = require('cmp_nvim_lsp').default_capabilities()
65+
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
66+
-- require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
67+
-- capabilities = capabilities,
68+
-- }
69+
70+
---------------------------------------------------------------------
71+
72+
-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
73+
vim.diagnostic.config {
74+
virtual_text = true,
75+
signs = true,
76+
}
77+
78+
-- Use an on_attach function to only map the following keys
79+
-- after the language server attaches to the current buffer
80+
local on_attach = function(client, bufnr)
81+
-- Enable completion triggered by <c-x><c-o>
82+
vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc")
83+
84+
-- Mappings.
85+
-- See `:help vim.lsp.*` for documentation on any of the below functions
86+
local bufopts = { noremap = true, silent = true, buffer = bufnr }
87+
vim.keymap.set("n", "<leader>gD", vim.lsp.buf.declaration, bufopts)
88+
vim.keymap.set("n", "<leader>gd", vim.lsp.buf.definition, bufopts)
89+
vim.keymap.set("n", "<leader>K", vim.lsp.buf.hover, bufopts)
90+
vim.keymap.set("n", "<leader>gi", vim.lsp.buf.implementation, bufopts)
91+
-- vim.keymap.set("n", "<C-k>", vim.lsp.buf.signature_help, bufopts)
92+
-- vim.keymap.set("n", "<space>wa", vim.lsp.buf.add_workspace_folder, bufopts)
93+
-- vim.keymap.set("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, bufopts)
94+
-- vim.keymap.set("n", "<space>wl", function()
95+
-- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
96+
-- end, bufopts)
97+
vim.keymap.set("n", "<leader>gt", vim.lsp.buf.type_definition, bufopts)
98+
vim.keymap.set("n", "<leader>rn", vim.lsp.buf.rename, bufopts)
99+
vim.keymap.set("n", "<leader>ca", vim.lsp.buf.code_action, bufopts)
100+
vim.keymap.set("n", "<leader>gr", vim.lsp.buf.references, bufopts)
101+
vim.keymap.set("n", "<leader>fmt", function()
102+
vim.lsp.buf.format { async = true }
103+
end, bufopts)
104+
end
105+
106+
require("clangd_extensions").setup {
107+
server = {
108+
-- options to pass to nvim-lspconfig
109+
-- i.e. the arguments to require("lspconfig").clangd.setup({})
110+
capabilities = capabilities,
111+
cmd = {
112+
"clangd",
113+
"--clang-tidy",
114+
"--compile-commands-dir=_build/debug",
115+
"--pretty",
116+
"--cross-file-rename",
117+
"--inlay-hints=true",
118+
"--background-index",
119+
"--suggest-missing-includes=true",
120+
},
121+
filetypes = { "c", "cpp", "objc", "objcpp" },
122+
on_attach = on_attach
123+
},
124+
extensions = {
125+
-- defaults:
126+
-- Automatically set inlay hints (type hints)
127+
autoSetHints = true,
128+
-- These apply to the default ClangdSetInlayHints command
129+
inlay_hints = {
130+
-- Only show inlay hints for the current line
131+
only_current_line = false,
132+
-- Event which triggers a refersh of the inlay hints.
133+
-- You can make this "CursorMoved" or "CursorMoved,CursorMovedI" but
134+
-- not that this may cause higher CPU usage.
135+
-- This option is only respected when only_current_line and
136+
-- autoSetHints both are true.
137+
only_current_line_autocmd = "CursorHold",
138+
-- whether to show parameter hints with the inlay hints or not
139+
show_parameter_hints = true,
140+
-- prefix for parameter hints
141+
parameter_hints_prefix = "<- ",
142+
-- prefix for all the other hints (type, chaining)
143+
other_hints_prefix = "=> ",
144+
-- whether to align to the length of the longest line in the file
145+
max_len_align = false,
146+
-- padding from the left if max_len_align is true
147+
max_len_align_padding = 1,
148+
-- whether to align to the extreme right or not
149+
right_align = false,
150+
-- padding from the right if right_align is true
151+
right_align_padding = 7,
152+
-- The color of the hints
153+
highlight = "Comment",
154+
-- The highlight group priority for extmark
155+
priority = 100,
156+
},
157+
ast = {
158+
-- These are unicode, should be available in any font
159+
role_icons = {
160+
type = "🄣",
161+
declaration = "🄓",
162+
expression = "🄔",
163+
statement = ";",
164+
specifier = "🄢",
165+
["template argument"] = "🆃",
166+
},
167+
kind_icons = {
168+
Compound = "🄲",
169+
Recovery = "🅁",
170+
TranslationUnit = "🅄",
171+
PackExpansion = "🄿",
172+
TemplateTypeParm = "🅃",
173+
TemplateTemplateParm = "🅃",
174+
TemplateParamObject = "🅃",
175+
},
176+
highlights = {
177+
detail = "Comment",
178+
},
179+
},
180+
memory_usage = {
181+
border = "none",
182+
},
183+
symbol_info = {
184+
border = "none",
185+
},
186+
},
187+
}
188+
189+
require 'lspconfig'.lua_ls.setup {
190+
capabilities = capabilities,
191+
on_attach = on_attach,
192+
settings = {
193+
Lua = {
194+
runtime = {
195+
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
196+
version = 'LuaJIT',
197+
},
198+
format = {
199+
enable = true,
200+
-- Put format options here
201+
-- NOTE: the value should be STRING!!
202+
defaultConfig = {
203+
indent_style = "tab",
204+
indent_size = "2",
205+
}
206+
},
207+
diagnostics = {
208+
-- Get the language server to recognize the `vim` global
209+
globals = { 'vim' },
210+
},
211+
workspace = {
212+
-- Make the server aware of Neovim runtime files
213+
library = vim.api.nvim_get_runtime_file("", true),
214+
},
215+
-- Do not send telemetry data containing a randomized but unique identifier
216+
telemetry = {
217+
enable = false,
218+
},
219+
},
220+
},
221+
}
222+
223+
-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#jsonls
224+
-- npm i -g vscode-langservers-extracted
225+
require 'lspconfig'.jsonls.setup {
226+
capabilities = capabilities,
227+
on_attach = on_attach,
228+
}
229+
230+
cmp.setup {
231+
-- ... rest of your cmp setup ...
232+
sorting = {
233+
comparators = {
234+
cmp.config.compare.offset,
235+
cmp.config.compare.exact,
236+
cmp.config.compare.recently_used,
237+
require("clangd_extensions.cmp_scores"),
238+
cmp.config.compare.kind,
239+
cmp.config.compare.sort_text,
240+
cmp.config.compare.length,
241+
cmp.config.compare.order,
242+
},
243+
},
244+
}

root/.config/nvim/setup.lua

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require("nvim-treesitter.configs").setup {
2+
-- 安装 language parser
3+
-- :TSInstallInfo 命令查看支持的语言
4+
ensure_installed = { "cpp", "lua", "vim", "python" },
5+
-- 启用代码高亮模块
6+
highlight = {
7+
enable = true,
8+
additional_vim_regex_highlighting = false,
9+
},
10+
}
11+
12+
local builtin = require('telescope.builtin')
13+
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
14+
vim.keymap.set('n', '<leader>rg', builtin.live_grep, {})
15+
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
16+
vim.keymap.set('n', '<leader>fh', builtin.oldfiles, {})
17+
18+
19+
require("mason").setup {
20+
ui = {
21+
icons = {
22+
package_installed = "",
23+
package_pending = "",
24+
package_uninstalled = "",
25+
},
26+
},
27+
github = {
28+
-- The template URL to use when downloading assets from GitHub.
29+
-- The placeholders are the following (in order):
30+
-- 1. The repository (e.g. "rust-lang/rust-analyzer")
31+
-- 2. The release version (e.g. "v0.3.0")
32+
-- 3. The asset name (e.g. "rust-analyzer-v0.3.0-x86_64-unknown-linux-gnu.tar.gz")
33+
download_url_template = "https://cors.isteed.cc/github.com/%s/releases/download/%s/%s",
34+
},
35+
}
36+
37+
require("lsp")

root/.vim/coc-settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"--compile-commands-dir=_build/debug",
66
"--pretty",
77
"--cross-file-rename",
8-
"--inlay-hints=true"
8+
"--inlay-hints=true",
9+
"--background-index",
10+
"--suggest-missing-includes=true"
911
],
1012
"languageserver": {
1113
"golang": {

root/.vimrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ let g:netrw_browsex_viewer="start"
7777
" Commenting blocks of code.
7878
augroup commenting_blocks_of_code
7979
autocmd!
80-
autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
80+
autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
8181
autocmd FileType sh,ruby,python,conf,fstab,gitconfig let b:comment_leader = '# '
8282
autocmd FileType tex let b:comment_leader = '% '
8383
autocmd FileType mail let b:comment_leader = '> '
8484
autocmd FileType vim let b:comment_leader = '" '
85+
autocmd FileType lua let b:comment_leader = '-- '
8586
augroup end
8687

8788
" https://stackoverflow.com/questions/1676632/whats-a-quick-way-to-comment-uncomment-lines-in-vim

root/vimrc.d/basic.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ set smartindent " 以 { 或cinword变量开始的行(if、while...),换行
4040

4141
augroup indent2
4242
autocmd!
43-
autocmd FileType cpp,vim,tex,markdown,html,sh,zsh,json setlocal tabstop=2 shiftwidth=2 softtabstop=2
43+
autocmd FileType cpp,vim,tex,markdown,html,sh,zsh,json,lua setlocal tabstop=2 shiftwidth=2 softtabstop=2
4444
augroup end
4545
augroup indent4
4646
autocmd!

root/vimrc.d/coc.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ nmap <silent> <leader>gy <Plug>(coc-type-definition)
3737
nmap <silent> <leader>gi <Plug>(coc-implementation)
3838
nmap <silent> <leader>gr <Plug>(coc-references)
3939
40-
" Apply the most preferred quickfix action to fix diagnostic on the current line
41-
nmap <leader>qf <Plug>(coc-fix-current)
40+
" Apply the most preferred quickfix code action to fix diagnostic on the current line
41+
nmap <leader>ca <Plug>(coc-fix-current)
4242
4343
" Use K to show documentation in preview window.
4444
nnoremap <silent> <leader>K :call <SID>show_documentation()<CR>

0 commit comments

Comments
 (0)