1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-13 02:05:40 +08:00

Add ~ keybinding for iedit (#3046)

This commit is contained in:
Wang Shidong 2019-09-12 13:07:57 +08:00 committed by GitHub
parent 64dc68d796
commit ad849b6bc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -49,6 +49,20 @@ function! s:self.fill(str, length, ...) abort
return l:string . l:spaces return l:string . l:spaces
endfunction endfunction
function! s:self.toggle_case(str) abort
let chars = []
for char in self.string2chars(a:str)
if char2nr(char) >= 97 && char2nr(char) <= 122
call add(chars, nr2char(char2nr(char) - 32))
elseif char2nr(char) >= 65 && char2nr(char) <= 90
call add(chars, nr2char(char2nr(char) + 32))
else
call add(chars, char)
endif
endfor
return join(chars, '')
endfunction
function! s:self.fill_left(str, length, ...) abort function! s:self.fill_left(str, length, ...) abort
if strwidth(a:str) <= a:length if strwidth(a:str) <= a:length
let l:string = a:str let l:string = a:str

View File

@ -221,6 +221,11 @@ function! s:handle_normal(char) abort
let s:cursor_stack[i].end = '' let s:cursor_stack[i].end = ''
endfor endfor
call s:replace_symbol() call s:replace_symbol()
elseif a:char == 126 " ~
for i in range(len(s:cursor_stack))
let s:cursor_stack[i].cursor = s:STRING.toggle_case(s:cursor_stack[i].cursor)
endfor
call s:replace_symbol()
elseif a:char == 115 " s elseif a:char == 115 " s
let s:mode = 'i' let s:mode = 'i'
let w:spacevim_iedit_mode = s:mode let w:spacevim_iedit_mode = s:mode

View File

@ -40,4 +40,6 @@ Execute ( SpaceVim api: data#string ):
AssertEqual str.strAllIndex('hello spacevim hello', 'he.*', 1), [[0, 20]] AssertEqual str.strAllIndex('hello spacevim hello', 'he.*', 1), [[0, 20]]
AssertEqual str.strAllIndex('hello spacevim hello', 'he[^ ]*', 1), [[0, 5], [15, 20]] AssertEqual str.strAllIndex('hello spacevim hello', 'he[^ ]*', 1), [[0, 5], [15, 20]]
AssertEqual str.strAllIndex('let s:cursor_stack[i].end = s:cursor_stack[i].cursor . s:cursor_stack[i].end', 's.cursor[^_]*', 1), [[4, 12], [28, 36], [55, 63]] AssertEqual str.strAllIndex('let s:cursor_stack[i].end = s:cursor_stack[i].cursor . s:cursor_stack[i].end', 's.cursor[^_]*', 1), [[4, 12], [28, 36], [55, 63]]
Log 'test toggle_case()'
AssertEqual str.toggle_case(' A b 123'), ' a B 123'
unlet str unlet str