summaryrefslogtreecommitdiff
path: root/.config/nvim/keys
diff options
context:
space:
mode:
authorVito Graffagnino <vito@graffagnino.xyz>2020-09-09 14:53:26 +0100
committerVito Graffagnino <vito@graffagnino.xyz>2020-09-09 14:53:26 +0100
commit0d16d52492938dd92591b1278a73d50ef388c633 (patch)
tree2f342456a71b8c52dab89cb0311d033c24e54896 /.config/nvim/keys
parent3b0142cedcde39e4c2097ecd916a870a3ced5ec6 (diff)
update/modularised nvim config files
Diffstat (limited to '.config/nvim/keys')
-rw-r--r--.config/nvim/keys/mappings.vim73
-rw-r--r--.config/nvim/keys/which-key.vim170
2 files changed, 243 insertions, 0 deletions
diff --git a/.config/nvim/keys/mappings.vim b/.config/nvim/keys/mappings.vim
new file mode 100644
index 0000000..929414b
--- /dev/null
+++ b/.config/nvim/keys/mappings.vim
@@ -0,0 +1,73 @@
+" g Leader key
+let mapleader=","
+let localleader=",,"
+nnoremap <Space> <Nop>
+map <leader>v :edit $MYVIMRC<CR>
+
+" Better indenting
+vnoremap < <gv
+vnoremap > >gv
+
+" Better nav for omnicomplete
+inoremap <expr> <c-j> ("\<C-n>")
+inoremap <expr> <c-k> ("\<C-p>")
+
+" TAB in general mode will move to text buffer
+nnoremap <silent> <TAB> :bnext<CR>
+" SHIFT-TAB will go back
+nnoremap <silent> <S-TAB> :bprevious<CR>
+
+" Use control-c instead of escape
+nnoremap <silent> <C-c> <Esc>
+" <TAB>: completion.
+inoremap <silent> <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
+
+" Better window navigation
+nnoremap <C-h> <C-w>h
+nnoremap <C-j> <C-w>j
+nnoremap <C-k> <C-w>k
+nnoremap <C-l> <C-w>l
+
+" Use alt + hjkl to resize windows
+nnoremap <silent> <M-j> :resize -2<CR>
+nnoremap <silent> <M-k> :resize +2<CR>
+nnoremap <silent> <M-h> :vertical resize -2<CR>
+nnoremap <silent> <M-l> :vertical resize +2<CR>
+
+" Copy selected text to system clipboard (requires gvim/nvim/vim-x11 installed):
+vnoremap <C-c> "+y
+map <C-p> "+P
+
+" Binary File Settings ---- {{{
+"
+" Hex read
+nmap <leader>hr :%!xxd<CR> :set filetype=xxd<CR>
+" Hex write
+nmap <leader>hw :%!xxd -r<CR> :set binary<CR> :set filetype=xxd<CR>
+"
+" }}}
+" Info Pages Settings ----- {{{
+"
+" Set up the reading of info from within vim (use :Info whatever)
+
+nnoremap <F1> :exe ":Info ".expand("<cword>")<CR>
+
+"
+" }}}
+" Terminal Emulator ----- {{{
+"
+"
+tnoremap <Esc> <C-\><C-n>
+
+" Usel alt+hjkl to move between windows
+
+tnoremap <A-h> <C-\><C-n><C-w>h
+tnoremap <A-j> <C-\><C-n><C-w>j
+tnoremap <A-k> <C-\><C-n><C-w>k
+tnoremap <A-l> <C-\><C-n><C-w>l
+nnoremap <A-h> <C-w>h
+nnoremap <A-j> <C-w>j
+nnoremap <A-k> <C-w>k
+nnoremap <A-l> <C-w>l
+"
+" }}}
diff --git a/.config/nvim/keys/which-key.vim b/.config/nvim/keys/which-key.vim
new file mode 100644
index 0000000..87eda18
--- /dev/null
+++ b/.config/nvim/keys/which-key.vim
@@ -0,0 +1,170 @@
+" Map leader to which_key
+nnoremap <silent> <leader> :silent WhichKey '<Space>'<CR>
+vnoremap <silent> <leader> :silent <c-u> :silent WhichKeyVisual '<Space>'<CR>
+
+" Create map to add keys to
+let g:which_key_map = {}
+" Define a separator
+let g:which_key_sep = '→'
+" set timeoutlen=100
+
+
+" Not a fan of floating windows for this
+let g:which_key_use_floating_win = 0
+
+" Change the colors if you want
+highlight default link WhichKey Operator
+highlight default link WhichKeySeperator DiffAdded
+highlight default link WhichKeyGroup Identifier
+highlight default link WhichKeyDesc Function
+
+" Hide status line
+autocmd! FileType which_key
+autocmd FileType which_key set laststatus=0 noshowmode noruler
+ \| autocmd BufLeave <buffer> set laststatus=2 noshowmode ruler
+
+" Single mappings
+let g:which_key_map['/'] = [ '<Plug>NERDCommenterToggle' , 'comment' ]
+let g:which_key_map['.'] = [ ':e $MYVIMRC' , 'open init' ]
+let g:which_key_map[';'] = [ ':Commands' , 'commands' ]
+let g:which_key_map['='] = [ '<C-W>=' , 'balance windows' ]
+let g:which_key_map[','] = [ 'Startify' , 'start screen' ]
+let g:which_key_map['d'] = [ ':bd' , 'delete buffer']
+let g:which_key_map['e'] = [ ':CocCommand explorer' , 'explorer' ]
+let g:which_key_map['f'] = [ ':Files' , 'search files' ]
+let g:which_key_map['h'] = [ '<C-W>s' , 'split below']
+let g:which_key_map['q'] = [ 'q' , 'quit' ]
+let g:which_key_map['r'] = [ ':RnvimrToggle' , 'ranger' ]
+let g:which_key_map['S'] = [ ':SSave' , 'save session' ]
+let g:which_key_map['T'] = [ ':Rg' , 'search text' ]
+let g:which_key_map['v'] = [ '<C-W>v' , 'split right']
+let g:which_key_map['w'] = [ 'w' , 'write' ]
+let g:which_key_map['z'] = [ 'Goyo' , 'zen' ]
+
+" Group mappings
+
+" b is for buffer
+let g:which_key_map.b = {
+ \ 'name' : '+buffer' ,
+ \ '1' : ['b1' , 'buffer 1'] ,
+ \ '2' : ['b2' , 'buffer 2'] ,
+ \ 'd' : ['bd' , 'delete-buffer'] ,
+ \ 'f' : ['bfirst' , 'first-buffer'] ,
+ \ 'h' : ['Startify' , 'home-buffer'] ,
+ \ 'l' : ['blast' , 'last-buffer'] ,
+ \ 'n' : ['bnext' , 'next-buffer'] ,
+ \ 'p' : ['bprevious' , 'previous-buffer'] ,
+ \ '?' : ['Buffers' , 'fzf-buffer'] ,
+ \ }
+
+" s is for search
+let g:which_key_map.s = {
+ \ 'name' : '+search' ,
+ \ '/' : [':History/' , 'history'],
+ \ ';' : [':Commands' , 'commands'],
+ \ 'a' : [':Ag' , 'text Ag'],
+ \ 'b' : [':BLines' , 'current buffer'],
+ \ 'B' : [':Buffers' , 'open buffers'],
+ \ 'c' : [':Commits' , 'commits'],
+ \ 'C' : [':BCommits' , 'buffer commits'],
+ \ 'f' : [':Files' , 'files'],
+ \ 'g' : [':GFiles' , 'git files'],
+ \ 'G' : [':GFiles?' , 'modified git files'],
+ \ 'h' : [':History' , 'file history'],
+ \ 'H' : [':History:' , 'command history'],
+ \ 'l' : [':Lines' , 'lines'] ,
+ \ 'm' : [':Marks' , 'marks'] ,
+ \ 'M' : [':Maps' , 'normal maps'] ,
+ \ 'p' : [':Helptags' , 'help tags'] ,
+ \ 'P' : [':Tags' , 'project tags'],
+ \ 's' : [':Snippets' , 'snippets'],
+ \ 'S' : [':Colors' , 'color schemes'],
+ \ 't' : [':Rg' , 'text Rg'],
+ \ 'T' : [':BTags' , 'buffer tags'],
+ \ 'w' : [':Windows' , 'search windows'],
+ \ 'y' : [':Filetypes' , 'file types'],
+ \ 'z' : [':FZF' , 'FZF'],
+ \ }
+
+" g is for git
+let g:which_key_map.g = {
+ \ 'name' : '+git' ,
+ \ 'a' : [':Git add .' , 'add all'],
+ \ 'A' : [':Git add %' , 'add current'],
+ \ 'b' : [':Git blame' , 'blame'],
+ \ 'B' : [':GBrowse' , 'browse'],
+ \ 'c' : [':Git commit -m "autocommit"' , 'commit'],
+ \ 'd' : [':Git diff' , 'diff'],
+ \ 'D' : [':Gdiffsplit' , 'diff split'],
+ \ 'g' : [':GGrep' , 'git grep'],
+ \ 'G' : [':Gstatus' , 'status'],
+ \ 'h' : [':GitGutterLineHighlightsToggle' , 'highlight hunks'],
+ \ 'H' : ['<Plug>(GitGutterPreviewHunk)' , 'preview hunk'],
+ \ 'j' : ['<Plug>(GitGutterNextHunk)' , 'next hunk'],
+ \ 'k' : ['<Plug>(GitGutterPrevHunk)' , 'prev hunk'],
+ \ 'l' : [':Git log' , 'log'],
+ \ 'p' : [':Git push' , 'push'],
+ \ 'P' : [':Git pull' , 'pull'],
+ \ 'r' : [':GRemove' , 'remove'],
+ \ 's' : ['<Plug>(GitGutterStageHunk)' , 'stage hunk'],
+ \ 't' : [':GitGutterSignsToggle' , 'toggle signs'],
+ \ 'u' : ['<Plug>(GitGutterUndoHunk)' , 'undo hunk'],
+ \ 'v' : [':GV' , 'view commits'],
+ \ 'V' : [':GV!' , 'view buffer commits'],
+ \ }
+
+" l is for language server protocol
+let g:which_key_map.l = {
+ \ 'name' : '+lsp' ,
+ \ '.' : [':CocConfig' , 'config'],
+ \ ';' : ['<Plug>(coc-refactor)' , 'refactor'],
+ \ 'a' : ['<Plug>(coc-codeaction)' , 'line action'],
+ \ 'A' : ['<Plug>(coc-codeaction-selected)' , 'selected action'],
+ \ 'b' : [':CocNext' , 'next action'],
+ \ 'B' : [':CocPrev' , 'prev action'],
+ \ 'c' : [':CocList commands' , 'commands'],
+ \ 'd' : ['<Plug>(coc-definition)' , 'definition'],
+ \ 'D' : ['<Plug>(coc-declaration)' , 'declaration'],
+ \ 'e' : [':CocList extensions' , 'extensions'],
+ \ 'f' : ['<Plug>(coc-format-selected)' , 'format selected'],
+ \ 'F' : ['<Plug>(coc-format)' , 'format'],
+ \ 'h' : ['<Plug>(coc-float-hide)' , 'hide'],
+ \ 'i' : ['<Plug>(coc-implementation)' , 'implementation'],
+ \ 'I' : [':CocList diagnostics' , 'diagnostics'],
+ \ 'j' : ['<Plug>(coc-float-jump)' , 'float jump'],
+ \ 'l' : ['<Plug>(coc-codelens-action)' , 'code lens'],
+ \ 'n' : ['<Plug>(coc-diagnostic-next)' , 'next diagnostic'],
+ \ 'N' : ['<Plug>(coc-diagnostic-next-error)' , 'next error'],
+ \ 'o' : ['<Plug>(coc-openlink)' , 'open link'],
+ \ 'O' : [':CocList outline' , 'outline'],
+ \ 'p' : ['<Plug>(coc-diagnostic-prev)' , 'prev diagnostic'],
+ \ 'P' : ['<Plug>(coc-diagnostic-prev-error)' , 'prev error'],
+ \ 'q' : ['<Plug>(coc-fix-current)' , 'quickfix'],
+ \ 'r' : ['<Plug>(coc-rename)' , 'rename'],
+ \ 'R' : ['<Plug>(coc-references)' , 'references'],
+ \ 's' : [':CocList -I symbols' , 'references'],
+ \ 't' : ['<Plug>(coc-type-definition)' , 'type definition'],
+ \ 'u' : [':CocListResume' , 'resume list'],
+ \ 'U' : [':CocUpdate' , 'update CoC'],
+ \ 'v' : [':Vista!!' , 'tag viewer'],
+ \ 'z' : [':CocDisable' , 'disable CoC'],
+ \ 'Z' : [':CocEnable' , 'enable CoC'],
+ \ }
+
+
+" t is for toggle
+let g:which_key_map.t = {
+ \ 'name' : '+toggle' ,
+ \ 'c' : [':ColorizerToggle' , 'colorizer'],
+ \ 'e' : [':CocCommand explorer' , 'explorer'],
+ \ 'n' : [':set nonumber!' , 'line-numbers'],
+ \ 'r' : [':set norelativenumber!' , 'relative line nums'],
+ \ 's' : [':let @/ = ""' , 'remove search highlight'],
+ \ 't' : [':FloatermToggle' , 'terminal'],
+ \ 'v' : [':Vista!!' , 'tag viewer'],
+ \ }
+
+" Register which key map
+call which_key#register('<Space>', "g:which_key_map")
+
+