mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 04:30:04 +08:00
Merge branch 'comment' into dev
This commit is contained in:
commit
7401904c51
@ -20,6 +20,8 @@ function! SpaceVim#mapping#g#init() abort
|
|||||||
nnoremap g, g,
|
nnoremap g, g,
|
||||||
let g:_spacevim_mappings_g[';'] = ['call feedkeys("g;", "n")', 'older position in change list']
|
let g:_spacevim_mappings_g[';'] = ['call feedkeys("g;", "n")', 'older position in change list']
|
||||||
nnoremap g; g;
|
nnoremap g; g;
|
||||||
|
let g:_spacevim_mappings_g['@'] = ['call feedkeys("g@", "n")', 'call operatorfunc']
|
||||||
|
nnoremap g@ g@
|
||||||
|
|
||||||
let g:_spacevim_mappings_g['#'] = ['call feedkeys("\<Plug>(incsearch-nohl-g#)")', 'search under cursor backward']
|
let g:_spacevim_mappings_g['#'] = ['call feedkeys("\<Plug>(incsearch-nohl-g#)")', 'search under cursor backward']
|
||||||
let g:_spacevim_mappings_g['*'] = ['call feedkeys("\<Plug>(incsearch-nohl-g*)")', 'search under cursor forward']
|
let g:_spacevim_mappings_g['*'] = ['call feedkeys("\<Plug>(incsearch-nohl-g*)")', 'search under cursor forward']
|
||||||
|
@ -74,7 +74,26 @@ function! SpaceVim#mapping#space#init() abort
|
|||||||
"
|
"
|
||||||
" Toggles the comment state of the selected line(s). If the topmost selected
|
" Toggles the comment state of the selected line(s). If the topmost selected
|
||||||
" line is commented, all selected lines are uncommented and vice versa.
|
" line is commented, all selected lines are uncommented and vice versa.
|
||||||
call SpaceVim#mapping#space#def('nnoremap', ['c', 'l'], 'call NERDComment("n", "Toggle")', 'Toggle comment line(s)', 1)
|
call SpaceVim#mapping#space#def('nmap', ['c', 'l'], '<Plug>NERDCommenterComment', 'comment lines', 0, 1)
|
||||||
|
call SpaceVim#mapping#space#def('nmap', ['c', 'L'], '<Plug>NERDCommenterInvert', 'toggle comment lines', 0, 1)
|
||||||
|
call SpaceVim#mapping#space#def('nmap', ['c', 'p'], 'vip<Plug>NERDCommenterComment', 'comment paragraphs', 0, 1)
|
||||||
|
call SpaceVim#mapping#space#def('nmap', ['c', 'P'], 'vip<Plug>NERDCommenterInvert', 'toggle comment paragraphs', 0, 1)
|
||||||
|
|
||||||
|
nnoremap <silent> <Plug>CommentToLine :call <SID>comment_to_line(0)<Cr>
|
||||||
|
nnoremap <silent> <Plug>CommentToLineInvert :call <SID>comment_to_line(1)<Cr>
|
||||||
|
call SpaceVim#mapping#space#def('nmap', ['c', 't'], '<Plug>CommentToLine', 'comment to line', 0, 1)
|
||||||
|
call SpaceVim#mapping#space#def('nmap', ['c', 'T'], '<Plug>CommentToLineInvert', 'toggle comment to line', 0, 1)
|
||||||
|
|
||||||
|
nnoremap <silent> <Plug>CommentOperator :set opfunc=<SID>commentOperator<Cr>g@
|
||||||
|
let g:_spacevim_mappings_space[';'] = ['call feedkeys("\<Plug>CommentOperator")', 'comment operator']
|
||||||
|
nmap <silent> [SPC]; <Plug>CommentOperator
|
||||||
|
|
||||||
|
" in nerdcomment if has map to <plug>... the default mapping will be
|
||||||
|
" disable, so we add it for compatibility
|
||||||
|
nmap <Leader>cc <Plug>NERDCommenterComment
|
||||||
|
xmap <Leader>cc <Plug>NERDCommenterComment
|
||||||
|
nmap <Leader>ci <Plug>NERDCommenterInvert
|
||||||
|
xmap <Leader>ci <Plug>NERDCommenterInvert
|
||||||
|
|
||||||
let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'}
|
let g:_spacevim_mappings_space.e = {'name' : '+Errors/Encoding'}
|
||||||
let g:_spacevim_mappings_space.B = {'name' : '+Global-buffers'}
|
let g:_spacevim_mappings_space.B = {'name' : '+Global-buffers'}
|
||||||
@ -205,10 +224,11 @@ function! SpaceVim#mapping#space#init() abort
|
|||||||
\ 'clear search highlight', 1)
|
\ 'clear search highlight', 1)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd) abort
|
function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd, ...) abort
|
||||||
if s:has_map_to_spc()
|
if s:has_map_to_spc()
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
let is_visual = a:0 > 0 ? a:1 : 0
|
||||||
if a:is_cmd
|
if a:is_cmd
|
||||||
let cmd = ':<C-u>' . a:cmd . '<CR>'
|
let cmd = ':<C-u>' . a:cmd . '<CR>'
|
||||||
let lcmd = a:cmd
|
let lcmd = a:cmd
|
||||||
@ -222,6 +242,13 @@ function! SpaceVim#mapping#space#def(m, keys, cmd, desc, is_cmd) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
exe a:m . ' <silent> [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g')
|
exe a:m . ' <silent> [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g')
|
||||||
|
if is_visual
|
||||||
|
if a:m ==# 'nnoremap'
|
||||||
|
exe 'xnoremap <silent> [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g')
|
||||||
|
elseif a:m ==# 'nmap'
|
||||||
|
exe 'xmap <silent> [SPC]' . join(a:keys, '') . ' ' . substitute(cmd, '|', '\\|', 'g')
|
||||||
|
endif
|
||||||
|
endif
|
||||||
if len(a:keys) == 2
|
if len(a:keys) == 2
|
||||||
let g:_spacevim_mappings_space[a:keys[0]][a:keys[1]] = [lcmd, a:desc]
|
let g:_spacevim_mappings_space[a:keys[0]][a:keys[1]] = [lcmd, a:desc]
|
||||||
elseif len(a:keys) == 3
|
elseif len(a:keys) == 3
|
||||||
@ -287,4 +314,45 @@ function! SpaceVim#mapping#space#langSPC(m, keys, cmd, desc, is_cmd) abort
|
|||||||
call extend(g:_spacevim_mappings_prefixs['[SPC]'], get(g:, '_spacevim_mappings_space', {}))
|
call extend(g:_spacevim_mappings_prefixs['[SPC]'], get(g:, '_spacevim_mappings_space', {}))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:commentOperator(type, ...)
|
||||||
|
let sel_save = &selection
|
||||||
|
let &selection = "inclusive"
|
||||||
|
let reg_save = @@
|
||||||
|
|
||||||
|
if a:0 " Invoked from Visual mode, use gv command.
|
||||||
|
silent exe "normal! gv"
|
||||||
|
call feedkeys("\<Plug>NERDCommenterComment")
|
||||||
|
elseif a:type == 'line'
|
||||||
|
call feedkeys('`[V`]')
|
||||||
|
call feedkeys("\<Plug>NERDCommenterComment")
|
||||||
|
else
|
||||||
|
call feedkeys('`[v`]')
|
||||||
|
call feedkeys("\<Plug>NERDCommenterComment")
|
||||||
|
endif
|
||||||
|
|
||||||
|
let &selection = sel_save
|
||||||
|
let @@ = reg_save
|
||||||
|
set opfunc=
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:comment_to_line(invert) abort
|
||||||
|
let input = input('line number :')
|
||||||
|
if empty(input)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
let line = str2nr(input)
|
||||||
|
let ex = line - line('.')
|
||||||
|
if ex > 0
|
||||||
|
exe 'normal! V'. ex .'j'
|
||||||
|
elseif ex == 0
|
||||||
|
else
|
||||||
|
exe 'normal! V'. abs(ex) .'k'
|
||||||
|
endif
|
||||||
|
if a:invert
|
||||||
|
call feedkeys("\<Plug>NERDCommenterInvert")
|
||||||
|
else
|
||||||
|
call feedkeys("\<Plug>NERDCommenterComment")
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
" vim:set et sw=2 cc=80:
|
" vim:set et sw=2 cc=80:
|
||||||
|
@ -80,6 +80,7 @@ title: "Documentation"
|
|||||||
* [Persistent highlighting](#persistent-highlighting)
|
* [Persistent highlighting](#persistent-highlighting)
|
||||||
* [Editing](#editing)
|
* [Editing](#editing)
|
||||||
* [Text insertion commands](#text-insertion-commands)
|
* [Text insertion commands](#text-insertion-commands)
|
||||||
|
* [Commenting](#commenting)
|
||||||
* [Multi-Encodings](#multi-encodings)
|
* [Multi-Encodings](#multi-encodings)
|
||||||
* [Errors handling](#errors-handling)
|
* [Errors handling](#errors-handling)
|
||||||
* [Achievements](#achievements)
|
* [Achievements](#achievements)
|
||||||
@ -1158,6 +1159,7 @@ SpaceVim uses `g:spacevim_search_highlight_persist` to keep the searched express
|
|||||||
Text insertion commands (start with `i`):
|
Text insertion commands (start with `i`):
|
||||||
|
|
||||||
Key binding | Description
|
Key binding | Description
|
||||||
|
----------- | -----------
|
||||||
`SPC i l l` | insert lorem-ipsum list
|
`SPC i l l` | insert lorem-ipsum list
|
||||||
`SPC i l p` | insert lorem-ipsum paragraph
|
`SPC i l p` | insert lorem-ipsum paragraph
|
||||||
`SPC i l s` | insert lorem-ipsum sentence
|
`SPC i l s` | insert lorem-ipsum sentence
|
||||||
@ -1171,6 +1173,25 @@ Key binding | Description
|
|||||||
`SPC i U 4` | insert UUIDv4 (use universal argument to insert with CID format)
|
`SPC i U 4` | insert UUIDv4 (use universal argument to insert with CID format)
|
||||||
`SPC i U U` | insert UUIDv4 (use universal argument to insert with CID format)
|
`SPC i U U` | insert UUIDv4 (use universal argument to insert with CID format)
|
||||||
|
|
||||||
|
#### Commenting
|
||||||
|
|
||||||
|
Comments are handled by [nerdcommenter](https://github.com/scrooloose/nerdcommenter), it’s bound to the following keys.
|
||||||
|
|
||||||
|
Key Binding | Description
|
||||||
|
----------- | -----------
|
||||||
|
`SPC ;` | comment operator
|
||||||
|
`SPC c h` | hide/show comments
|
||||||
|
`SPC c l` | comment lines
|
||||||
|
`SPC c L` | invert comment lines
|
||||||
|
`SPC c p` | comment paragraphs
|
||||||
|
`SPC c P` | invert comment paragraphs
|
||||||
|
`SPC c t` | comment to line
|
||||||
|
`SPC c T` | invert comment to line
|
||||||
|
`SPC c y` | comment and yank
|
||||||
|
`SPC c Y` | invert comment and yank
|
||||||
|
|
||||||
|
**Tips:** To comment efficiently a block of line use the combo `SPC ; SPC j l`
|
||||||
|
|
||||||
#### Multi-Encodings
|
#### Multi-Encodings
|
||||||
|
|
||||||
SpaceVim use utf-8 as default encoding. there are four options for these case:
|
SpaceVim use utf-8 as default encoding. there are four options for these case:
|
||||||
|
Loading…
Reference in New Issue
Block a user