" Keybindings """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Stop highlighting search result when pressing Return nnoremap :nohlsearch " Indentation jump " https://vim.fandom.com/wiki/Move_to_next/previous_line_with_same_indentation " noremap :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%<' . line('.') . 'l\S', 'be') " noremap :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%>' . line('.') . 'l\S', 'e') " Split view navigation " Create new panes nnoremap N :vsplit nnoremap n :split " Substitute command if (exists('+inccommand') && &inccommand != '') nnoremap S :%s/ vnoremap S :s/ else " This does not work with live previewing commands (inccommand) since the " replace pattern is already defined and thus everything matching the search " pattern is just deleted. nnoremap S :%s//gc vnoremap S :s//gc endif " Interact with the system clipboard if (has('clipboard') || has('nvim')) map y "+y map Y "+Y map d "+d map p "+p map P "+P endif " Ctrl-Backspace should delete words in insert mode and on command-line. noremap! " Correct word with best/first suggestion. noremap c 1z= " Correct next or last misspelled word (and their non-rare/region versions) " without moving " TODO: see :keepjumps " Problem: with keepjumps the is not possible anymore noremap ]s ]s1z= noremap [s [s1z= noremap ]S ]S1z= noremap [S [S1z= " Toggle spell, cycle and set spelllang map st :set spell=!&spell map sc :call CycleSpellLang() map ss :set spelllang= " Umlaute and sz in Insert and Command-line mode when spelllang is set to `de` autocmd OptionSet spelllang silent call NewSpellLang(v:option_new, v:option_old) function! NewSpellLang(new_lang, old_lang) let &spellfile = $XDG_DATA_HOME . '/vim/spell/' . a:new_lang . '.utf-8.add' let mappings = { \ 'ae': 'ä', \ 'Ae': 'Ä', \ 'oe': 'ö', \ 'Oe': 'Ö', \ 'ue': 'ü', \ 'Ue': 'Ü', \ 'sz': 'ß', \ } if (a:new_lang == 'de') for [key, value] in items(mappings) execute 'map! ' key value endfor elseif (a:old_lang == 'de') for key in keys(mappings) execute 'unmap! ' key endfor endif endfunction " Jump through jump table but center noremap zz noremap zz nmap " Terminal if (has('nvim')) tnoremap nmap :split +terminali nmap v :vsplit +terminali elseif (has('terminal')) nmap :terminal endif " Plugin specific bindings if (get(g:, 'loaded_fzf')) nmap f :Files nmap j :Lines nmap / :Lines " TODO: fix this? if (get(g:, 'loaded_gutentags') || 1) nmap t :Tags endif endif " Search for selected text. " Taken from https://vim.fandom.com/wiki/Search_for_visually_selected_text vnoremap * y/\V=escape(@",'/\') vnoremap # y?\V=escape(@",'?\') " Select last pasted text in same visual mode as it was selected (v, V, or ^V) " Taken from: https://vim.fandom.com/wiki/Selecting_your_pasted_text nnoremap gp '`[' . strpart(getregtype(), 0, 1) . '`]' " Git bindings " Insert a commit's subject behind the SHA1 that the cursor is currently on. " Mnemonic: "git reference commit" " NOTE: This uses `system` and not `:r!` to insert the text directly at the " cursor. `subject[:-2]` cuts off the trailing newline. nmap grc :let subject=system('git show -s --format="(\"%s\")" ')ea =subject[:-2] if exists('g:loaded_fugitive') nmap gc :G commit nmap ga :G add -- % nmap gs :G stash -- % nmap gu :G checkout -- % else " only works if a file is already opened nnoremap gcd :cd %:h cd `git rev-parse --show-toplevel` endif if exists('g:loaded_gitgutter') " Add `g` prefix to hunk bindings " Mnemonic: "git hunk " nmap gha (GitGutterStageHunk) xmap gha (GitGutterStageHunk) " TODO: nmap ghs (GitGutterStashHunk) nmap ghu (GitGutterUndoHunk) nmap ghp (GitGutterPreviewHunk) " Add hunk/h version to textobject bindings that use `c` (for `change I " presume?) (e.g. ic -> ih) omap ih (GitGutterTextObjectInnerPending) omap ah (GitGutterTextObjectOuterPending) xmap ih (GitGutterTextObjectInnerVisual) xmap ah (GitGutterTextObjectOuterVisual) " Same for hunk navigation bindings nmap [h (GitGutterPrevHunk) nmap ]h (GitGutterNextHunk) endif " Y should behave like D & C does nnoremap Y y$ " Move lines up and down while correcting the indentation " https://vim.fandom.com/wiki/Moving_lines_up_or_down " (Use arrows, as Alt-{j,k} is used by my terminal for scrollback) nnoremap :m .-2== nnoremap :m .+1== vnoremap :m '<-2gv=gv vnoremap :m '>+1gv=gv inoremap :m .-2==gi inoremap :m .+1==gi " Fix & command to also use last flags nnoremap & :&& xnoremap & :&& " see :help i_ctrl-g_u " Do not break undo sequence when using the arrow keys or home and end in insert " mode inoremap U inoremap U inoremap col('.') == match(getline('.'), '\S') + 1 ? \ repeat('U', col('.') - 1) : \ (col('.') < match(getline('.'), '\S') ? \ repeat('U', match(getline('.'), '\S') + 0) : \ repeat('U', col('.') - 1 - match(getline('.'), '\S'))) inoremap repeat('U', col('$') - col('.')) " Make insert-mode texts repeatable by `.` with the closing parentheses at the " right position inoremap ( ()U " break undo sequence with every space and newline, making insert mode changes " revertible in smaller chunks inoremap u inoremap u " Open the manpage in the WORD under cursor nnoremap gm :Man xnoremap gm :Man