dotfiles/.config/nvim/maps.vim

227 lines
7.6 KiB
VimL
Raw Normal View History

" 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 SearchNotes()")<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>