"--------------------------------------------------------------------------- " Key-mappings: " " Use ',' instead of '\'. " Use in global plugin. let g:mapleader = ',' " Use in filetype plugin. let g:maplocalleader = 'm' " Release keymappings for plug-in. nnoremap ; nnoremap m nnoremap , " Use . nmap cmap " Visual mode keymappings: " Indent nnoremap > >> nnoremap < << xnoremap > >gv xnoremap < y "*y:let [@+,@"]=[@*,@*] endif " Insert mode keymappings: " : insert tab. inoremap " Enable undo and . inoremap u inoremap u inoremap D " Command-line mode keymappings: " , A: move to head. cnoremap " : previous char. cnoremap " : delete char. cnoremap " , E: move to end. cnoremap " : next char. cnoremap " : next history. cnoremap " : previous history. cnoremap " : paste. cnoremap * " : Exit. cnoremap " [Space]: Other useful commands " Smart space mapping. nmap [Space] nnoremap [Space] " Set autoread. nnoremap [Space]ar \ call vimrc#toggle_option('autoread') " Set spell check. nnoremap [Space]p \ call vimrc#toggle_option('spell') \set spelllang=en_us \set spelllang+=cjk nnoremap [Space]w \ call vimrc#toggle_option('wrap') nnoremap [Space]l \ call vimrc#toggle_option('laststatus') " Easily edit current buffer nnoremap [Space]e \ bufname('%') !=# '' ? 'edit %' : '' " Useful save mappings. nnoremap update " s: Windows and buffers(High priority) " The prefix key. nnoremap sp vsplit:wincmd w nnoremap so only nnoremap wincmd w nnoremap q winnr('$') != 1 ? 'close' : '' " Original search nnoremap s/ / nnoremap s? ? " Better x nnoremap x "_x " Disable Ex-mode. nnoremap Q q " Useless command. nnoremap M m " Smart , . noremap max([winheight(0) - 2, 1]) \ . '' . (line('w$') >= line('$') ? 'L' : 'M') noremap max([winheight(0) - 2, 1]) \ . '' . (line('w0') <= 1 ? 'H' : 'M') " Disable ZZ. nnoremap ZZ " Select rectangle. xnoremap r " Redraw. nnoremap redraw! " If press l on fold, fold open. nnoremap l foldclosed(line('.')) != -1 ? 'zo0' : 'l' " If press l on fold, range fold open. xnoremap l foldclosed(line('.')) != -1 ? 'zogv0' : 'l' " Substitute. xnoremap s :s//g " Sticky shift in English keyboard. " Sticky key. inoremap ; vimrc#sticky_func() cnoremap ; vimrc#sticky_func() snoremap ; vimrc#sticky_func() " Easy escape. inoremap jj cnoremap j \ getcmdline()[getcmdpos()-2] ==# 'j' ? '' : 'j' inoremap j j " a>, i], etc... " onoremap aa a> xnoremap aa a> onoremap ia i> xnoremap ia i> " [rectangle] onoremap ar a] xnoremap ar a] onoremap ir i] xnoremap ir i] " Improved increment. nmap (increment) nmap (decrement) nnoremap (increment) AddNumbers 1 nnoremap (decrement) AddNumbers -1 command! -range -nargs=1 AddNumbers \ call vimrc#add_numbers((-+1) * eval()) nnoremap # if exists(':tnoremap') " Note: Does not overwrite behavior if has('nvim') tnoremap jj else tnoremap N tnoremap jj N endif tnoremap j j tnoremap ; vimrc#sticky_func() endif " Wordcount command! WordCount echo strchars(join(getline(1, '$'))) " {visual}P to put without yank to unnamed register " https://github.com/neovim/neovim/pull/12383#issuecomment-695768082 xnoremap p call vimrc#visual_paste('p') xnoremap P call vimrc#visual_paste('P') " Command group opening with a specific character code again. " In particular effective when I am garbled in a terminal. " Open in UTF-8 again. command! -bang -bar -complete=file -nargs=? Utf8 \ edit ++enc=utf-8 " Open in iso-2022-jp again. command! -bang -bar -complete=file -nargs=? Iso2022jp \ edit ++enc=iso-2022-jp " Open in Shift_JIS again. command! -bang -bar -complete=file -nargs=? Cp932 \ edit ++enc=cp932 " Open in EUC-jp again. command! -bang -bar -complete=file -nargs=? Euc \ edit ++enc=euc-jp " Open in UTF-16 again. command! -bang -bar -complete=file -nargs=? Utf16 \ edit ++enc=ucs-2le " Tried to make a file note version. command! WUtf8 setlocal fenc=utf-8 command! WCp932 setlocal fenc=cp932 " Appoint a line feed. command! -bang -complete=file -nargs=? WUnix \ write ++fileformat=unix | edit command! -bang -complete=file -nargs=? WDos \ write ++fileformat=dos | edit " Insert special character inoremap u =nr2char(0x)