if !exists('g:env') finish endif " Common {{{1 if !g:plug.is_installed('mru.vim') "if exists(':MRU2') if exists('*s:MRU_Create_Window') nnoremap [Space]j :call MRU_Create_Window() "nnoremap [Space]j :MRU endif endif " Use backslash if IsMac() noremap ¥ \ noremap \ ¥ endif " Define mapleader let g:mapleader = ',' let g:maplocalleader = ',' " Smart space mapping " Notice: when starting other mappings in noremap, disappeared [Space] nmap [Space] xmap [Space] nnoremap [Space] xnoremap [Space] " key map ^,$ to h,l. Because ^ and $ is difficult to type and damage little finger!!! noremap [Space]h ^ noremap [Space]l $ if !g:plug.is_installed('lexima.vim') inoremap [ [] inoremap ( () inoremap " "" inoremap ' '' inoremap ` `` endif inoremap inoremap "nnoremap + "nnoremap - inoremap inoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap cnoremap inoremap inoremap inoremap inoremap inoremap inoremap inoremap inoremap inoremap nnoremap q: nnoremap q/ nnoremap q? nnoremap nnoremap nnoremap nnoremap nnoremap ZZ nnoremap ZQ " Must {{{1 inoremap jj cnoremap j getcmdline()[getcmdpos()-2] ==# 'j' ? "\\" : 'j' vnoremap onoremap jj inoremap j[Space] j onoremap j[Space] j nnoremap : ; nnoremap ; : nnoremap q; q: vnoremap : ; vnoremap ; : vnoremap q; q: cnoreabbrev w!! w !sudo tee > /dev/null % nnoremap :nohlsearch nnoremap n nzz nnoremap N Nzz nnoremap S *zz nnoremap * *zz nnoremap # #zz nnoremap g* g*zz nnoremap g# g#zz " View file information nnoremap 1 " Write only when the buffer has been modified nnoremap :silent update " Goto file under cursor noremap gf gF noremap gF gf " Type 'v', select end of line in visual mode vnoremap v $h " Make Y behave like other capitals nnoremap Y y$ " expand path cmap =expand('%:p:h')/ " expand file (not ext) cmap =expand('%:p:r') " Add a relative number toggle nnoremap r :call toggle_option('relativenumber') " Add a spell check toggle nnoremap s :call toggle_option('spell') " Tabs Increase nnoremap ~ :let &tabstop = (&tabstop * 2 > 16) ? 2 : &tabstop * 2:echo 'tabstop:' &tabstop " Toggle top/center/bottom noremap zz (winline() == (winheight(0)+1)/ 2) ? 'zt' : (winline() == 1)? 'zb' : 'zz' " Jump a next blank line nnoremap W :keepjumps normal! } nnoremap B :keepjumps normal! { " Save word and exchange it under cursor nnoremap ciy ciw0:let@/=@1:noh nnoremap cy ce0:let@/=@1:noh " Yank the entire file nnoremap y :%y nnoremap Y :%y nnoremap l :call toggle_option('cursorline') nnoremap c :call toggle_option('cursorcolumn') " Tabpages {{{1 nnoremap t nnoremap [Space]t :tabclose:tabnew nnoremap tt :tabnew nnoremap tT :tabnew:tabprev nnoremap tc :tabclose nnoremap to :tabonly nnoremap tm :call move_to_tab() function! s:move_to_tab() tab split tabprevious if winnr('$') > 1 close elseif bufnr('$') > 1 buffer # endif tabnext endfunction " Tabpages mappings nnoremap L :call move_tabpage("right") nnoremap H :call move_tabpage("left") nnoremap dh :call close_all_left_tabpages() nnoremap dl :call close_all_right_tabpages() " Swap jk for gjgk {{{1 nnoremap j gj nnoremap k gk vnoremap j gj vnoremap k gk nnoremap gj j nnoremap gk k vnoremap gj j vnoremap gk k if g:env.vimrc.goback_to_eof2bof == g:true function! s:up(key) if line(".") == 1 return ":call cursor(line('$'), col('.'))\" else return a:key endif endfunction function! s:down(key) if line(".") == line("$") return ":call cursor(1, col('.'))\" else return a:key endif endfunction nnoremap k up("gk") nnoremap j down("gj") endif " Buffers, windows, and tabpages {{{1 "nnoremap :call get_buflists('n') "nnoremap :call get_buflists('p') if !g:plug.is_installed('vim-buftabs') nnoremap :silent bnext nnoremap :silent bprev else nnoremap :silent bnext:call get_buflists() nnoremap :silent bprev:call get_buflists() endif nnoremap u :call buf_restore() nnoremap d :Delete nnoremap :Delete! " Windows nnoremap s nnoremap sp :split nnoremap vs :vsplit function! s:vsplit_or_wincmdw() if winnr('$') == 1 return ":vsplit\" else return ":wincmd w\" endif endfunction nnoremap ss vsplit_or_wincmdw() nnoremap sj j nnoremap sk k nnoremap sl l nnoremap sh h "nnoremap :silent! tabnext "nnoremap :silent! tabprev nnoremap t nnoremap [Space]t :tabclose:tabnew nnoremap tt :tabnew nnoremap tT :tabnew:tabprev nnoremap tc :tabclose nnoremap to :tabonly " Folding (see :h usr_28.txt){{{1 "nnoremap l foldclosed('.') != -1 ? 'zo' : 'l' "nnoremap h col('.') == 1 && foldlevel(line('.')) > 0 ? 'zc' : 'h' nnoremap z0 :set foldlevel==foldlevel('.') " __END__ {{{1 " vim:fdm=marker expandtab fdc=3: