From b0647949f8bf0638574c216005ae0776437cdd68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 7 Dec 2020 16:36:17 +0100 Subject: [PATCH] Style and shortcut tweaks. Added vim-which-key. * Shortcut changes to make the Leader-based shortcuts easier to use * Install vim-which-key * Style fixes and changes * Reorganised some of the settings --- bundles-init/nerdtree.cfg.vim | 3 ++ bundles-init/undotree.cfg.vim | 4 ++ bundles-init/vim-fugitive.cfg.vim | 4 +- bundles-init/vim-lsp.cfg.vim | 16 ++++--- bundles-init/vim-which-key.cfg.vim | 69 +++++++++++++++++++++++++++++ bundles-init/vim-which-key.load.vim | 1 + cfg/00-silent.vim | 1 - cfg/01-colours.vim | 2 - cfg/01-timeouts.vim | 3 +- cfg/03-hlsearch.vim | 3 +- cfg/03-mouse.vim | 7 +-- cfg/03-x-copy.vim | 2 + cfg/05-cursor.vim | 8 ++-- cfg/05-line-numbers.vim | 7 +++ cfg/20-plugins.vim | 4 +- cfg/25-man.vim | 5 +-- cfg/50-sign-column.vim | 12 ++++- cfg/50-vertical-split.vim | 9 ++-- cfg/99-paste-toggle.vim | 6 ++- 19 files changed, 131 insertions(+), 35 deletions(-) create mode 100644 bundles-init/vim-which-key.cfg.vim create mode 100644 bundles-init/vim-which-key.load.vim create mode 100644 cfg/03-x-copy.vim create mode 100644 cfg/05-line-numbers.vim diff --git a/bundles-init/nerdtree.cfg.vim b/bundles-init/nerdtree.cfg.vim index 4ff408a..c5d160c 100644 --- a/bundles-init/nerdtree.cfg.vim +++ b/bundles-init/nerdtree.cfg.vim @@ -7,3 +7,6 @@ autocmd VimEnter * if argc() == 0 && &columns > 150 | NERDTree | endif " Set the bookmarks file's path let g:NERDTreeBookmarksFile = GetVardataPath( 'NTBookmarks' ) + +" Hide the sign column +autocmd FileType nerdtree setlocal signcolumn=no diff --git a/bundles-init/undotree.cfg.vim b/bundles-init/undotree.cfg.vim index f7e1987..b408cbf 100644 --- a/bundles-init/undotree.cfg.vim +++ b/bundles-init/undotree.cfg.vim @@ -1 +1,5 @@ +" Keyboard shortcut nnoremap u :UndotreeToggle + +" Hide the sign column +autocmd FileType undotree setlocal signcolumn=no diff --git a/bundles-init/vim-fugitive.cfg.vim b/bundles-init/vim-fugitive.cfg.vim index 78fd9fd..43d5820 100644 --- a/bundles-init/vim-fugitive.cfg.vim +++ b/bundles-init/vim-fugitive.cfg.vim @@ -5,10 +5,12 @@ nnoremap gs :Git nnoremap gc :Git commit -q nnoremap gb :Git branch -" Note: dangerous commands don't have a +" Note: dangerous commands don't have a . Also commands that need +" arguments, obviously. nnoremap gB :Git checkout -b nnoremap gC :Git checkout nnoremap gM :GMove nnoremap gp :Git pull --recurse-submodules nnoremap gP :Git push +nnoremap gr :GRename nnoremap gR :GRemove diff --git a/bundles-init/vim-lsp.cfg.vim b/bundles-init/vim-lsp.cfg.vim index 9490fba..79c937a 100644 --- a/bundles-init/vim-lsp.cfg.vim +++ b/bundles-init/vim-lsp.cfg.vim @@ -9,10 +9,12 @@ let g:lsp_signs_error = {'text': '✗'} let g:lsp_signs_warning = {'text': '‼'} " Keyboard shortcuts -noremap df :LspDocumentFormat -vnoremap df :LspDocumentRangeFormat -noremap dr :LspReferences -noremap :LspDefinition -noremap dR :LspRename -noremap dh :LspHover -noremap ds :LspWorkspaceSymbol +noremap ld :LspDocumentDiagnostics +noremap lf :LspDocumentFormat +noremap lgd :LspDefinition +noremap lgD :LspDeclaration +noremap li :LspHover +noremap lr :LspReferences +noremap lR :LspRename +noremap ls :LspDocumentSymbol +noremap lS :LspWorkspaceSymbol diff --git a/bundles-init/vim-which-key.cfg.vim b/bundles-init/vim-which-key.cfg.vim new file mode 100644 index 0000000..a834f3e --- /dev/null +++ b/bundles-init/vim-which-key.cfg.vim @@ -0,0 +1,69 @@ +" Leader-based key sequences +nnoremap :WhichKey '' +let g:which_key_map = {} +call which_key#register('', 'g:which_key_map') +let g:which_key_fallback_to_native_key = 1 + +" Direct commands +let g:which_key_map[' '] = [ 'call feedkeys(":nohlsearch\n")' , 'clear-search' ] +let g:which_key_map.e = 'file-explorer' +let g:which_key_map.u = 'undo-tree' + +" Options +let g:which_key_map.o = { 'name' : '+options' } +let g:which_key_map.o.c = 'cursor-dir' +let g:which_key_map.o.C = 'cursor-mode' +let g:which_key_map.o.m = 'mouse' +let g:which_key_map.o.n = 'line-numbers' +let g:which_key_map.o.N = 'relative-line-numbers' +let g:which_key_map.o.p = 'paste' +let g:which_key_map.o.w = 'whitespace' +let g:which_key_map.o.s = 'sign-column' + +" Fuzzy finder +let g:which_key_map.p = { 'name' : '+fuzzy-finder' } +let g:which_key_map.p.p = 'buffers' +let g:which_key_map.p.o = 'recent-files' +let g:which_key_map.p.i = 'open-file' + +" Git commands +let g:which_key_map.g = { 'name' : '+git' } +let g:which_key_map.g['+'] = 'add-hunk' +let g:which_key_map.g['-'] = 'revert-hunk' +let g:which_key_map.g['<'] = 'previous-hunk' +let g:which_key_map.g['>'] = 'next-hunk' +let g:which_key_map.g.a = 'add-file' +let g:which_key_map.g.B = 'new-branch' +let g:which_key_map.g.C = 'checkout-branch' +let g:which_key_map.g.c = 'commit' +let g:which_key_map.g.d = 'diff' +let g:which_key_map.g.L = 'log-full' +let g:which_key_map.g.l = 'log-split' +let g:which_key_map.g.M = 'move' +let g:which_key_map.g.P = 'push' +let g:which_key_map.g.p = 'pull' +let g:which_key_map.g.R = 'remove' +let g:which_key_map.g.s = 'status' + +" Help +let g:which_key_map.h = { 'name' : '+help' } +let g:which_key_map.h.m = 'man-page' +let g:which_key_map.h.v = 'vim-help' + +" Language helpers +let g:which_key_map.l = { 'name' : '+language' } +let g:which_key_map.l.d = 'diagnostics' +let g:which_key_map.l.f = 'format' +let g:which_key_map.l.g = { 'name' : '+goto' } +let g:which_key_map.l.g.d = 'declaration' +let g:which_key_map.l.g.D = 'definition' +let g:which_key_map.l.i = 'information' +let g:which_key_map.l.r = 'references' +let g:which_key_map.l.R = 'rename' +let g:which_key_map.l.s = 'document-symbols' +let g:which_key_map.l.s = 'workspace-symbols' + +" Plugins +let g:which_key_map.P = { 'name' : '+plugins' } +let g:which_key_map.P.i = 'install-new' +let g:which_key_map.P.u = 'update' diff --git a/bundles-init/vim-which-key.load.vim b/bundles-init/vim-which-key.load.vim new file mode 100644 index 0000000..76c5d62 --- /dev/null +++ b/bundles-init/vim-which-key.load.vim @@ -0,0 +1 @@ +NeoBundle 'tseeker/vim-which-key' diff --git a/cfg/00-silent.vim b/cfg/00-silent.vim index 4b67c68..5e5329b 100644 --- a/cfg/00-silent.vim +++ b/cfg/00-silent.vim @@ -1,3 +1,2 @@ " 'Silent' command, can be used to run stuff silently then redrawing - command! -nargs=* -bang Silent execute ':silent'.' '. | execute ':redraw!' diff --git a/cfg/01-colours.vim b/cfg/01-colours.vim index f5dcfb6..fc61f43 100644 --- a/cfg/01-colours.vim +++ b/cfg/01-colours.vim @@ -10,8 +10,6 @@ if &t_Co == 256 hi CursorLine cterm=NONE ctermbg=234 hi CursorColumn cterm=NONE ctermbg=233 hi ColorColumn ctermbg=52 - hi LineNr ctermfg=58 - hi CursorLineNr ctermfg=130 hi Search ctermfg=15 ctermbg=53 hi Folded ctermbg=17 ctermfg=227 endif diff --git a/cfg/01-timeouts.vim b/cfg/01-timeouts.vim index c043015..0bf3027 100644 --- a/cfg/01-timeouts.vim +++ b/cfg/01-timeouts.vim @@ -1,8 +1,7 @@ " Timeout settings for key sequences -set notimeout +set timeout set timeoutlen=0 set ttimeout set ttimeoutlen=-1 - " Time between updates set updatetime=100 diff --git a/cfg/03-hlsearch.vim b/cfg/03-hlsearch.vim index 80c8b18..292e578 100644 --- a/cfg/03-hlsearch.vim +++ b/cfg/03-hlsearch.vim @@ -1,2 +1,3 @@ +" Highlight search results, and clear that by hitting space very hard twice. set hlsearch -nnoremap :nohlsearch +nmap :nohlsearch diff --git a/cfg/03-mouse.vim b/cfg/03-mouse.vim index 014408c..0e776c5 100644 --- a/cfg/03-mouse.vim +++ b/cfg/03-mouse.vim @@ -1,4 +1,4 @@ -" Enable mouse by default, provide M shortcut to toggle on/off +" Enable mouse by default, provide om shortcut to toggle on/off function! ToggleMouse() if &g:mouse != "" @@ -11,7 +11,4 @@ function! ToggleMouse() endfunction set mouse=a - -nnoremap M :call ToggleMouse() -vnoremap "+y -set pastetoggle=P +nnoremap om :call ToggleMouse() diff --git a/cfg/03-x-copy.vim b/cfg/03-x-copy.vim new file mode 100644 index 0000000..1dffd1c --- /dev/null +++ b/cfg/03-x-copy.vim @@ -0,0 +1,2 @@ +" Map Ctrl+C to X-compatable copy +vnoremap "+y diff --git a/cfg/05-cursor.vim b/cfg/05-cursor.vim index bd9a614..797ab11 100644 --- a/cfg/05-cursor.vim +++ b/cfg/05-cursor.vim @@ -1,4 +1,4 @@ -" Cursor line & column: ' c' = invert, ' C' = mode, ' n' = line numbers +" Cursor line & column display function! ToggleCursorMode() if &cursorline && &cursorcolumn || !( &cursorline || &cursorcolumn ) set cursorline nocursorcolumn @@ -7,8 +7,6 @@ function! ToggleCursorMode() endif endfunction -nnoremap c :set cursorline! cursorcolumn! -nnoremap C :call ToggleCursorMode() -nnoremap n :set number! - set cursorline number +nnoremap oc :set cursorline! cursorcolumn! +nnoremap oC :call ToggleCursorMode() diff --git a/cfg/05-line-numbers.vim b/cfg/05-line-numbers.vim new file mode 100644 index 0000000..2047954 --- /dev/null +++ b/cfg/05-line-numbers.vim @@ -0,0 +1,7 @@ +" Line number display and related controls +highlight LineNr ctermbg=232 ctermfg=58 cterm=NONE +highlight CursorLineNr ctermbg=232 ctermfg=130 cterm=bold + +set number relativenumber +nnoremap on :set number! +nnoremap oN :set relativenumber! diff --git a/cfg/20-plugins.vim b/cfg/20-plugins.vim index a9d36e0..cf3cb4a 100644 --- a/cfg/20-plugins.vim +++ b/cfg/20-plugins.vim @@ -3,5 +3,5 @@ call DoNeoBundleCheck( ) " Add key mappings for updates and installation -nnoremap Bu :NeoBundleCheckUpdate -nnoremap Bi :call DoNeoBundleCheck() +nnoremap Pu :NeoBundleCheckUpdate +nnoremap Pi :call DoNeoBundleCheck() diff --git a/cfg/25-man.vim b/cfg/25-man.vim index 137aeb2..8026943 100644 --- a/cfg/25-man.vim +++ b/cfg/25-man.vim @@ -1,7 +1,6 @@ -" Make sure :Man is loaded, and map it. - +" Make sure :Man is loaded, and map it. Also, remove the default mapping. if exists( ':Man' ) != 2 source $VIMRUNTIME/ftplugin/man.vim endif - +unmap K nnoremap hm :Man diff --git a/cfg/50-sign-column.vim b/cfg/50-sign-column.vim index 0662fc8..c50be49 100644 --- a/cfg/50-sign-column.vim +++ b/cfg/50-sign-column.vim @@ -1,3 +1,13 @@ " Sign column color and visibility +let s:sc_modes = { +\ 'no' : 'yes' , +\ 'yes' : 'no' , +\ } + +function! ToggleSignColumn() + let &signcolumn = s:sc_modes[ &g:signcolumn ] +endfunction + +highlight SignColumn ctermfg=15 ctermbg=234 set signcolumn=yes -highlight SignColumn ctermbg=234 +nmap os :call ToggleSignColumn() diff --git a/cfg/50-vertical-split.vim b/cfg/50-vertical-split.vim index 920af3b..b8f23e5 100644 --- a/cfg/50-vertical-split.vim +++ b/cfg/50-vertical-split.vim @@ -1,5 +1,8 @@ " Vertical split style and color set fillchars+=vert:┃ -highlight VertSplit ctermbg=234 ctermfg=29 cterm=NONE -highlight StatusLine ctermbg=0 ctermfg=234 cterm=inverse -highlight StatusLineNC ctermbg=234 ctermfg=234 cterm=inverse +highlight VertSplit ctermbg=234 ctermfg=29 cterm=NONE +highlight StatusLine ctermbg=15 ctermfg=234 cterm=inverse +highlight StatusLineNC ctermbg=234 ctermfg=234 cterm=inverse +highlight StatusLineTerm ctermbg=15 ctermfg=234 cterm=inverse +highlight StatusLineTermNC ctermbg=234 ctermfg=234 cterm=inverse +highlight WildMenu ctermbg=29 ctermfg=0 cterm=standout diff --git a/cfg/99-paste-toggle.vim b/cfg/99-paste-toggle.vim index 5aeb438..6f1728f 100644 --- a/cfg/99-paste-toggle.vim +++ b/cfg/99-paste-toggle.vim @@ -1,2 +1,4 @@ -" Configure the paste toggle shortcut -set pastetoggle= +" Configure the paste toggle shortcut and a mapping that also toggles paste, +" for use with vim-which-key. +set pastetoggle=op +nnoremap op :set paste!