From f53fc71e3fa994f23b891f4b1f48ac6006f000ff Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 17 Jul 2017 07:08:53 +0800 Subject: [PATCH] Add mappings for changing symbol style --- autoload/SpaceVim/layers/edit.vim | 57 ++++++++++++++++++++++++++++++ autoload/SpaceVim/layers/tools.vim | 1 + docs/documentation.md | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/layers/edit.vim b/autoload/SpaceVim/layers/edit.vim index 956a7d22d..1ba58281c 100644 --- a/autoload/SpaceVim/layers/edit.vim +++ b/autoload/SpaceVim/layers/edit.vim @@ -1,3 +1,4 @@ +scriptencoding utf-8 function! SpaceVim#layers#edit#plugins() abort let plugins = [ \ ['tpope/vim-surround'], @@ -40,6 +41,8 @@ function! SpaceVim#layers#edit#config() abort let g:wildfire_objects = ["i'", 'i"', 'i)', 'i]', 'i}', 'ip', 'it'] let g:_spacevim_mappings_space.x = {'name' : '+Text'} let g:_spacevim_mappings_space.x.a = {'name' : '+align'} + let g:_spacevim_mappings_space.x.d = {'name' : '+delete'} + let g:_spacevim_mappings_space.x.i = {'name' : '+change symbol style'} call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '&'], 'Tabularize /&', 'align region at &', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '('], 'Tabularize /(', 'align region at (', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ')'], 'Tabularize /)', 'align region at )', 1) @@ -50,5 +53,59 @@ function! SpaceVim#layers#edit#config() abort call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ','], 'Tabularize /,', 'align region at ,', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '.'], 'Tabularize /.', 'align region at .', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ':'], 'Tabularize /:', 'align region at :', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', ';'], 'Tabularize /;', 'align region at ;', 1) call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '='], 'Tabularize /=', 'align region at =', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'a', '¦'], 'Tabularize /¦', 'align region at ¦', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'd', 'w'], 'StripWhitespace', 'delete trailing whitespaces', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'd', '[SPC]'], 'silent call call(' + \ . string(s:_function('s:delete_extra_space')) . ', [])', + \ 'delete extra space arround cursor', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'c'], 'silent call call(' + \ . string(s:_function('s:lowerCamelCase')) . ', [])', + \ 'change symbol style to lowerCamelCase', 1) + call SpaceVim#mapping#space#def('nnoremap', ['x', 'i', 'C'], 'silent call call(' + \ . string(s:_function('s:UpperCamelCase')) . ', [])', + \ 'change symbol style to UpperCamelCase', 1) endfunction + +function! s:lowerCamelCase() abort + let cword = expand('') + if !empty(cword) && cword[0:0] =~# '[A-Z]' + let save_cursor = getcurpos() + normal! b~ + call setpos('.', save_cursor) + endif +endfunction + +function! s:UpperCamelCase() abort + let cword = expand('') + if !empty(cword) && cword[0:0] =~# '[a-z]' + let save_cursor = getcurpos() + normal! b~ + call setpos('.', save_cursor) + endif +endfunction + + +function! s:delete_extra_space() abort + if !empty(getline('.')) + if getline('.')[col('.')-1] ==# ' ' + exe "normal! viw\"_di\\" + endif + endif +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(''), '\zs\d\+\ze__SID$') + endfunction + let s:_s = '' . s:_SID() . '_' + function! s:_function(fstr) abort + return function(substitute(a:fstr, 's:', s:_s, 'g')) + endfunction +endif diff --git a/autoload/SpaceVim/layers/tools.vim b/autoload/SpaceVim/layers/tools.vim index 13fabf06f..0c7877e20 100644 --- a/autoload/SpaceVim/layers/tools.vim +++ b/autoload/SpaceVim/layers/tools.vim @@ -47,6 +47,7 @@ function! SpaceVim#layers#tools#plugins() abort endfunction function! SpaceVim#layers#tools#config() abort + let g:better_whitespace_filetypes_blacklist = ['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown', 'leaderGuide'] call SpaceVim#mapping#space#def('nnoremap', ['a', 'c'], 'Calendar', 'vim calendar', 1) call SpaceVim#mapping#space#def('nnoremap', ['e', 'a'], 'FencAutoDetect', \ 'Auto detect the file encoding', 1) diff --git a/docs/documentation.md b/docs/documentation.md index 41ffc165a..a568ca164 100644 --- a/docs/documentation.md +++ b/docs/documentation.md @@ -1129,13 +1129,13 @@ Key Binding | Description `SPC x a :` | align region at : `SPC x a ;` | align region at ; `SPC x a =` | align region at = +`SPC x a ¦` | align region at ¦ `SPC x a a` | align region (or guessed section) using default rules `SPC x a c` | align current indentation region using default rules `SPC x a l` | left-align with evil-lion `SPC x a L` | right-align with evil-lion `SPC x a r` | align region using user-specified regexp `SPC x a m` | align region at arithmetic operators `` (+-*/) `` -`SPC x a ¦` | align region at ¦ `SPC x c` | cunt the number of chars/words/lines in the selection region `SPC x d w` | delete trailing whitespaces `SPC x d SPC` | Delete all spaces and tabs around point, leaving one space