vim9script import autoload "kg8m/configure/mappings/search.vim" import autoload "kg8m/plugin/mappings/i.vim" as mappingsI import autoload "kg8m/util.vim" import autoload "kg8m/util/f2.vim" import autoload "kg8m/util/marks.vim" as marksUtil augroup vimrc-configure-mappings autocmd! autocmd InsertEnter * timer_start(0, (_) => mappingsI.Define()) autocmd User insert_mode_plugin_loaded timer_start(0, (_) => mappingsI.Define({ force: true })) augroup END export def Define(): void # Split window nnoremap v :vsplit nnoremap h :split # Overwrite default `f`/`F`/`t`/`T`. nnoremap f f2.LowerF() xnoremap f f2.LowerF() onoremap f f2.LowerF() nnoremap F f2.UpperF() xnoremap F f2.UpperF() onoremap F f2.UpperF() nnoremap t f2.LowerT() xnoremap t f2.LowerT() onoremap t f2.LowerT() nnoremap T f2.UpperT() xnoremap T f2.UpperT() onoremap T f2.UpperT() nnoremap f f2.Multiline() xnoremap f f2.Multiline() onoremap f f2.Multiline() # Overwrite default `;`/`,`. nnoremap ; f2.Semi() xnoremap ; f2.Semi() onoremap ; f2.Semi() nnoremap , f2.Comma() xnoremap , f2.Comma() onoremap , f2.Comma() # See also settings of vim-lsp and vim-fzf-tjump # : Jump back nnoremap g[ # gF: Same as "gf", except if a number follows the file name, then the cursor is positioned on that line in the file. # Don't use `nnoremap` because `gf` sometimes overwritten by plugins nmap gf gF # Go to next/previous location and open its folding. # zv: Show cursor even if in fold. # zz: Adjust cursor at center of window. nnoremap gn :cnextzvzz nnoremap gp :cpreviouszvzz # Increment/Decrement nmap + nmap - # Swap / and / in commandline mode # Original / respect inputted prefix cnoremap cnoremap cnoremap cnoremap # For Cmdline popupmenu (`set wildoptions=pum`). Don't do `cnoremap pumvisible() ? " : ...` # because the mapping to `` breaks some operations in Cmdline mode, e.g., pasting from clipboard. cnoremap pumvisible() ? "" : "" # Swap pasting with adjusting indentations or not # Disable exchanging because indentation is sometimes bad # nnoremap p ]p # nnoremap ] # nnoremap ]p p # nnoremap ] # Moving in INSERT mode # U: don't break undo with next left/right cursor movement, if the cursor stays within the same line inoremap inoremap U inoremap inoremap U inoremap inoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap # Replace selected text with unnamed register content without overwriting. # :h visual-operators # v_P: put without unnamed register overwrite xnoremap r P # v_o: Go to other end of highlighted text # Invert visual selection start and end => ! xnoremap ! o # Clear and redraw the screen even if Insert mode inoremap # Select text with quotation marks without spaces around them # :h v_iquote onoremap a" 2i" onoremap a' 2i' onoremap a` 2i` # Enter Insert mode with indentation if the line is empty. # :h inserting # a: Append text after the cursor [count] times. # A: Append text at the end of the line [count] times. # i: Insert text before the cursor [count] times. # I: Insert text before the first non-blank in the line [count] times. nnoremap a ExprToEnterIWithIndentation("a") nnoremap A ExprToEnterIWithIndentation("A") nnoremap i ExprToEnterIWithIndentation("i") nnoremap I ExprToEnterIWithIndentation("I") xnoremap y "zyutil.RemoteCopy(@z) xnoremap w :call util.RemoveTrailingWhitespaces() nnoremap m marksUtil.Increment() search.Define() enddef # == export def PreventUnconsciousOperation(): void # Break undo sequence with `u` when a word is deleted with ``. inoremap u inoremap tnoremap noremap enddef def ExprToEnterIWithIndentation(original_key: string): string if empty(getline(".")) return '"_cc' else return original_key endif enddef