1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-23 17:11:32 +08:00
SpaceVim/autoload/SpaceVim/layers/default.vim

196 lines
7.8 KiB
VimL
Raw Normal View History

2017-02-08 20:27:27 +08:00
""
" @section Default, default
" @parentsection layers
function! SpaceVim#layers#default#plugins() abort
let plugins = []
2017-02-08 20:27:27 +08:00
return plugins
endfunction
function! SpaceVim#layers#default#config() abort
2017-05-25 00:27:56 +08:00
" Unimpaired bindings
" Quickly add empty lines
nnoremap <silent> [<space> :<c-u>put! =repeat(nr2char(10), v:count1)<cr>
nnoremap <silent> ]<space> :<c-u>put =repeat(nr2char(10), v:count1)<cr>
"]e or [e move current line ,count can be useed
nnoremap <silent>[e :<c-u>execute 'move -1-'. v:count1<cr>
nnoremap <silent>]e :<c-u>execute 'move +'. v:count1<cr>
" [b or ]n go to previous or next buffer
nnoremap <silent> [b :<c-u>bN<cr>
nnoremap <silent> ]b :<c-u>bn<cr>
" [f or ]f go to next or previous file in dir
nnoremap <silent> ]f :<c-u>call <SID>next_file()<cr>
nnoremap <silent> [f :<c-u>call <SID>previous_file()<cr>
2017-05-25 00:48:45 +08:00
" [l or ]l go to next and previous error
nnoremap <silent> [l :lprevious<cr>
nnoremap <silent> ]l :lnext<cr>
" [c or ]c go to next or previous vcs hunk
2017-05-25 20:18:21 +08:00
" [w or ]w go to next or previous window
nnoremap <silent> [w :call <SID>previous_window()<cr>
nnoremap <silent> ]w :call <SID>next_window()<cr>
2017-05-25 21:06:14 +08:00
" [t or ]t for next and previous tab
nnoremap <silent> [t :tabprevious<cr>
nnoremap <silent> ]t :tabnext<cr>
" [p or ]p for p and P
nnoremap <silent> [p P
nnoremap <silent> ]p p
" Select last paste
nnoremap <silent><expr> gp '`['.strpart(getregtype(), 0, 1).'`]'
2017-05-25 00:27:56 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['f', 'f'], "exe 'CtrlP ' . fnamemodify(bufname('%'), ':h')", 'Find files in the directory of the current buffer', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 's'], 'write', 'save buffer', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'S'], 'wall', 'save all buffer', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'W'], 'write !sudo tee % >/dev/null', 'save buffer with sudo', 1)
" help mappings
call SpaceVim#mapping#space#def('nnoremap', ['h', 'I'], 'call SpaceVim#issue#report()', 'Reporting an issue of SpaceVim', 1)
if has('python3')
call SpaceVim#mapping#space#def('nnoremap', ['h', 'i'], 'DeniteCursorWord help', 'get help with the symbol at point', 1)
else
call SpaceVim#mapping#space#def('nnoremap', ['h', 'i'], 'UniteWithCursorWord help', 'get help with the symbol at point', 1)
endif
call SpaceVim#mapping#space#def('nnoremap', ['h', 'l'], 'SPLayer -l', 'lists all the layers available in SpaceVim', 1)
call SpaceVim#mapping#space#def('nnoremap', ['h', 'm'], 'Unite manpage', 'search available man pages', 1)
call SpaceVim#mapping#space#def('nnoremap', ['h', 'k'], 'LeaderGuide "[KEYs]"', 'show top-level bindings with mapping guide', 1)
call SpaceVim#mapping#space#def('nnoremap', ['h', '[SPC]'], 'Unite help -input=SpaceVim', 'unite-SpaceVim-help', 1)
call SpaceVim#mapping#space#def('nnoremap', ['j', '0'], 'm`^', 'push mark and goto beginning of line', 0)
call SpaceVim#mapping#space#def('nnoremap', ['j', '$'], 'm`g_', 'push mark and goto beginning of line', 0)
2017-06-01 23:41:13 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['j', 'b'], '<C-o>', 'jump backward', 0)
call SpaceVim#mapping#space#def('nnoremap', ['j', 'f'], '<C-i>', 'jump forward', 0)
2017-05-28 23:24:55 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['j', 'd'], 'VimFiler -no-split', 'Explore current directory', 1)
call SpaceVim#mapping#space#def('nnoremap', ['j', 'D'], 'VimFiler', 'Explore current directory (other window)', 1)
call SpaceVim#mapping#space#def('nmap', ['j', 'j'], '<Plug>(easymotion-prefix)s', 'jump to a character', 0)
2017-06-01 23:30:17 +08:00
call SpaceVim#mapping#space#def('nmap', ['j', 'J'], '<Plug>(easymotion-s2)', 'jump to a suite of two characters', 0)
2017-05-28 23:24:55 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['j', 'k'], 'j==', 'go to next line and indent', 0)
call SpaceVim#mapping#space#def('nmap', ['j', 'l'], '<Plug>(easymotion-bd-jk)', 'jump to a line', 0)
call SpaceVim#mapping#space#def('nmap', ['j', 'u'], '<Plug>(easymotion-bd-jk)', 'jump to a line', 0)
call SpaceVim#mapping#space#def('nmap', ['j', 'v'], '<Plug>(easymotion-bd-jk)', 'jump to a line', 0)
call SpaceVim#mapping#space#def('nmap', ['j', 'w'], '<Plug>(easymotion-bd-jk)', 'jump to a line', 0)
call SpaceVim#mapping#space#def('nmap', ['j', 'q'], '<Plug>(easymotion-bd-jk)', 'jump to a line', 0)
call SpaceVim#mapping#space#def('nnoremap', ['j', 'n'], "i\<cr>\<esc>", 'sp-newline', 0)
2017-06-02 00:05:55 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['j', 'o'], "i\<cr>\<esc>k$", 'open-line', 0)
call SpaceVim#mapping#space#def('nnoremap', ['j', 's'], 'call call('
\ . string(s:_function('s:split_string')) . ', [0])',
\ 'split sexp', 1)
call SpaceVim#mapping#space#def('nnoremap', ['j', 'S'], 'call call('
\ . string(s:_function('s:split_string')) . ', [1])',
\ 'split-and-add-newline', 1)
2017-05-30 23:53:06 +08:00
call SpaceVim#mapping#space#def('nnoremap', ['w', 'r'], 'call call('
\ . string(s:_function('s:next_window')) . ', [])',
\ 'rotate windows forward', 1)
call SpaceVim#mapping#space#def('nnoremap', ['w', 'R'], 'call call('
\ . string(s:_function('s:previous_window')) . ', [])',
\ 'rotate windows backward', 1)
2017-02-08 20:27:27 +08:00
endfunction
2017-05-25 00:27:56 +08:00
let s:file = SpaceVim#api#import('file')
function! s:next_file() abort
let dir = expand('%:p:h')
let f = expand('%:t')
let file = s:file.ls(dir, 1)
if index(file, f) == -1
call add(file,f)
endif
call sort(file)
if len(file) != 1
if index(file, f) == len(file) - 1
exe 'e ' . dir . s:file.separator . file[0]
else
exe 'e ' . dir . s:file.separator . file[index(file, f) + 1]
endif
endif
endfunction
function! s:previous_file() abort
let dir = expand('%:p:h')
let f = expand('%:t')
let file = s:file.ls(dir, 1)
if index(file, f) == -1
call add(file,f)
endif
call sort(file)
if len(file) != 1
if index(file, f) == 0
exe 'e ' . dir . s:file.separator . file[-1]
else
exe 'e ' . dir . s:file.separator . file[index(file, f) - 1]
endif
endif
endfunction
2017-05-25 20:18:21 +08:00
function! s:next_window() abort
try
exe (winnr() + 1 ) . 'wincmd w'
catch
exe 1 . 'wincmd w'
endtry
endfunction
function! s:previous_window() abort
try
if winnr() == 1
exe winnr('$') . 'wincmd w'
else
exe (winnr() - 1 ) . 'wincmd w'
endif
catch
exe winnr('$') . 'wincmd w'
endtry
endfunction
function! s:split_string(newline) abort
let syn_name = synIDattr(synID(line("."), col("."), 1), "name")
if syn_name == &filetype . 'String'
let c = col('.')
let sep = ''
while c > 0
if s:is_string(line('.'), c)
let c = c - 1
else
let sep = getline('.')[c]
break
endif
endwhile
if a:newline
let save_register_m = @m
let @m = sep . "\n" . sep
normal! "mp
let @m = save_register_m
else
let save_register_m = @m
let @m = sep . sep
normal! "mp
let @m = save_register_m
endif
endif
endfunction
function! s:is_string(l,c) abort
return synIDattr(synID(a:l, a:c, 1), "name") == &filetype . 'String'
endfunction
" function() wrapper
if v:version > 703 || v:version == 703 && has('patch1170')
function! s:_function(fstr) abort
return function(a:fstr)
endfunction
else
function! s:_SID() abort
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
endfunction
let s:_s = '<SNR>' . s:_SID() . '_'
function! s:_function(fstr) abort
return function(substitute(a:fstr, 's:', s:_s, 'g'))
endfunction
endif