Skip to content

Commit ea8b278

Browse files
nvim: moved lsp/completion/diagnostic key mapping to keymap folder
1 parent 80f93f8 commit ea8b278

8 files changed

Lines changed: 106 additions & 89 deletions

File tree

.config/cvim/cheats/cheat40.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,31 @@ Filter out all grep's result in files FOO/bar :cfilter! FOO
7373
Filter out the result under the quickfix cursor from grep's result :x
7474
Replace FOO with BAR in grep results :cfdo %s/FOO/BAR/g
7575
}}}
76+
Code Symbol Browsing {{{2
77+
Jump to symbol (under cursor) declaration gD N
78+
Jump to symbol (under cursor) definition gd N
79+
View symbol (under cursor) info K N
80+
List symbol (under cursor) implementation gi N
81+
View symbol (under cursor) signature <C-K> N
82+
Add folder to workspace <space>wa N
83+
Remove folder from workspace <space>wr N
84+
List workspace folders <space>wl N
85+
Jump to type symbol (under cursor) definition <space>D N
86+
List symbol (under cursor) references gr N
87+
List symbol (under cursor) incoming calls gri N
88+
List symbol (under cursor) outgoing calls gro N
89+
}}}
90+
Code Symbol Editing {{{2
91+
Select code action (under cursor) <space>ca N
92+
Rename symbol (under cursor) <space>rn N
93+
Format symbol (under cursor) <space>f N
94+
}}}
95+
Code diagnostics {{{2
96+
Show diagnostics in floating window <space>e N
97+
Show diagnostics in bottom window <space>q N
98+
Jump to next diagnostic [d N
99+
Jump to previous diagnostic ]d N
100+
}}}
76101
Keycodes {{{2
77102
All keycodes like <S-..>, :keycodes N
78103
}}}

.config/cvim/common/functions.vim

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ function! F_Load_PluginsSettings (vimDistribution, plugins)
1414
endfor
1515
endfunction
1616

17-
" Load key mapping "plugins" (keymap/*.vim)
17+
" Load key mapping "plugins" (keymap/*.vim, keymap/*.lua)
1818
function! F_Load_KeyMappings (vimKeyMappingsPath)
1919
for fpath in split(globpath(a:vimKeyMappingsPath, '*.vim'), '\n')
2020
"call F_Source (, fpath)
2121
exe 'source ' . fpath
2222
endfor
23+
for fpath in split(globpath(a:vimKeyMappingsPath, '*.lua'), '\n')
24+
exe 'luafile ' . fpath
25+
endfor
2326
endfunction
2427

2528
" Load ui "plugins" (ui/*.vim)
@@ -162,3 +165,14 @@ function! F_Source_VimL_File (vimDistribution, file)
162165
vim.cmd("source ".a:file)
163166
endif
164167
endfunction
168+
169+
" Check if keymap should be set
170+
function! F_IsKeymapOn(mode, feature, variant)
171+
let features = g:distribKeymapFlags[a:mode]
172+
let enabled = F_IsFeatureEnabled(features, g:vimDistribution, a:feature)
173+
if a:variant == v:null
174+
return enabled
175+
else
176+
return enabled && a:variant ==# g:vimDistribution
177+
endif
178+
endfunction

.config/cvim/init/init.vim

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,3 @@ call F_FeatureLoad(g:commonFeatureFlags, g:vimDistribution, "ui_enhancement")
761761
call F_FeatureLoad(g:commonFeatureFlags, g:vimDistribution, "grep")
762762
call F_FeatureLoad(g:commonFeatureFlags, g:vimDistribution, "diagnostic")
763763
call F_FeatureLoad(g:commonFeatureFlags, g:vimDistribution, "local_vimrc")
764-
765-
" Post setup
766-
HardTimeOn

.config/cvim/keymap/00_mapping.vim

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22
" Content editing: Vim at the speed of thoughts
33
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
44

5-
function! F_IsKeymapOn(mode, feature, variant)
6-
let features = g:distribKeymapFlags[a:mode]
7-
let enabled = F_IsFeatureEnabled(features, g:vimDistribution, a:feature)
8-
if a:variant == v:null
9-
return enabled
10-
else
11-
return enabled && a:variant ==# g:vimDistribution
12-
endif
13-
endfunction
14-
155
" Faster Command mode access {{{
166
" - eg: :w becomes ;w
177
" - effectively reducing stroke count from S-; w (5 strokes) to ;w (3 strokes)
@@ -34,14 +24,11 @@ if F_IsKeymapOn('n', '*', v:null) | map <F8> :TagbarToggle<CR> | endif
3424
" }}}
3525

3626
" Content editing: Vim at the speed of thoughts {{{
37-
3827
" Force to master Vim's advanced motion and search functionnality
3928
" by disabling some/all arrow keys, hjkl keys, page up/down and others
40-
"autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardTimeOn()
41-
29+
autocmd VimEnter,BufNewFile,BufReadPost * silent! call HardTimeOn()
4230
" Mode switching alternative: Back to Normal Mode from Insert Mode
4331
if F_IsKeymapOn('i', 'fast_switch_to_normal_mode', v:null) | :imap jj <Esc> | endif
44-
4532
" Search and replace selected text in VISUAL mode
4633
if F_IsKeymapOn('n', '*', v:null) | vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left> | endif
4734
"}}}
@@ -160,9 +147,3 @@ if F_IsKeymapOn('n', '*', v:null) | map <Leader>tc :term ~/.bin/vim-term-cwd.sh
160147
" Todo/Fixme
161148
" - Show todo/fixme
162149
if F_IsKeymapOn('n', '*', v:null) | map <Leader>td :Ag TODO\|FIXME | endif
163-
164-
" Refactor
165-
" - Rename element
166-
" FIXME add support via LSP ?
167-
" - Refactor menu actions
168-
" No support
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Diagostics. See `:help diagnostic-defaults
2+
-- Show diagnostics in a floating window
3+
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
4+
-- Show diagnostics in a bottom window
5+
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
6+
-- Jump to the previous diagnostic
7+
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
8+
-- Jump to the next diagnostic
9+
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
-- Code completion/action on LSP enabled buffers. See `:help lsp-defaults
2+
-- Use LspAttach autocommand to only map the following keys after the language server attaches to the current buffer
3+
vim.api.nvim_create_autocmd('LspAttach', {
4+
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
5+
callback = function(ev)
6+
-- Enable completion triggered by <c-x><c-o>
7+
-- -- ommi-func: manual completion
8+
-- -- nvim-cmp : auto completion
9+
-- - Disable ommi-func for nvim-cmp: https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
10+
-- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
11+
12+
-- Buffer local mappings.
13+
-- See `:help vim.lsp.*` for documentation on any of the below functions
14+
local opts = { buffer = ev.buf }
15+
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
16+
-- Jump to the definition
17+
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
18+
-- Displays hover information about the symbol under the cursor
19+
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
20+
-- Lists all the implementations for the symbol under the cursor
21+
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
22+
-- Displays a function's signature information
23+
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
24+
-- Add to workspace
25+
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
26+
-- Remove from workspace
27+
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
28+
-- List workspaces
29+
vim.keymap.set('n', '<space>wl', function()
30+
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
31+
end, opts)
32+
-- Jumps to the definition of the type symbol
33+
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
34+
-- Renames all references to the symbol under the cursor
35+
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
36+
-- Selects a code action available at the current cursor position
37+
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
38+
-- Lists all the references
39+
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
40+
-- Lists all incoming call sites of the symbol under the cursor in the quickfix window
41+
-- User can pick one site in the input list
42+
vim.keymap.set('n', 'gri', vim.lsp.buf.incoming_calls, opts)
43+
-- Lists all outgoing call sites of the symbol under the cursor in the quickfix window
44+
-- User can pick one site in the input list
45+
vim.keymap.set('n', 'gro', vim.lsp.buf.outgoing_calls, opts)
46+
-- Set some key bindings conditional on server capabilities
47+
vim.keymap.set('n', '<space>f', function()
48+
vim.lsp.buf.format { async = true }
49+
end, opts)
50+
51+
-- FIXME: Continue with https://github.com/jdhao/nvim-config/blob/4d8ef868ad0ef7f6433d91332aa6649186d9a2fb/lua/config/lsp.lua
52+
end,
53+
})

.config/cvim/settings/nvim_lspconfig.lua

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,3 @@
1-
-- src: https://github.com/neovim/nvim-lspconfig
2-
local function setup_keybinding_diagnostic()
3-
-- Global mappings.
4-
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
5-
-- Show diagnostics in a floating window
6-
--vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
7-
-- Show diagnostics in a bottom window
8-
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist)
9-
-- Move to the previous diagnostic
10-
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
11-
-- Move to the next diagnostic
12-
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
13-
end
14-
15-
-- src: https://github.com/neovim/nvim-lspconfig
16-
local function setup_keybinding_when_lspserver_attach_to_buffer()
17-
-- Use LspAttach autocommand to only map the following keys
18-
-- after the language server attaches to the current buffer
19-
vim.api.nvim_create_autocmd('LspAttach', {
20-
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
21-
callback = function(ev)
22-
-- Enable completion triggered by <c-x><c-o>
23-
-- -- ommi-func: manual completion
24-
-- -- nvim-cmp : auto completion
25-
-- - Disable ommi-func for nvim-cmp: https://github.com/neovim/nvim-lspconfig/wiki/Autocompletion
26-
-- vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
27-
28-
-- Buffer local mappings.
29-
-- See `:help vim.lsp.*` for documentation on any of the below functions
30-
local opts = { buffer = ev.buf }
31-
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
32-
-- Jump to the definition
33-
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
34-
-- Displays hover information about the symbol under the cursor
35-
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
36-
-- Lists all the implementations for the symbol under the cursor
37-
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
38-
-- Displays a function's signature information
39-
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
40-
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
41-
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
42-
vim.keymap.set('n', '<space>wl', function()
43-
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
44-
end, opts)
45-
-- Jumps to the definition of the type symbol
46-
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
47-
-- Renames all references to the symbol under the cursor
48-
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
49-
-- Selects a code action available at the current cursor position
50-
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
51-
-- Lists all the references
52-
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
53-
-- Set some key bindings conditional on server capabilities
54-
vim.keymap.set('n', '<space>f', function()
55-
vim.lsp.buf.format { async = true }
56-
end, opts)
57-
58-
-- FIXME: Continue with https://github.com/jdhao/nvim-config/blob/4d8ef868ad0ef7f6433d91332aa6649186d9a2fb/lua/config/lsp.lua
59-
end,
60-
})
61-
end
62-
631
local function setup_lsp(vim_lsp, lsp_name, client_lsp_capabilities, settings, flags)
642
-- Extend config for a language
653
vim_lsp.config(lsp_name,{
@@ -244,9 +182,6 @@ local function config()
244182
{},
245183
{}
246184
)
247-
248-
setup_keybinding_diagnostic()
249-
setup_keybinding_when_lspserver_attach_to_buffer()
250185
end
251186

252187
return {config = config}

.config/cvim/settings/nvim_nvim-cmp.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ local function config()
7575
}
7676
)
7777
-- View cmp sources status with :CmpStatus
78+
79+
--
80+
--vim.keymap.set({'n','i'}, '<M-]>', vim.lsp.inline_completion.select({count=1}), opts)
7881
end
7982

8083
return {config = config}

0 commit comments

Comments
 (0)