" mapleader let g:mapleader = ',' nnoremap xnoremap xnoremap if has('nvim') tnoremap else tnoremap N endif tnoremap " disable dengerous/annoying mapping " NOTE: ZQ is useful when cmdline is broken nnoremap ZZ nnoremap q nnoremap S xnoremap q xnoremap S " Record macro like ["x]Q (in default use 'q' register) nnoremap Q empty(reg_recording()) \ ? 'q' .. (v:register =~# '["*+]' ? 'q' : v:register) \ : 'q' nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k xnoremap j gj xnoremap k gk xnoremap gj j xnoremap gk k nnoremap x "_x nnoremap s "_s nnoremap Y y$ xnoremap x "_x xnoremap s "_s xnoremap Y y$ nnoremap n nzzzv(VimrcSearchPost) nnoremap N Nzzzv(VimrcSearchPost) nnoremap * *zzzv(VimrcSearchPost) nnoremap # #zzzv(VimrcSearchPost) nnoremap g* g*zzzv(VimrcSearchPost) nnoremap g# g#zzzv(VimrcSearchPost) " disable arrow keys nnoremap nnoremap nnoremap nnoremap xnoremap xnoremap xnoremap xnoremap inoremap inoremap inoremap inoremap " better aliases of / nnoremap \ getline('.')[:col('.') - 2] =~# '^\s*$' ? '0' : '^' nnoremap xnoremap \ getline('.')[:col('.') - 2] =~# '^\s*$' ? '0' : '^' xnoremap inoremap u inoremap u nnoremap [Space] nmap [Space] nnoremap nohlsearchdiffupdate nnoremap [Space]w update nnoremap [Space]W write nnoremap ^ edit nnoremap [Space]f edit %:p:h nnoremap [Space]q confirm qall nnoremap gf gF cnoremap / getcmdtype() ==# '/' ? '\/' : '/' cnoremap ? getcmdtype() ==# '?' ? '\?' : '?' " open native cmdline nnoremap g: : nnoremap g/ / " from https://github.com/pesblog/dots-base/blob/a0762b8ffe/home/.vimrc#L140 nnoremap gp '`[' .. strpart(getregtype(), 0, 1) .. '`]' " from https://baqamore.hatenablog.com/entry/2016/07/07/201856 xnoremap p 'pgv"' .. v:register .. 'ygv' " from https://vim-jp.org/vim-users-jp/2009/08/31/Hack-65.html xnoremap / /\%V " from https://github.com/nnsnico/dotfiles/blob/cf9ce83cfa/vim/vimrcs/basic.vim#L150-L151 " center horizontally on cursor position nnoremap z. normal! zszH " based on https://github.com/romgrk/nvim/blob/ba305c52/rc/keymap.vim#L98-L99 nnoremap i getline('.') =~# '^\s*$' ? 'cc' : 'i' " from https://github.com/monaqa/dotfiles/blob/de4bdb9f/.config/nvim/lua/rc/keymap.lua#L436 nnoremap dd empty(getline('.')) && v:count1 ==# 1 && v:register ==# '"' \ ? '"_dd' : 'dd' " NOTE: `g_` is almost same as `$h` xnoremap v mode() ==# 'v' ? 'g_' : 'v' xnoremap t xnoremap ) t) xnoremap < >gv onoremap t onoremap ) t) inoremap z zz inoremap zz inoremap p setlocal paste! paste? inoremap setlocal paste! paste? " emacs-like insert/cmdline mode mapping {{{ function! s:is_at_end() abort return mode() ==# 'c' \ ? getcmdpos() > strlen(getcmdline()) \ : col('.') > strlen(getline('.')) endfunction noremap! inoremap is_at_end() ? '' : '' noremap! noremap! noremap! noremap! noremap! is_at_end() ? '' : '' inoremap is_at_end() ? 'gJ' : 'D' cnoremap call setcmdline( \ getcmdpos() ==# 1 ? '' : getcmdline()[:getcmdpos() - 2]) noremap! " " }}} map! ¥ map ¥ " insert current file fullpath cnoremap =expand('%:p') " toggle options nnoremap [Toggle] nmap [Toggle] nnoremap [Toggle]w setlocal wrap! wrap? nnoremap [Toggle]p setlocal paste! paste? nnoremap [Toggle]c setlocal termguicolors! termguicolors? nnoremap [Toggle]n setlocal relativenumber! relativenumber? " moving mappings {{{ " buffer move nnoremap [b :bprevious nnoremap ]b :bnext nnoremap [B :bfirst nnoremap ]B :blast " quickfix move " NOTE: conflict with diff move (see `:help jumpto-diffs`) " nnoremap [c :cprevious " nnoremap ]c :cnext " nnoremap [C :cfirst " nnoremap ]C :clast " locationlist move nnoremap [l :lprevious nnoremap ]l :lnext nnoremap [L :lfirst nnoremap ]L :llast " tabpage move nnoremap [t :tabprevious nnoremap ]t :tabnext nnoremap [T :tabfirst nnoremap ]T :tablast " }}}