"--------------------------------------------------------------------------- " 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 < let [@+,@"]=[@*,@*] endif " Enable undo and . inoremap u inoremap u inoremap D " Command-line mode keymappings: " , A: move to head. cnoremap " : previous char. cnoremap " : delete char. cnoremap " : next char. cnoremap " : next history. cnoremap " : previous history. cnoremap " : Exit. cnoremap " : Delete to the end. cnoremap call setcmdline( \ getcmdpos() ==# 1 ? '' : getcmdline()[:getcmdpos() - 2]) " [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]c \ call toggle_conceal() function s:toggle_conceal() abort if &l:conceallevel == 0 setlocal conceallevel=3 else setlocal conceallevel=0 endif setlocal conceallevel? endfunction " NOTE: hit-enter prompt is needed to debug. nnoremap [Space]h \ call toggle_messagesopt() function s:toggle_messagesopt() abort if &messagesopt->stridx('hit-enter') < 0 set messagesopt+=hit-enter set more else set messagesopt-=hit-enter set nomore endif set messagesopt? more? endfunction " Easily reload filetype nnoremap [Space]r let &filetype = &filetype " Quickfix nnoremap [Space]q \ call vimrc#diagnostics_to_location_list() " Useful save mappings. nnoremap silent update " s: Windows and buffers(High priority) " The prefix key. nnoremap s nnoremap sp vsplitwincmd w nnoremap so only nnoremap wincmd w nnoremap q \ &l:filetype ==# 'qf' \ ? 'ccloselclose' \ : '#'->winnr()->getwinvar('&winfixbuf') \ ? '' \ : range(1, '$'->winnr()) \ ->filter({_, val -> val !=# winnr() }) \ ->map({ _, val -> val->winbufnr()->getbufvar('&buftype') }) \ ->filter({_, val -> val !=# 'quickfix' && val !=# 'help' }) \ ->len() > 0 \ ? '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. nnoremap AddNumbers 1 nnoremap AddNumbers -1 command! -range -nargs=1 AddNumbers \ call vimrc#add_numbers((-+1) * eval() * v:count1) nnoremap # " NOTE: Does not overwrite behavior if has('nvim') tnoremap jj else tnoremap N tnoremap jj N endif tnoremap j j tnoremap ; vimrc#sticky_func() tnoremap + " {visual}p to put without yank to unnamed register xnoremap p 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 " 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 " Tag jump nnoremap tt g nnoremap tp pop