diff --git a/autoload/SpaceVim.vim b/autoload/SpaceVim.vim index b9249daff..95197a19f 100644 --- a/autoload/SpaceVim.vim +++ b/autoload/SpaceVim.vim @@ -175,6 +175,7 @@ endfunction function! SpaceVim#default() abort call SpaceVim#default#SetOptions() call SpaceVim#default#SetPlugins() + call SpaceVim#default#SetMappings() endfunction function! SpaceVim#defindFuncs() abort diff --git a/autoload/SpaceVim/default.vim b/autoload/SpaceVim/default.vim index 0d1a22b9f..1f7c8d493 100644 --- a/autoload/SpaceVim/default.vim +++ b/autoload/SpaceVim/default.vim @@ -1,3 +1,4 @@ +scriptencoding utf-8 function! SpaceVim#default#SetOptions() abort " basic vim settiing if has('gui_running') @@ -138,3 +139,248 @@ function! SpaceVim#default#SetPlugins() abort call add(g:spacevim_plugin_groups, 'linux') endif endfunction + +function! SpaceVim#default#SetMappings() abort + + "mapping + "全局映射 + "也可以通过'za'打开或者关闭折叠 + nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') + "Super paste it does not work + "ino :set pastemui+mv'uV'v=:set nopaste + "对于没有权限的文件使用 :w!!来保存 + cnoremap w!! %!sudo tee > /dev/null % + " cmap W!! w !sudo tee % >/dev/null " I can not understand + " Save a file with sudo + " http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN + + + " 映射Ctrl+上下左右来切换窗口 + nnoremap :wincmd l + nnoremap :wincmd h + nnoremap :wincmd k + nnoremap :wincmd j + if has('nvim') + exe 'tnoremap :wincmd l' + exe 'tnoremap :wincmd h' + exe 'tnoremap :wincmd k' + exe 'tnoremap :wincmd j' + exe 'tnoremap ' + endif + + "for buftabs + noremap bp :bprev + noremap bn :bnext + + "Quickly add empty lines + nnoremap [ :put! =repeat(nr2char(10), v:count1) + nnoremap ] :put =repeat(nr2char(10), v:count1) + + "Use jk switch to normal model + inoremap jk + + "]e or [e move current line ,count can be useed + nnoremap [e :execute 'move -1-'. v:count1 + nnoremap ]e :execute 'move +'. v:count1 + + "] or ] move current line to the end or the begin of current buffer + nnoremap ] ddGp`` + nnoremap ] ddggP`` + vnoremap ] dGp`` + vnoremap ] dggP`` + + + "Ctrl+Shift+上下移动当前行 + nnoremap :m .+1== + nnoremap :m .-2== + inoremap :m .+1==gi + inoremap :m .-2==gi + "上下移动选中的行 + vnoremap :m '>+1gv=gv + vnoremap :m '<-2gv=gv + "background + noremap bg :call ToggleBG() + "numbers + noremap nu :call ToggleNumber() + " download gvimfullscreen.dll from github, copy gvimfullscreen.dll to + " the directory that has gvim.exe + nnoremap :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) + " yark and paste + vmap y "+y + vmap d "+d + nmap p "+p + nmap P "+P + vmap p "+p + vmap P "+P + + " Start new line + inoremap o + + " Improve scroll, credits: https://github.com/Shougo + nnoremap zz (winline() == (winheight(0)+1) / 2) ? + \ 'zt' : (winline() == 1) ? 'zb' : 'zz' + noremap max([winheight(0) - 2, 1]) + \ ."\".(line('w$') >= line('$') ? "L" : "H") + noremap max([winheight(0) - 2, 1]) + \ ."\".(line('w0') <= 1 ? "H" : "L") + noremap (line("w$") >= line('$') ? "j" : "3\") + noremap (line("w0") <= 1 ? "k" : "3\") + + " Select blocks after indenting + xnoremap < >gv| + + " Use tab for indenting in visual mode + xnoremap >gv| + xnoremap >>_ + nnoremap < <<_ + + " smart up and down + nnoremap gj + nnoremap gk + + " Select last paste + nnoremap gp '`['.strpart(getregtype(), 0, 1).'`]' + + " Disable Q and gQ + nnoremap Q + nnoremap gQ + + " Navigate window + nnoremap + nnoremap x + + " Navigation in command line + cnoremap + cnoremap + cnoremap + + " When pressing cd switch to the directory of the open buffer + " map cd :cd %:p:h:pwd "I use RooterChangeToRootDirectory + + " Fast saving + nnoremap w :w + vnoremap w :w + nnoremap :w + vnoremap :w + cnoremap w + + " Toggle editor visuals + nmap ts :setlocal spell! + nmap tn :setlocal nonumber! norelativenumber! + nmap tl :setlocal nolist! + nmap th :nohlsearch + nmap tw :setlocal wrap! breakindent! + + " Tabs + nnoremap g0 :tabfirst + nnoremap g$ :tablast + nnoremap gr :tabprevious + + " Remove spaces at the end of lines + nnoremap , :silent! keeppatterns %substitute/\s\+$//e + + " C-r: Easier search and replace + xnoremap :call VSetSearch('/'):%s/\V=@///gc + + " Location list movement + nmap lj :lnext + nmap lk :lprev + nmap lq :lclose + + " quickfix list movement + nmap qj :cnext + nmap qk :cprev + nmap qq :cclose + + " Duplicate lines + nnoremap d m`YP`` + vnoremap d YPgv + + "irssi like hot key + nnoremap :call tobur(1) + nnoremap :call tobur(2) + nnoremap :call tobur(3) + nnoremap :call tobur(4) + nnoremap :call tobur(5) + nnoremap :call tobur("bnext") + nnoremap :call tobur("bprev") + + "qqmsg hot key + nnoremap :call chat#qq#OpenMsgWin() + "weixin hot key + nnoremap :call chat#weixin#OpenMsgWin() + "chatting hot key + nnoremap :call chat#chatting#OpenMsgWin() + + "format current buffer + nnoremap g= :call zvim#format() + + + call zvim#util#defineMap('vnoremap', 'S', "y:execute @@:echo 'Sourced selection.'", + \ 'Sourced selection.', + \ "echo 'Use S to sourced selection.'") + call zvim#util#defineMap('nnoremap','S',"^vg_y:execute @@:echo 'Sourced line.'",'Source line', + \ "echo 'Use S to sourced line.'") + + call zvim#util#defineMap('nnoremap ', '', ':call zvim#util#CopyToClipboard()', + \ 'Copy buffer absolute path to X11 clipboard','call zvim#util#CopyToClipboard()') + call zvim#util#defineMap('nnoremap ', '', + \ ':call zvim#util#CopyToClipboard(1)', + \ 'Yank the github link of current file to X11 clipboard', + \ 'call zvim#util#CopyToClipboard(1)') + call zvim#util#defineMap('nnoremap ', '', + \ ':call zvim#util#CopyToClipboard(2)', + \ 'Yank the github link of current line to X11 clipboard', + \ 'call zvim#util#CopyToClipboard(2)') + call zvim#util#defineMap('vnoremap ', '', + \ ':call zvim#util#CopyToClipboard(3)', + \ 'Yank the github link of current selection to X11 clipboard', + \ 'call zvim#util#CopyToClipboard(3)') + " Window prefix + call zvim#util#defineMap('nnoremap', '[Window]', '' , 'Defind window prefix' ,'normal [Window]') + call zvim#util#defineMap('nmap' , 's' , '[Window]', 'Use s as window prefix' ,'normal s') + + call zvim#util#defineMap('nnoremap ', '', ':wincmd w', 'Switch to next window or tab','wincmd w') + call zvim#util#defineMap('nnoremap ', '', ':wincmd p', 'Switch to previous window or tab','wincmd p') + call zvim#util#defineMap('nnoremap ', '[Window]p', ':vsplit:wincmd w', + \'vsplit vertically,switch to next window','vsplit | wincmd w') + call zvim#util#defineMap('nnoremap ', '[Window]v', ':split', 'split window','split') + call zvim#util#defineMap('nnoremap ', '[Window]g', ':vsplit', 'vsplit window','vsplit') + call zvim#util#defineMap('nnoremap ', '[Window]t', ':tabnew', 'Create new tab','tabnew') + call zvim#util#defineMap('nnoremap ', '[Window]o', ':only', 'Close other windows','only') + call zvim#util#defineMap('nnoremap ', '[Window]x', ':call zvim#util#BufferEmpty()', + \'Empty current buffer','call zvim#util#BufferEmpty()') + call zvim#util#defineMap('nnoremap ', '[Window]\', ':b#', 'Switch to the last buffer','b#') + call zvim#util#defineMap('nnoremap ', '[Window]q', ':close', 'Close current windows','close') + call zvim#util#defineMap('nnoremap ', 'q', ':call zvim#util#SmartClose()', + \ 'Smart close windows', + \ 'call zvim#util#SmartClose()') + call zvim#util#defineMap('nnoremap ', 'qr', 'q', 'Toggle recording','') + call zvim#util#defineMap('nnoremap ', 'sv', ':split:wincmd p:e#', + \'Open previous buffer in split window' , 'split|wincmd p|e#') + call zvim#util#defineMap('nnoremap ', 'sg', ':vsplit:wincmd p:e#', + \'Open previous buffer in vsplit window' , 'vsplit|wincmd p|e#') + call zvim#util#defineMap('nnoremap ', 'gf', ':call zvim#gf()', 'Jump to a file under cursor', '') +endfunction + +fu! s:tobur(num) abort + if index(get(g:,'spacevim_altmoveignoreft',[]), &filetype) == -1 + if a:num ==# 'bnext' + bnext + elseif a:num ==# 'bprev' + bprev + else + let ls = split(execute(':ls'), "\n") + let buffers = [] + for b in ls + let nr = matchstr(b, '\d\+') + call add(buffers, nr) + endfor + if len(buffers) >= a:num + exec 'buffer ' . buffers[a:num - 1] + endif + endif + endif +endf diff --git a/config/main.vim b/config/main.vim index 0a9a898e2..e6d236066 100644 --- a/config/main.vim +++ b/config/main.vim @@ -20,7 +20,7 @@ call zvim#util#source_rc('plugins.vim') call zvim#util#source_rc('general.vim') -call zvim#util#source_rc('mappings.vim') + call SpaceVim#autocmds#init() diff --git a/config/mappings.vim b/config/mappings.vim deleted file mode 100644 index e6d910f4c..000000000 --- a/config/mappings.vim +++ /dev/null @@ -1,241 +0,0 @@ -scriptencoding utf-8 -"mapping -"全局映射 -"也可以通过'za'打开或者关闭折叠 -nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') -"Super paste it does not work -"ino :set pastemui+mv'uV'v=:set nopaste -"对于没有权限的文件使用 :w!!来保存 -cnoremap w!! %!sudo tee > /dev/null % -" cmap W!! w !sudo tee % >/dev/null " I can not understand -" Save a file with sudo -" http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN - - -" 映射Ctrl+上下左右来切换窗口 -nnoremap :wincmd l -nnoremap :wincmd h -nnoremap :wincmd k -nnoremap :wincmd j -if has('nvim') - exe 'tnoremap :wincmd l' - exe 'tnoremap :wincmd h' - exe 'tnoremap :wincmd k' - exe 'tnoremap :wincmd j' - exe 'tnoremap ' -endif - -"for buftabs -noremap bp :bprev -noremap bn :bnext - -"Quickly add empty lines -nnoremap [ :put! =repeat(nr2char(10), v:count1) -nnoremap ] :put =repeat(nr2char(10), v:count1) - -"Use jk switch to normal model -inoremap jk - -"]e or [e move current line ,count can be useed -nnoremap [e :execute 'move -1-'. v:count1 -nnoremap ]e :execute 'move +'. v:count1 - -"] or ] move current line to the end or the begin of current buffer -nnoremap ] ddGp`` -nnoremap ] ddggP`` -vnoremap ] dGp`` -vnoremap ] dggP`` - - -"Ctrl+Shift+上下移动当前行 -nnoremap :m .+1== -nnoremap :m .-2== -inoremap :m .+1==gi -inoremap :m .-2==gi -"上下移动选中的行 -vnoremap :m '>+1gv=gv -vnoremap :m '<-2gv=gv -"background -noremap bg :call ToggleBG() -"numbers -noremap nu :call ToggleNumber() -" download gvimfullscreen.dll from github, copy gvimfullscreen.dll to -" the directory that has gvim.exe -nnoremap :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) -" yark and paste -vmap y "+y -vmap d "+d -nmap p "+p -nmap P "+P -vmap p "+p -vmap P "+P - -" Start new line -inoremap o - -" Improve scroll, credits: https://github.com/Shougo -nnoremap zz (winline() == (winheight(0)+1) / 2) ? - \ 'zt' : (winline() == 1) ? 'zb' : 'zz' -noremap max([winheight(0) - 2, 1]) - \ ."\".(line('w$') >= line('$') ? "L" : "H") -noremap max([winheight(0) - 2, 1]) - \ ."\".(line('w0') <= 1 ? "H" : "L") -noremap (line("w$") >= line('$') ? "j" : "3\") -noremap (line("w0") <= 1 ? "k" : "3\") - -" Select blocks after indenting -xnoremap < >gv| - -" Use tab for indenting in visual mode -xnoremap >gv| -xnoremap >>_ -nnoremap < <<_ - -" smart up and down -nnoremap gj -nnoremap gk - -" Select last paste -nnoremap gp '`['.strpart(getregtype(), 0, 1).'`]' - -" Disable Q and gQ -nnoremap Q -nnoremap gQ - -" Navigate window -nnoremap -nnoremap x - -" Navigation in command line -cnoremap -cnoremap -cnoremap - -" When pressing cd switch to the directory of the open buffer -" map cd :cd %:p:h:pwd "I use RooterChangeToRootDirectory - -" Fast saving -nnoremap w :w -vnoremap w :w -nnoremap :w -vnoremap :w -cnoremap w - -" Toggle editor visuals -nmap ts :setlocal spell! -nmap tn :setlocal nonumber! norelativenumber! -nmap tl :setlocal nolist! -nmap th :nohlsearch -nmap tw :setlocal wrap! breakindent! - -" Tabs -nnoremap g0 :tabfirst -nnoremap g$ :tablast -nnoremap gr :tabprevious - -" Remove spaces at the end of lines -nnoremap , :silent! keeppatterns %substitute/\s\+$//e - -" C-r: Easier search and replace -xnoremap :call VSetSearch('/'):%s/\V=@///gc - -" Location list movement -nmap lj :lnext -nmap lk :lprev -nmap lq :lclose - -" quickfix list movement -nmap qj :cnext -nmap qk :cprev -nmap qq :cclose - -" Duplicate lines -nnoremap d m`YP`` -vnoremap d YPgv - -fu! s:tobur(num) - if index(get(g:,'spacevim_altmoveignoreft',[]), &filetype) == -1 - if a:num ==# 'bnext' - bnext - elseif a:num ==# 'bprev' - bprev - else - let ls = split(execute(':ls'), "\n") - let buffers = [] - for b in ls - let nr = matchstr(b, '\d\+') - call add(buffers, nr) - endfor - if len(buffers) >= a:num - exec 'buffer ' . buffers[a:num - 1] - endif - endif - endif -endf -"irssi like hot key -nnoremap :call tobur(1) -nnoremap :call tobur(2) -nnoremap :call tobur(3) -nnoremap :call tobur(4) -nnoremap :call tobur(5) -nnoremap :call tobur("bnext") -nnoremap :call tobur("bprev") - -"qqmsg hot key -nnoremap :call chat#qq#OpenMsgWin() -"weixin hot key -nnoremap :call chat#weixin#OpenMsgWin() -"chatting hot key -nnoremap :call chat#chatting#OpenMsgWin() - -"format current buffer -nnoremap g= :call zvim#format() - - -call zvim#util#defineMap('vnoremap', 'S', "y:execute @@:echo 'Sourced selection.'", - \ 'Sourced selection.', - \ "echo 'Use S to sourced selection.'") -call zvim#util#defineMap('nnoremap','S',"^vg_y:execute @@:echo 'Sourced line.'",'Source line', - \ "echo 'Use S to sourced line.'") - -call zvim#util#defineMap('nnoremap ', '', ':call zvim#util#CopyToClipboard()', - \ 'Copy buffer absolute path to X11 clipboard','call zvim#util#CopyToClipboard()') -call zvim#util#defineMap('nnoremap ', '', - \ ':call zvim#util#CopyToClipboard(1)', - \ 'Yank the github link of current file to X11 clipboard', - \ 'call zvim#util#CopyToClipboard(1)') -call zvim#util#defineMap('nnoremap ', '', - \ ':call zvim#util#CopyToClipboard(2)', - \ 'Yank the github link of current line to X11 clipboard', - \ 'call zvim#util#CopyToClipboard(2)') -call zvim#util#defineMap('vnoremap ', '', - \ ':call zvim#util#CopyToClipboard(3)', - \ 'Yank the github link of current selection to X11 clipboard', - \ 'call zvim#util#CopyToClipboard(3)') -" Window prefix -call zvim#util#defineMap('nnoremap', '[Window]', '' , 'Defind window prefix' ,'normal [Window]') -call zvim#util#defineMap('nmap' , 's' , '[Window]', 'Use s as window prefix' ,'normal s') - -call zvim#util#defineMap('nnoremap ', '', ':wincmd w', 'Switch to next window or tab','wincmd w') -call zvim#util#defineMap('nnoremap ', '', ':wincmd p', 'Switch to previous window or tab','wincmd p') -call zvim#util#defineMap('nnoremap ', '[Window]p', ':vsplit:wincmd w', - \'vsplit vertically,switch to next window','vsplit | wincmd w') -call zvim#util#defineMap('nnoremap ', '[Window]v', ':split', 'split window','split') -call zvim#util#defineMap('nnoremap ', '[Window]g', ':vsplit', 'vsplit window','vsplit') -call zvim#util#defineMap('nnoremap ', '[Window]t', ':tabnew', 'Create new tab','tabnew') -call zvim#util#defineMap('nnoremap ', '[Window]o', ':only', 'Close other windows','only') -call zvim#util#defineMap('nnoremap ', '[Window]x', ':call zvim#util#BufferEmpty()', - \'Empty current buffer','call zvim#util#BufferEmpty()') -call zvim#util#defineMap('nnoremap ', '[Window]\', ':b#', 'Switch to the last buffer','b#') -call zvim#util#defineMap('nnoremap ', '[Window]q', ':close', 'Close current windows','close') -call zvim#util#defineMap('nnoremap ', 'q', ':call zvim#util#SmartClose()', - \ 'Smart close windows', - \ 'call zvim#util#SmartClose()') -call zvim#util#defineMap('nnoremap ', 'qr', 'q', 'Toggle recording','') -call zvim#util#defineMap('nnoremap ', 'sv', ':split:wincmd p:e#', - \'Open previous buffer in split window' , 'split|wincmd p|e#') -call zvim#util#defineMap('nnoremap ', 'sg', ':vsplit:wincmd p:e#', - \'Open previous buffer in vsplit window' , 'vsplit|wincmd p|e#') -call zvim#util#defineMap('nnoremap ', 'gf', ':call zvim#gf()', 'Jump to a file under cursor', '')