1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
-- Tab completion
--[[
vim.api.nvim_set_keymap("i", "<tab>",
"coc#pum:visible() ? coc#pum#next(1) : v:lua.check_back_space() ? '<tab>' : coc#refresh()",
{silent = true, expr = true, noremap = true})
vim.api.nvim_set_keymap("i", "<s-tab>", "pumvisible() ? '<C-p>' : '<C-h>'",
{expr = true, noremap = true})
]]
vim.cmd(
[[
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ v:lua.check_back_space() ? "\<Tab>" :
\ coc#refresh()
inoremap <silent><expr> <S-TAB>
\ coc#pum#visible() ? coc#pum#prev(1):
\ v:lua.check_back_space() ? "\<Tab>" :
\ coc#refresh()
]]
)
-- Use <c-space> to trigger completion
vim.api.nvim_set_keymap("i", "<C-space>", "coc#refresh()",
{silent = true, expr = true, noremap = true})
-- Make <CR> auto-select the first completion item and notify coc.nvim to
-- format on enter, <cr> could be remapped by other vim plugin
vim.api.nvim_set_keymap("i", "<CR>",
"pumvisible() ? coc#_select_confirm() : '<C-g>u<CR><c-r>=coc#on_enter()<CR>'",
{silent = true, expr = true, noremap = true})
-- Use `[g` and `]g` to navigate diagnostics
-- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
vim.api.nvim_set_keymap("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true})
vim.api.nvim_set_keymap("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true})
-- GoTo code navigation.
vim.api.nvim_set_keymap("n", "gd", "<Plug>(coc-definition)", {silent = true})
vim.api.nvim_set_keymap("n", "gy", "<Plug>(coc-type-definition)", {silent = true})
vim.api.nvim_set_keymap("n", "gi", "<Plug>(coc-implementation)", {silent = true})
vim.api.nvim_set_keymap("n", "gr", "<Plug>(coc-references)", {silent = true})
-- Use K to show documentation in preview window.
vim.api.nvim_set_keymap("n", "K", ":call v:lua.show_documentation()<CR>",
{silent = true, noremap = true})
-- Symbol renaming.
vim.api.nvim_set_keymap("n", "<leader>rn", "<Plug>(coc-rename)", {})
vim.api.nvim_set_keymap(
"n",
"<leader>d", ":CocCommand rust-analyzer.openDocs<CR>",
{ silent = true, noremap = true }
)
-- Formatting selected code.
-- vim.api.nvim_set_keymap("x", "<leader>f", "<Plug>(coc-format-selected)", {})
-- vim.api.nvim_set_keymap("n", "<leader>f", "<Plug>(coc-format-selected)", {})
-- Remap <C-f> and <C-b> for scroll float windows/popups.
vim.api.nvim_set_keymap(
"n",
"<C-f>",
"coc#float#has_scroll() ? coc#float#scroll(1) : '\\<C-f>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
vim.api.nvim_set_keymap(
"n",
"<C-b>",
"coc#float#has_scroll() ? coc#float#scroll(0) : '\\<C-b>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
vim.api.nvim_set_keymap(
"i",
"<C-f>",
"coc#float#has_scroll() ? '\\<c-r>=coc#float#scroll(1)\\<cr>' : '\\<Right>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
vim.api.nvim_set_keymap(
"i",
"<C-b>",
"coc#float#has_scroll() ? '\\<c-r>=coc#float#scroll(0)\\<cr>' : '\\<Left>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
vim.api.nvim_set_keymap(
"v",
"<C-f>",
"coc#float#has_scroll() ? coc#float#scroll(1) : '\\<C-f>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
vim.api.nvim_set_keymap(
"v",
"<C-b>",
"coc#float#has_scroll() ? coc#float#scroll(0) : '\\<C-b>'",
{silent = true, nowait = true, expr = true, noremap = true}
)
--[[
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of language server.
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocActionAsync('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>e :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>p :<C-u>CocListResume<CR>
]]
|