2021-09-01 00:15:10 +02:00
|
|
|
map = vim.api.nvim_set_keymap
|
|
|
|
|
|
|
|
function escape_keycode(keycode)
|
|
|
|
return vim.api.nvim_replace_termcodes(keycode, true, true, true)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function check_back_space()
|
|
|
|
local col = vim.fn.col(".") - 1
|
|
|
|
return col <= 0 or vim.fn.getline("."):sub(col, col):match("%s")
|
|
|
|
end
|
|
|
|
|
|
|
|
function tab_completion()
|
|
|
|
if vim.fn.pumvisible() > 0 then
|
|
|
|
return escape_keycode("<C-n>")
|
|
|
|
end
|
|
|
|
|
|
|
|
if check_back_space() then
|
|
|
|
return escape_keycode("<TAB>")
|
|
|
|
end
|
|
|
|
|
|
|
|
return vim.fn["coc#refresh"]()
|
|
|
|
end
|
|
|
|
|
|
|
|
function shift_tab_completion()
|
|
|
|
if vim.fn.pumvisible() > 0 then
|
|
|
|
return escape_keycode("<C-p>")
|
|
|
|
else
|
|
|
|
return escape_keycode("<C-h>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function cr_completion()
|
|
|
|
if vim.fn.pumvisible() > 0 then
|
|
|
|
return vim.fn["coc#_select_confirm"]()
|
|
|
|
else
|
|
|
|
return escape_keycode("<CR>")
|
|
|
|
end
|
|
|
|
end
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- Getting stuck in ~~vim~~ terminal
|
2021-04-20 14:43:22 +02:00
|
|
|
map("t", "<Esc>", "<C-\\><C-n>", {})
|
|
|
|
map("n", "fzf", ":FZF<CR>", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- Quick cursor movement
|
2021-04-20 14:43:22 +02:00
|
|
|
map("n", "<C-Down>", "5j", { noremap = true })
|
|
|
|
map("n", "<C-Up>", "5k", { noremap = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- Quick pasting/yoinking to system register
|
|
|
|
map("n", "+y", "\"+y", { noremap = true })
|
|
|
|
map("n", "+p", "\"+p", { noremap = true })
|
|
|
|
map("n", "+d", "\"+d", { noremap = true })
|
|
|
|
|
|
|
|
map("n", "*y", "\"*y", { noremap = true })
|
|
|
|
map("n", "*p", "\"*p", { noremap = true })
|
|
|
|
map("n", "*d", "\"*d", { noremap = true })
|
|
|
|
|
2021-09-01 00:15:10 +02:00
|
|
|
map("i", "<TAB>", "v:lua.tab_completion()", { expr = true })
|
|
|
|
map("i", "<S-TAB>", "v:lua.shift_tab_completion()", { expr = true })
|
|
|
|
map("i", "<CR>", "v:lua.cr_completion()", { expr = true })
|
|
|
|
|
2021-04-20 14:34:02 +02:00
|
|
|
-- symbol renaming
|
2021-05-13 16:37:41 +02:00
|
|
|
map("n", "-n", "<Plug>(coc-rename)", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
-- apply AutoFix to problem on current line
|
2021-05-13 16:37:41 +02:00
|
|
|
map("n", "-f", "<Plug>(coc-fix-current)", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
-- open action dialog
|
2021-05-13 16:37:41 +02:00
|
|
|
map("n", "-a", ":CocAction<CR>", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- GoTo code navigation.
|
2021-04-20 14:43:22 +02:00
|
|
|
map("n", "gd", "<Plug>(coc-definition)", { silent = true })
|
|
|
|
map("n", "gy", "<Plug>(coc-type-definition)", { silent = true })
|
|
|
|
map("n", "gi", "<Plug>(coc-implementation)", { silent = true })
|
|
|
|
map("n", "gr", "<Plug>(coc-references)", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- Use K to show documentation in preview window.
|
2021-04-20 14:43:22 +02:00
|
|
|
map("n", "K", ":call CocActionAsync(\'doHover\')<CR>", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- use space o to show symbols
|
2021-04-20 14:43:22 +02:00
|
|
|
map("n", "<space>o", ":CocList -I symbols<CR>", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
|
|
|
-- format code
|
2021-05-13 16:37:41 +02:00
|
|
|
map("n", "-r", ":call CocActionAsync(\'format\')<CR>", { silent = true })
|
2021-04-20 14:34:02 +02:00
|
|
|
|
2021-04-20 15:12:56 +02:00
|
|
|
-- Use <c-space> to trigger completion.
|
|
|
|
map("i", "<c-space>", "coc#refresh()", { silent = true, expr = true })
|
|
|
|
|
2021-05-13 16:37:41 +02:00
|
|
|
-- Use -d to jump to next diagnostic
|
|
|
|
map("n", "-d", "<Plug>(coc-diagnostic-next)", { silent = true })
|
2021-04-24 15:58:23 +02:00
|
|
|
|
2021-05-13 16:37:41 +02:00
|
|
|
-- Use -o to show outline
|
|
|
|
map("n", "-o", ":CocList outline<CR>", { silent = true })
|