From 2e59341d6d82c57bf02197b873c129a7428e36a1 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 21 Nov 2019 13:57:07 +0000 Subject: [PATCH] Move existing mappings into new file Simply take all the mappings and move them to one big new file for now. At some point we can start thinking about splitting them up further, and if that could make sense. The groundwork is laid by vimrc looking for a maps.vim file in every subdirectory of its runtime path. --- .config/nvim/init.vim | 236 ++++-------------------------------------- .config/nvim/maps.vim | 226 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 244 insertions(+), 218 deletions(-) create mode 100644 .config/nvim/maps.vim diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 0bff66e..837b5fb 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -137,11 +137,6 @@ endif " PLUGIN CONFIGURATION {{{ " ================================================================================ -" PLUGIN: vim-sneak -map f Sneak_f -map F Sneak_F -map t Sneak_t -map T Sneak_T let g:sneak#s_next = 1 let g:sneak#use_ic_scs = 1 @@ -215,19 +210,6 @@ let g:pandoc#hypertext#ausosave_on_edit_open_link=1 let g:pandoc#hypertext#create_if_no_alternates_exists=1 let g:pandoc#syntax#conceal#use = 1 let g:pandoc#syntax#conceal#urls = 1 -" -" follow and open links with pandoc -" open a file with either local means, or let the system decide -nnoremap gX :call pandoc#hypertext#OpenSystem() -nnoremap gx :call pandoc#hypertext#OpenLocal() -" open a link in the editor (this buffer, or split) -nnoremap gf :call pandoc#hypertext#OpenLink( g:pandoc#hypertext#edit_open_cmd ) -nnoremap :call pandoc#hypertext#OpenLink( g:pandoc#hypertext#edit_open_cmd ) -nnoremap gF :call pandoc#hypertext#OpenLink( g:pandoc#hypertext#split_open_cmd ) -nnoremap gF :call pandoc#hypertext#OpenLink( g:pandoc#hypertext#split_open_cmd ) -" go back a link -nnoremap gb :call pandoc#hypertext#BackFromLink() -nnoremap :call pandoc#hypertext#BackFromLink() " PLUGIN: wiki.vim if $WIKIROOT ==? "" @@ -241,26 +223,6 @@ let g:wiki_filetypes = ['md', 'mkd', 'markdown', 'wiki'] let g:wiki_link_extension = '.md' let g:wiki_link_target_type = 'md' let g:wiki_mappings_use_defaults = 1 -" overwrites some default mappings I don't use, or that interfere with my own -" mappings TODO: currently this just assigns bogus shortcuts, since the plugin grumbles -" when setting to an empty string -let g:wiki_mappings_global = { - \ '(wiki-journal)' : '===', - \ '(wiki-code-run)' : '====', - \ '(wiki-graph-in)' : '====', - \ '(wiki-graph-out)' : '=====', - \ '(wiki-link-toggle)' : '=======', - \ '(wiki-page-toc)' : '=========', - \ '(wiki-page-toc-local)' : '=============', - \ '(wiki-export)' : '==============', - \ '(wiki-list-uniq)' : '===============', - \ '(wiki-list-uniq-local)' : '================', - \ '(wiki-tag-list)' : '=================', - \ '(wiki-tag-reload)' : '==================', - \ '(wiki-tag-search)' : '=====================', - \ '(wiki-link-toggle-operator)' : '======================', - \} - " PLUGIN: vim-pencil " set default wrap mode to hard - TODO test which mode works better for @@ -359,16 +321,6 @@ command! -bang -nargs=* CiteMarkdown call fzf#run(fzf#wrap({ \ 'up': '25%', \ 'options': '--ansi --multi --prompt "Markdown> "' \ })) -" map @@ to automatically insert citation reference at cursor -inoremap @@ u:call fzf#run(fzf#wrap({ - \ 'source': bibtex_ls(), - \ 'sink*': function('bibtex_cite_sink_insert'), - \ 'up': '25%', - \ 'options': '--ansi --multi --prompt "Cite> "'})) -" map cc to insert a complete citation at cursor -nnoremap cc :CiteRef -" map cm to insert markdown prettified citation -nnoremap cm :CiteMarkdown " PLUGIN: vim-go " change the tabstops for go to use tabs and a width of 4 @@ -517,6 +469,19 @@ call matchadd('ColorColumn', '\%81v', 100) " the directories it is supposed to au BufNewFile,BufRead /dev/shm/gopass.* setlocal noswapfile nobackup noundofile +function! SearchWiki() + let l:curpath=getcwd() + :execute(":cd " . g:wiki_root) + let l:texttofind=input("Search in Notes: ") + :execute(":CtrlSF " . l:texttofind) + :CtrlSFFocus + :execute(":cd " . l:curpath) +endfunction + +" Configure notational-fzf-vim +let g:nv_search_paths = [ g:wiki_root ] +let g:nv_wrap_preview_text=1 + " }}} " KEYBINDINGS {{{ " ================================================================================ @@ -541,174 +506,8 @@ endfunction " use :ShowMaps to call the function com! ShowMaps call s:ShowMaps() " Enable :ShowMaps to call the function -" set our leader key to space since with hjkl, space is largely useless -let mapleader = "\" -" maps the leader for buffer local mappings (e.g. vim-waikiki for files under -" the root dir to the same key -- might lead to incompatibilities, will have -" to test) -let maplocalleader = "\" -" set jk to escape, in case capslock is not mapped to escape on the system -inoremap jk - -" remove search highlights by pressing space+/ - the key for searching the -" first place -nnoremap / :noh - -" split buffers vertically/horizontally with the leader \ or - (mirrors my -" tmux setup) -nnoremap - :sp -nnoremap \ :vsp - -" move around between matching brackets with tab -nnoremap % -nnoremap % - -" Spell check set to O, 'o' for 'orthography': -noremap O :setlocal spell! spelllang=en_us -noremap OE :setlocal spell! spelllang=en_us -noremap OG :setlocal spell! spelllang=de_de -noremap o z= - -" select the whole buffer with -a -nnoremap a ggVG - -" quickly edit vimrc with leader+V -nnoremap V :vsp $MYVIMRC -" automatically source the vimrc file whenever it is saved (causes slowdown -" when done in MANY successions) -" au BufWritePost init.vim so ~/.config/nvim/init.vim -" source vimrc with keystroke combination -nnoremap VV :source $MYVIMRC - -" since u undoes, would it not make sense that U redoes? -nnoremap U - -" when in insertion mode, C-u uppercases the current word, C-l lowercases it, -inoremap gUiw`]a -inoremap guiw`]a - -" get rid of the help message popping up when I miss esc and hit F1 -nnoremap -inoremap -vnoremap - -" yank filename to f buffer -nnoremap yf :let @f = expand("%") - -" remove all trailing whitespaces -" on pressing space+W -nnoremap W :%s/\s\+$//:let @/='' -" automatically on saving -" autocmd BufWritePre * :%s/\s\+$//e - -" 'open new buffer' with leader-t (opens new buffer and switches to it) -" open actual new tab with leader-T -nnoremap t :vsp . -nnoremap T :tabedit . - -" open/close NERDtree with leader-e -" whatever method tree has been opened by, leader-e closes it again -nnoremap e :NERDTreeToggle -" open root of current VCS project in tree -nnoremap :NERDTreeVCS -" open current nerdtree with current file highlighted -nnoremap E :NERDTreeFind - -" vim-go mappings - will only activate in go files -" most of this credit to https://hackernoon.com/my-neovim-setup-for-go-7f7b6e805876 -" switch between test file and function -au Filetype go nnoremap ga (go-alternate-edit) -" switch between test file and function - in a horizontal/vertical split -au Filetype go nnoremap gah (go-alternate-split) -au Filetype go nnoremap gav (go-alternate-vertical) -" run a test (but run it as short version, in case tests are tagged -" accordingly) -au FileType go nnoremap :GoTest -short -" show/hide code coverage of go file -au FileType go nnoremap :GoCoverageToggle -short -" To get the documentation of whatever you are hovering over press K (to go -" back C-t) -- this is enabled by default and needs no bind -" go to the definition of whatever you hover over -au FileType go nnoremap (go-def) - -" Configure notational-fzf-vim -let g:nv_search_paths = [ g:wiki_root ] -let g:nv_wrap_preview_text=1 -" Dictionary with string keys and values. Must be in the form 'ctrl-KEY': -" 'command' or 'alt-KEY' : 'command'. See examples below. -let g:nv_fzf_binds = [ - \ 'alt-a:select-all', - \ 'alt-q:deselect-all', - \ 'alt-p:toggle-preview', - \ 'alt-u:page-up', - \ 'alt-d:page-down', - \ 'ctrl-w:backward-kill-word', - \ ] - - -" Markdown & Pandoc compilation group -" the commented out command can be used if vim-rmarkdown plugin is not -" installed (it is a bit more brittle) -" autocmd FileType rmd noremap :!echo"require(rmarkdown);render('%')"\|R--vanilla -" Compile with rmarkdown -" autocmd FileType markdown,rmarkdown noremap c :RMarkdown pdf -" autocmd FileType markdown,rmarkdown noremap C :RMarkdown! pdf - -function! SearchWiki() - let l:curpath=getcwd() - :execute(":cd " . g:wiki_root) - let l:texttofind=input("Search in Notes: ") - :execute(":CtrlSF " . l:texttofind) - :CtrlSFFocus - :execute(":cd " . l:curpath) -endfunction - -" search in wiki with ctrlsf, in fullscreen window -nnoremap wf :execute(":call SearchWiki()") - -" FUZZY FINDING -" FZF buffers and files in current workdir -noremap s :FzfBuffers -" FZF most recently used / MRU, bound to S since it is essentially a larger -" go-back intention than just buffers -noremap S :FzfHistory -noremap f :FzfFiles - -" use wiki.vim to look through document outlines in fzf (only for note -" directory atm) -nnoremap l :WikiFzfToc - -" FZF general full-text search in cwd with rg -noremap F :FzfRg -" FZF note full-text search with notational-velocity like functions (in wiki -" directory) -noremap n :NV -noremap N :NV! - -" FZF git diff -noremap gd :FzfGFiles? - -" FZF colorschemes -nnoremap :FzfColors -" Toggle background light/dark -call togglebg#map("") - -" Mostly dealing with Prose writing from here on out -" Format current Paragraph (esp useful in prose writing) -nnoremap q gqap -xnoremap q gq -nnoremap Q vapJgqap - -" Enter distraction free prose mode with F11 -noremap :Goyo - -" surround stuff with quotes, from normal or visual mode -nnoremap " viwa"bi"lel -vnoremap " ``>la"l - -" stronger versions of left,right - move all the way -nnoremap H ^ -nnoremap L $ +" Begin mapping definitions +runtime! **/maps.vim " }}} " ABBREVIATIONS {{{ @@ -721,8 +520,9 @@ iabbrev whit with iabbrev whith with " Text expansion -iabbrev @e@ marty.oehme@gmail.com -iabbrev ccopy Copyright 2019 Marty Oehme, all rights reserved. +iabbrev mo@ marty.oehme@gmail.com +iabbrev mo.me@ +iabbrev mcc@ Copyright 2019 Marty Oehme, all rights reserved. " " }}} diff --git a/.config/nvim/maps.vim b/.config/nvim/maps.vim new file mode 100644 index 0000000..6ba3a0a --- /dev/null +++ b/.config/nvim/maps.vim @@ -0,0 +1,226 @@ +" The general ideas behind these mappings: +" +" * Leader prefix is the generally preferred way to map new things, however +" only for those that affect all of vim +" +" * Localleader prefix is used for mappings which only affect single buffers, +" in other words mostly filetype specific mappings +" +" many of these mapping ideas come from Tom Ryder who has them nicely +" documented + +" backspace to switch to alternate (last) buffer +nnoremap + +" since u undoes, would it not make sense that U redoes? +nnoremap U + +" stronger versions of left,right - move all the way to beginning/end of line +nnoremap H ^ +nnoremap L $ + +" move around between matching brackets with tab +nnoremap % +nnoremap % + +" when in insertion mode, C-u uppercases the current word, C-l lowercases it, +inoremap gUiw`]a +inoremap guiw`]a + +" yank filename to f buffer +nnoremap yf :let @f = expand("%") + +" repeat the last substitute command with all its flags preserved +noremap & + \ :&& +ounmap & +sunmap & + +" bracket pairings to go to the next/previous of: +" (works with count prefixes) +" +" Argument list +nnoremap [a + \ :previous +nnoremap ]a + \ :next +" Buffers +nnoremap [b + \ :bprevious +nnoremap ]b + \ :bnext +" Quickfix list +nnoremap [c + \ :cprevious +nnoremap ]c + \ :cnext +" Location list +nnoremap [l + \ :lprevious +nnoremap ]l + \ :lnext + +" set our leader key to space since with hjkl, space is largely useless +let mapleader = "\" +" maps the leader for buffer local mappings +" since we are (atm) using sneak to go fwd/bwd in fFtT searches, comma does +" not do too many useful things and can be taken up as localleader +let maplocalleader = "," + +" If we mapped localleader to comma, we can still get to its original function +" by douple-tapping it. +if maplocalleader ==# ',' + noremap ,, , + sunmap ,, +endif + +" remove search highlights by pressing space+/ - the key for searching the +" first place +nnoremap / :noh + +" split buffers vertically/horizontally with the leader \ or - (mirrors my +" tmux setup) +nnoremap - :sp +nnoremap \ :vsp +" 'open new buffer' with leader-t (opens new buffer containing current dir and switches to it) +nnoremap t :vsp . +" open actual new tab with leader-T +nnoremap T :tabedit . + +" select the whole buffer with -a +nnoremap a ggVG + +" CONFIG EDITING +" quickly edit vimrc with leader+V +nnoremap V :vsp $MYVIMRC +" automatically source the vimrc file whenever it is saved (causes slowdown +" when done in MANY successions) +" au BufWritePost init.vim so ~/.config/nvim/init.vim +" source vimrc with keystroke combination +nnoremap VV :source $MYVIMRC + +" PLUGIN: vim-sneak +map f Sneak_f +map F Sneak_F +map t Sneak_t +map T Sneak_T + +" SPELL CHECKING +" Spell check set to O, 'o' for 'orthography': +" Move to the prev/next spelling error with [S ]S +" Move to the prev/next spelling error or suggestion with [s ]s +noremap O :setlocal spell! spelllang=en_us +noremap OE :setlocal spell! spelllang=en_us +noremap OG :setlocal spell! spelllang=de_de +noremap o z= + +" PLUGIN: NERDTree +" open/close NERDtree with leader-e +" whatever method tree has been opened by, leader-e closes it again +nnoremap e :NERDTreeToggle +" open root of current VCS project in tree +nnoremap :NERDTreeVCS +" open current nerdtree with current file highlighted +nnoremap E :NERDTreeFind + +" PLUGIN: FZF GLOBAL FUZZY FINDING +" FZF buffers and files in current workdir +noremap s :FzfBuffers +" FZF most recently used / MRU, bound to S since it is essentially a larger +" go-back intention than just buffers +noremap S :FzfHistory +" fuzzy find files in cwd +noremap f :FzfFiles + +" FZF general full-text search in cwd with rg +noremap F :FzfRg +" FZF git diff +noremap gd :FzfGFiles? + +" FZF colorschemes +nnoremap :FzfColors +" Toggle background light/dark +call togglebg#map("") + +" Note Searching +" PLUGIN: Notational-FZF +" set notational-fzf-vim keys for the NV window itself +let g:nv_fzf_binds = [ + \ 'alt-a:select-all', + \ 'alt-q:deselect-all', + \ 'alt-p:toggle-preview', + \ 'alt-u:page-up', + \ 'alt-d:page-down', + \ 'ctrl-w:backward-kill-word', + \ ] +" FZF note full-text search with notational-velocity like functions (in wiki +" directory) +noremap n :NV +noremap N :NV! +" PLUGIN: CtrlSF +" (non-fuzzy) search in wiki with ctrlsf, in fullscreen window +nnoremap wf :execute(":call SearchWiki()") + +" PLUGIN: vim-go +" vim-go mappings - will only activate in go files +" most of this credit to https://hackernoon.com/my-neovim-setup-for-go-7f7b6e805876 +" switch between test file and function +au Filetype go nnoremap ga (go-alternate-edit) +" switch between test file and function - in a horizontal/vertical split +au Filetype go nnoremap gah (go-alternate-split) +au Filetype go nnoremap gav (go-alternate-vertical) +" run a test (but run it as short version, in case tests are tagged +" accordingly) +au FileType go nnoremap :GoTest -short +" show/hide code coverage of go file +au FileType go nnoremap :GoCoverageToggle -short +" To get the documentation of whatever you are hovering over press K (to go +" back C-t) -- this is enabled by default and needs no bind +" go to the definition of whatever you hover over +au FileType go nnoremap (go-def) + +" PLUGIN: wiki.vim +" use wiki.vim to look through document outlines in fzf (only for note +" directory atm) +nnoremap l :WikiFzfToc +" overwrites some default mappings I don't use, or that interfere with my own +" mappings TODO: currently this just assigns bogus shortcuts, since the plugin grumbles +" when setting to an empty string +let g:wiki_mappings_global = { + \ '(wiki-journal)' : '===', + \ '(wiki-code-run)' : '====', + \ '(wiki-graph-in)' : '====', + \ '(wiki-graph-out)' : '=====', + \ '(wiki-link-toggle)' : '=======', + \ '(wiki-page-toc)' : '=========', + \ '(wiki-page-toc-local)' : '=============', + \ '(wiki-export)' : '==============', + \ '(wiki-list-uniq)' : '===============', + \ '(wiki-list-uniq-local)' : '================', + \ '(wiki-tag-list)' : '=================', + \ '(wiki-tag-reload)' : '==================', + \ '(wiki-tag-search)' : '=====================', + \ '(wiki-link-toggle-operator)' : '======================', + \} + +" Mostly dealing with Prose writing from here on out +" Format current Paragraph (esp useful in prose writing) +nnoremap q gqap +xnoremap q gq +nnoremap Q vapJgqap + +" PLUGIN: GOYO +" Enter distraction free prose mode with F11 +noremap :Goyo + +" PLUGIN: fzf-bibtex +" map @@ to automatically insert citation reference at cursor +inoremap @@ u:call fzf#run(fzf#wrap({ + \ 'source': bibtex_ls(), + \ 'sink*': function('bibtex_cite_sink_insert'), + \ 'up': '25%', + \ 'options': '--ansi --multi --prompt "Cite> "'})) +" map cc to insert a complete citation at cursor +nnoremap cc :CiteRef +" map cm to insert markdown prettified citation +nnoremap cm :CiteMarkdown