" 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 " Move between panes nnoremap nnoremap nnoremap nnoremap " 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')) noremap y "+y noremap d "+d noremap p "+p noremap 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= " 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 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 if (get(g:, 'loaded_gutentags')) 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(@",'/\') " 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) . '`]' if exists('g:loaded_fugitive') nnoremap cd :Gcd else " only works if a file is already opened nnoremap cd :cd %:h cd `git rev-parse --show-toplevel` endif