diff options
author | HampusM <hampus@hampusmat.com> | 2022-09-18 11:39:25 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2022-09-18 11:39:25 +0200 |
commit | 3c238894c5b6f15c5f27cea8bd3785eb0f1ebf0f (patch) | |
tree | 68292df2b0cd698484d26057a4faf914e9ea6300 /lua/maps/coc.lua | |
parent | d8fa264ac732286dcf9234bc40e60eeb7e230ca7 (diff) |
add config
Diffstat (limited to 'lua/maps/coc.lua')
-rw-r--r-- | lua/maps/coc.lua | 160 |
1 files changed, 160 insertions, 0 deletions
diff --git a/lua/maps/coc.lua b/lua/maps/coc.lua new file mode 100644 index 0000000..d7b2b3c --- /dev/null +++ b/lua/maps/coc.lua @@ -0,0 +1,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> + +]] |