dotfiles/nvim/.config/nvim/maps.vim
Marty Oehme 65df0fb91f
nvim: Remove pencil to fix relative cursor movement
Cursor movement works better for soft-wrapped prose files now:
When just using j/k to move vertically, the cursor will jump between the
different parts of a single wrapped line. That means you can easily move
anywhere you want on your lines, exactly as it's shown to you.

If, however, prefixing your j/k move with a number to move a relative
number of lines, it will no longer take wrapping into account. That
means you can not jump instantly to *any* part of a wrapped lines,
however on the other hand the relative line numbers on the side never
lie now: You will jump exactly as many lines as are shown on the side.
This is a tradeoff I am happily willing to make.

Additionally had to remove vim-pencil to get the movement to work, but
since it did not provide any visible pros anymore, this should not be a
big issue.
2020-10-08 20:38:50 +02:00

274 lines
9.0 KiB
VimL

" 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
" this may have to be adjusted / removed to let wiki.vim use BS for navigation
nnoremap <BS> <C-^>
" since u undoes, would it not make sense that U redoes?
nnoremap U <C-r>
" d-motion puts the last 'deleted' thing into the default register to paste;
" use D-motion to truly delete something into nothingness and keep whatever
" you want in your register, ready to paste
nnoremap D "_d
" I don't particularly need ex mode (at least, yet) but faster macro access
" is nice
nnoremap Q @
" stronger versions of left,right - move all the way to beginning/end of line
nnoremap H ^
nnoremap L $
" when in softwrapped files, allow moving through the visible lines with j/k
" but when prepending a number jump *exactly* as many lines, wrapped or not
" This makes relative linenumbers much more useful in prose docs since they
" are always exactly correct
nnoremap <expr> k (v:count == 0 ? 'gk' : 'k')
nnoremap <expr> j (v:count == 0 ? 'gj' : 'j')
" 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
" let me save stuff as sudo when I forget to call vim with it
cnoremap w!! execute 'silent! write !sudo tee % >/dev/null' <bar> edit!
" 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
" 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 :FzfRgHidden<cr>
" FZF git status
noremap <leader>gs :FzfGFiles?<cr>
" FZF git buffercommits
noremap <leader>gb :FzfBCommits<cr>
" FZF git commitlog
noremap <leader>gl :FzfCommits<cr>
" FZF helptags
noremap <leader><F1> :FzfHelptags<cr>
" FZF colorschemes
nnoremap <leader><F8> :FzfColors<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 <localleader>ga <Plug>(go-alternate-edit)
" switch between test file and function - in a horizontal/vertical split
au Filetype go nnoremap <localleader>gah <Plug>(go-alternate-split)
au Filetype go nnoremap <localleader>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)
" 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: wiki.vim
" use wiki.vim to look through document outlines in fzf (only for note
" directory atm)
" leader is used when it is callable from anywhere
" localleader is used when it is specific to the local file
nnoremap <leader>wf :WikiFzfPages<cr>
nnoremap <leader>l :WikiFzfTags<cr>
" use default TOC shortcut for viewing wikitoc if in correct filetype
augroup wikitoc
autocmd!
autocmd Filetype markdown,pandoc nnoremap <buffer> gO :WikiFzfToc<cr>
augroup END
" 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_local = {
\ '<plug>(wiki-link-next)' : '<tab>',
\ '<plug>(wiki-link-prev)' : '<s-tab>',
\ '<plug>(wiki-link-return)' : '<bs>',
\ 'v_<plug>(wiki-link-toggle-visual)' : '<cr>',
\ '<plug>(wiki-graph-find-backlinks)' : '<leader>wb',
\ '<plug>(wiki-graph-in)' : '<leader>wg',
\ '<plug>(wiki-graph-out)' : '<leader>wG',
\}
" additional zettelkasten mapping
augroup zettelkasten
autocmd!
autocmd Filetype markdown,pandoc nnoremap <cr> :ZettelOpenAtCursor<cr>
augroup END
" Mostly dealing with Prose writing from here on out
" Format current Paragraph (esp useful in prose writing)
nnoremap <silent> <localleader>q gqap
xnoremap <silent> <localleader>q gq
nnoremap <silent> <localleader>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>:CiteRef<CR>
" map <leader>cc to insert a complete citation at cursor
nnoremap <silent> <localleader>cc :CiteRef<cr>
" map <leader>cm to insert markdown prettified citation
nnoremap <silent> <localleader>cm :CiteMarkdown<cr>
" 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>Z :setlocal spell! spelllang=en_us<CR>
noremap <leader>ZE :setlocal spell! spelllang=en_us<CR>
noremap <leader>ZG :setlocal spell! spelllang=de_de<CR>
noremap <leader>zz 1z=
" PLUGIN: tq thesaurus_query.vim
nnoremap <leader>zt :ThesaurusQueryReplaceCurrentWord<cr>
vnoremap <leader>zt "ky:ThesaurusQueryReplace <cr>k<cr>
" pp to comPile a document (or file, works for some languages like go/python/c)
" o to open the resulting document (mostly for pdfs)
" po to comPile *and* open a doc
" and all the same in uppercase for verbose output
nnoremap <localleader>dp :DocCompile<cr>
nnoremap <localleader>dP :DocCompile!<cr>
nnoremap <localleader>do :DocOpen<cr>
nnoremap <localleader>dO :DocOpen!<cr>
" PLUGIN: easy-align
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)