summaryrefslogtreecommitdiff
path: root/lua/maps
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-09-18 11:39:25 +0200
committerHampusM <hampus@hampusmat.com>2022-09-18 11:39:25 +0200
commit3c238894c5b6f15c5f27cea8bd3785eb0f1ebf0f (patch)
tree68292df2b0cd698484d26057a4faf914e9ea6300 /lua/maps
parentd8fa264ac732286dcf9234bc40e60eeb7e230ca7 (diff)
add config
Diffstat (limited to 'lua/maps')
-rw-r--r--lua/maps/NERDtree.lua2
-rw-r--r--lua/maps/auto_close.lua24
-rw-r--r--lua/maps/buffer.lua6
-rw-r--r--lua/maps/coc.lua160
-rw-r--r--lua/maps/find.lua8
-rw-r--r--lua/maps/init.lua7
-rw-r--r--lua/maps/terminal.lua37
7 files changed, 244 insertions, 0 deletions
diff --git a/lua/maps/NERDtree.lua b/lua/maps/NERDtree.lua
new file mode 100644
index 0000000..15c933d
--- /dev/null
+++ b/lua/maps/NERDtree.lua
@@ -0,0 +1,2 @@
+vim.api.nvim_set_keymap("n", "<C-e>", ":NERDTreeToggle<CR>",
+ {silent = true, noremap = true})
diff --git a/lua/maps/auto_close.lua b/lua/maps/auto_close.lua
new file mode 100644
index 0000000..9da8c5f
--- /dev/null
+++ b/lua/maps/auto_close.lua
@@ -0,0 +1,24 @@
+vim.api.nvim_set_keymap("i", "\"",
+ "\"\"<left>",
+ {silent = true, noremap = true})
+
+vim.api.nvim_set_keymap("i", "'",
+ "''<left>",
+ {silent = true, noremap = true})
+
+vim.api.nvim_set_keymap("i", "(",
+ "()<left>",
+ {silent = true, noremap = true})
+
+vim.api.nvim_set_keymap("i", "[",
+ "[]<left>",
+ {silent = true, noremap = true})
+
+vim.api.nvim_set_keymap("i", "{",
+ "{}<left>",
+ {silent = true, noremap = true})
+
+vim.api.nvim_set_keymap("i", "{<CR>",
+ "{<CR>}<ESC>O",
+ {silent = true, noremap = true})
+
diff --git a/lua/maps/buffer.lua b/lua/maps/buffer.lua
new file mode 100644
index 0000000..99a11f6
--- /dev/null
+++ b/lua/maps/buffer.lua
@@ -0,0 +1,6 @@
+-- Close the current buffer
+vim.api.nvim_set_keymap(
+ "n",
+ "<leader>q", ":lua close_current_buffer()<CR>",
+ { silent = true, noremap = true }
+)
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>
+
+]]
diff --git a/lua/maps/find.lua b/lua/maps/find.lua
new file mode 100644
index 0000000..5d4bfbe
--- /dev/null
+++ b/lua/maps/find.lua
@@ -0,0 +1,8 @@
+vim.api.nvim_set_keymap("n", "<leader>p", ":Files<CR>", { silent = true, noremap = true })
+
+vim.api.nvim_set_keymap("n", "<leader>b", ":Buffers<CR>", { silent = true, noremap = true })
+
+vim.api.nvim_set_keymap("n", "<leader>c", ":Commits<CR>", { silent = true, noremap = true })
+
+vim.api.nvim_set_keymap("n", "<leader>f", ":Ag ", { noremap = true })
+
diff --git a/lua/maps/init.lua b/lua/maps/init.lua
new file mode 100644
index 0000000..43f1632
--- /dev/null
+++ b/lua/maps/init.lua
@@ -0,0 +1,7 @@
+require("maps.coc")
+require("maps.NERDtree")
+require("maps.terminal")
+require("maps.auto_close")
+require("maps.find")
+require("maps.buffer")
+
diff --git a/lua/maps/terminal.lua b/lua/maps/terminal.lua
new file mode 100644
index 0000000..cf6f999
--- /dev/null
+++ b/lua/maps/terminal.lua
@@ -0,0 +1,37 @@
+vim.api.nvim_set_keymap(
+ "n",
+ "<leader>t",
+ ":lua toggle_terminal(vim.g.terminal_height)<CR>",
+ {silent = true, noremap = true}
+)
+
+vim.api.nvim_set_keymap(
+ "i",
+ "<leader>t",
+ "<Esc>:lua toggle_terminal(vim.g.terminal_height)<CR>",
+ {silent = true, noremap = true}
+)
+
+vim.api.nvim_set_keymap(
+ "t",
+ "<leader>t",
+ "<C-\\><C-n>:lua toggle_terminal(vim.g.terminal_height)<CR>",
+ {silent = true, noremap = true}
+)
+
+-- Terminal go back to normal mode
+vim.api.nvim_set_keymap(
+ "t",
+ "<Esc>",
+ "<C-\\><C-n>",
+ {noremap = true}
+)
+
+vim.api.nvim_set_keymap(
+ "t",
+ ":q!",
+ "<C-\\><C-n>:q!<CR>",
+ {noremap = true}
+)
+
+