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.
This commit is contained in:
Marty Oehme 2019-11-21 13:57:07 +00:00
parent 8798642c61
commit 2e59341d6d
2 changed files with 244 additions and 218 deletions

View file

@ -137,11 +137,6 @@ endif
" PLUGIN CONFIGURATION {{{
" ================================================================================
" PLUGIN: vim-sneak
map f <Plug>Sneak_f
map F <Plug>Sneak_F
map t <Plug>Sneak_t
map T <Plug>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 <silent> gX :<C-u>call pandoc#hypertext#OpenSystem()<cr>
nnoremap <silent> gx :<C-u>call pandoc#hypertext#OpenLocal()<cr>
" open a link in the editor (this buffer, or split)
nnoremap <silent> gf :<C-u>call pandoc#hypertext#OpenLink( g:pandoc#hypertext#edit_open_cmd )<cr>
nnoremap <silent> <CR> :<C-u>call pandoc#hypertext#OpenLink( g:pandoc#hypertext#edit_open_cmd )<cr>
nnoremap <silent> gF :<C-u>call pandoc#hypertext#OpenLink( g:pandoc#hypertext#split_open_cmd )<cr>
nnoremap <silent> gF :<C-u>call pandoc#hypertext#OpenLink( g:pandoc#hypertext#split_open_cmd )<cr>
" go back a link
nnoremap <silent> gb :<C-u>call pandoc#hypertext#BackFromLink()<cr>
nnoremap <silent> <BS> :<C-u>call pandoc#hypertext#BackFromLink()<cr>
" 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 = {
\ '<plug>(wiki-journal)' : '<leader>===',
\ '<plug>(wiki-code-run)' : '<leader>====',
\ '<plug>(wiki-graph-in)' : '<leader>====',
\ '<plug>(wiki-graph-out)' : '<leader>=====',
\ '<plug>(wiki-link-toggle)' : '<leader>=======',
\ '<plug>(wiki-page-toc)' : '<leader>=========',
\ '<plug>(wiki-page-toc-local)' : '<leader>=============',
\ '<plug>(wiki-export)' : '<leader>==============',
\ '<plug>(wiki-list-uniq)' : '<leader>===============',
\ '<plug>(wiki-list-uniq-local)' : '<leader>================',
\ '<plug>(wiki-tag-list)' : '<leader>=================',
\ '<plug>(wiki-tag-reload)' : '<leader>==================',
\ '<plug>(wiki-tag-search)' : '<leader>=====================',
\ '<plug>(wiki-link-toggle-operator)' : '<leader>======================',
\}
" 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 <silent> @@ <c-g>u<c-o>:call fzf#run(fzf#wrap({
\ 'source': <sid>bibtex_ls(),
\ 'sink*': function('<sid>bibtex_cite_sink_insert'),
\ 'up': '25%',
\ 'options': '--ansi --multi --prompt "Cite> "'}))<CR>
" map <leader>cc to insert a complete citation at cursor
nnoremap <silent> <leader>cc :CiteRef<cr>
" map <leader>cm to insert markdown prettified citation
nnoremap <silent> <leader>cm :CiteMarkdown<cr>
" 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 = "\<Space>"
" 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 = "\<Space>"
" set jk to escape, in case capslock is not mapped to escape on the system
inoremap jk <ESC>
" remove search highlights by pressing space+/ - the key for searching the
" first place
nnoremap <leader>/ :noh<cr>
" split buffers vertically/horizontally with the leader \ or - (mirrors my
" tmux setup)
nnoremap <leader>- :sp<cr>
nnoremap <leader>\ :vsp<cr>
" move around between matching brackets with tab
nnoremap <tab> %
nnoremap <tab> %
" Spell check set to <leader>O, 'o' for 'orthography':
noremap <leader>O :setlocal spell! spelllang=en_us<CR>
noremap <leader>OE :setlocal spell! spelllang=en_us<CR>
noremap <leader>OG :setlocal spell! spelllang=de_de<CR>
noremap <leader>o z=
" select the whole buffer with <leader>-a
nnoremap <leader>a ggVG
" quickly edit vimrc with leader+V
nnoremap <leader>V :vsp $MYVIMRC<cr>
" 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 <leader>VV :source $MYVIMRC<cr>
" since u undoes, would it not make sense that U redoes?
nnoremap U <C-r>
" when in insertion mode, C-u uppercases the current word, C-l lowercases it,
inoremap <C-u> <esc>gUiw`]a
inoremap <C-l> <esc>guiw`]a
" get rid of the help message popping up when I miss esc and hit F1
nnoremap <F1> <ESC>
inoremap <F1> <ESC>
vnoremap <F1> <ESC>
" yank filename to f buffer
nnoremap yf :let @f = expand("%")<cr>
" remove all trailing whitespaces
" on pressing space+W
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" 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 <leader>t :vsp .<cr>
nnoremap <leader>T :tabedit .<cr>
" open/close NERDtree with leader-e
" whatever method tree has been opened by, leader-e closes it again
nnoremap <leader>e :NERDTreeToggle<CR>
" open root of current VCS project in tree
nnoremap <leader><C-e> :NERDTreeVCS<CR>
" open current nerdtree with current file highlighted
nnoremap <leader>E :NERDTreeFind<CR>
" 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 <leader>ga <Plug>(go-alternate-edit)
" switch between test file and function - in a horizontal/vertical split
au Filetype go nnoremap <leader>gah <Plug>(go-alternate-split)
au Filetype go nnoremap <leader>gav <Plug>(go-alternate-vertical)
" run a test (but run it as short version, in case tests are tagged
" accordingly)
au FileType go nnoremap <F10> :GoTest -short<cr>
" show/hide code coverage of go file
au FileType go nnoremap <F9> :GoCoverageToggle -short<cr>
" 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 <F12> <Plug>(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 <F10> :!echo<space>"require(rmarkdown);<space>render('<c-r>%')"<space>\|<space>R<space>--vanilla<enter>
" Compile with rmarkdown
" autocmd FileType markdown,rmarkdown noremap <leader>c :RMarkdown pdf<cr>
" autocmd FileType markdown,rmarkdown noremap <leader>C :RMarkdown! pdf<cr>
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 <leader>wf :execute(":call SearchWiki()")<cr>
" FUZZY FINDING
" FZF buffers and files in current workdir
noremap <leader>s :FzfBuffers<cr>
" FZF most recently used / MRU, bound to S since it is essentially a larger
" go-back intention than just buffers
noremap <leader>S :FzfHistory<cr>
noremap <leader>f :FzfFiles<cr>
" use wiki.vim to look through document outlines in fzf (only for note
" directory atm)
nnoremap <leader>l :WikiFzfToc<cr>
" FZF general full-text search in cwd with rg
noremap <leader>F :FzfRg<cr>
" FZF note full-text search with notational-velocity like functions (in wiki
" directory)
noremap <leader>n :NV<cr>
noremap <leader>N :NV!<cr>
" FZF git diff
noremap <leader>gd :FzfGFiles?<cr>
" FZF colorschemes
nnoremap <leader><F8> :FzfColors<cr>
" Toggle background light/dark
call togglebg#map("<F8>")
" Mostly dealing with Prose writing from here on out
" Format current Paragraph (esp useful in prose writing)
nnoremap <silent> <leader>q gqap
xnoremap <silent> <leader>q gq
nnoremap <silent> <leader>Q vapJgqap
" Enter distraction free prose mode with F11
noremap <F11> :Goyo<CR>
" surround stuff with quotes, from normal or visual mode
nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
vnoremap <leader>" <esc>`<i"<esc>`>la"<esc>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@ <https://martyoeh.me/>
iabbrev mcc@ Copyright 2019 Marty Oehme, all rights reserved.
"
" }}}

226
.config/nvim/maps.vim Normal file
View file

@ -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 <BS> <C-^>
" since u undoes, would it not make sense that U redoes?
nnoremap U <C-r>
" 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 <tab> %
nnoremap <tab> %
" when in insertion mode, C-u uppercases the current word, C-l lowercases it,
inoremap <C-U> <esc>gUiw`]a
inoremap <C-u> <esc>guiw`]a
" yank filename to f buffer
nnoremap yf :let @f = expand("%")<cr>
" repeat the last substitute command with all its flags preserved
noremap &
\ :&&<CR>
ounmap &
sunmap &
" bracket pairings to go to the next/previous of:
" (works with count prefixes)
"
" Argument list
nnoremap [a
\ :previous<CR>
nnoremap ]a
\ :next<CR>
" Buffers
nnoremap [b
\ :bprevious<CR>
nnoremap ]b
\ :bnext<CR>
" Quickfix list
nnoremap [c
\ :cprevious<CR>
nnoremap ]c
\ :cnext<CR>
" Location list
nnoremap [l
\ :lprevious<CR>
nnoremap ]l
\ :lnext<CR>
" set our leader key to space since with hjkl, space is largely useless
let mapleader = "\<Space>"
" 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 <leader>/ :noh<cr>
" split buffers vertically/horizontally with the leader \ or - (mirrors my
" tmux setup)
nnoremap <leader>- :sp<cr>
nnoremap <leader>\ :vsp<cr>
" 'open new buffer' with leader-t (opens new buffer containing current dir and switches to it)
nnoremap <leader>t :vsp .<cr>
" open actual new tab with leader-T
nnoremap <leader>T :tabedit .<cr>
" select the whole buffer with <leader>-a
nnoremap <leader>a ggVG
" CONFIG EDITING
" quickly edit vimrc with leader+V
nnoremap <leader>V :vsp $MYVIMRC<cr>
" 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 <leader>VV :source $MYVIMRC<cr>
" PLUGIN: vim-sneak
map f <Plug>Sneak_f
map F <Plug>Sneak_F
map t <Plug>Sneak_t
map T <Plug>Sneak_T
" SPELL CHECKING
" Spell check set to <leader>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 <leader>O :setlocal spell! spelllang=en_us<CR>
noremap <leader>OE :setlocal spell! spelllang=en_us<CR>
noremap <leader>OG :setlocal spell! spelllang=de_de<CR>
noremap <leader>o z=
" PLUGIN: NERDTree
" open/close NERDtree with leader-e
" whatever method tree has been opened by, leader-e closes it again
nnoremap <leader>e :NERDTreeToggle<CR>
" open root of current VCS project in tree
nnoremap <leader><C-e> :NERDTreeVCS<CR>
" open current nerdtree with current file highlighted
nnoremap <leader>E :NERDTreeFind<CR>
" PLUGIN: FZF GLOBAL FUZZY FINDING
" FZF buffers and files in current workdir
noremap <leader>s :FzfBuffers<cr>
" FZF most recently used / MRU, bound to S since it is essentially a larger
" go-back intention than just buffers
noremap <leader>S :FzfHistory<cr>
" fuzzy find files in cwd
noremap <leader>f :FzfFiles<cr>
" FZF general full-text search in cwd with rg
noremap <leader>F :FzfRg<cr>
" FZF git diff
noremap <leader>gd :FzfGFiles?<cr>
" FZF colorschemes
nnoremap <leader><F8> :FzfColors<cr>
" Toggle background light/dark
call togglebg#map("<F8>")
" 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 <leader>n :NV<cr>
noremap <leader>N :NV!<cr>
" PLUGIN: CtrlSF
" (non-fuzzy) search in wiki with ctrlsf, in fullscreen window
nnoremap <leader>wf :execute(":call SearchWiki()")<cr>
" 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 <leader>ga <Plug>(go-alternate-edit)
" switch between test file and function - in a horizontal/vertical split
au Filetype go nnoremap <leader>gah <Plug>(go-alternate-split)
au Filetype go nnoremap <leader>gav <Plug>(go-alternate-vertical)
" run a test (but run it as short version, in case tests are tagged
" accordingly)
au FileType go nnoremap <F10> :GoTest -short<cr>
" show/hide code coverage of go file
au FileType go nnoremap <F9> :GoCoverageToggle -short<cr>
" 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 <F12> <Plug>(go-def)
" PLUGIN: wiki.vim
" use wiki.vim to look through document outlines in fzf (only for note
" directory atm)
nnoremap <leader>l :WikiFzfToc<cr>
" 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 = {
\ '<plug>(wiki-journal)' : '<leader>===',
\ '<plug>(wiki-code-run)' : '<leader>====',
\ '<plug>(wiki-graph-in)' : '<leader>====',
\ '<plug>(wiki-graph-out)' : '<leader>=====',
\ '<plug>(wiki-link-toggle)' : '<leader>=======',
\ '<plug>(wiki-page-toc)' : '<leader>=========',
\ '<plug>(wiki-page-toc-local)' : '<leader>=============',
\ '<plug>(wiki-export)' : '<leader>==============',
\ '<plug>(wiki-list-uniq)' : '<leader>===============',
\ '<plug>(wiki-list-uniq-local)' : '<leader>================',
\ '<plug>(wiki-tag-list)' : '<leader>=================',
\ '<plug>(wiki-tag-reload)' : '<leader>==================',
\ '<plug>(wiki-tag-search)' : '<leader>=====================',
\ '<plug>(wiki-link-toggle-operator)' : '<leader>======================',
\}
" Mostly dealing with Prose writing from here on out
" Format current Paragraph (esp useful in prose writing)
nnoremap <silent> <leader>q gqap
xnoremap <silent> <leader>q gq
nnoremap <silent> <leader>Q vapJgqap
" PLUGIN: GOYO
" Enter distraction free prose mode with F11
noremap <F11> :Goyo<CR>
" PLUGIN: fzf-bibtex
" map @@ to automatically insert citation reference at cursor
inoremap <silent> @@ <c-g>u<c-o>:call fzf#run(fzf#wrap({
\ 'source': <sid>bibtex_ls(),
\ 'sink*': function('<sid>bibtex_cite_sink_insert'),
\ 'up': '25%',
\ 'options': '--ansi --multi --prompt "Cite> "'}))<CR>
" map <leader>cc to insert a complete citation at cursor
nnoremap <silent> <leader>cc :CiteRef<cr>
" map <leader>cm to insert markdown prettified citation
nnoremap <silent> <leader>cm :CiteMarkdown<cr>