Created
January 24, 2019 10:11
-
-
Save jerdna-regeiz/daf5f420f45d71d3665d767761f7a03f to your computer and use it in GitHub Desktop.
vim-surround toggling quotes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Toggle_Surround(char) | |
let pos = getcurpos() | |
let cur = col(".") | |
exe "norm! va".a:char | |
let start = col("v") | |
let end = col(".") | |
exe "norm! \<esc>" | |
call cursor(pos[1], pos[2]) | |
if start <= cur && cur <= end && start != end | |
" inside quote :) | |
exe "norm ds".a:char | |
call cursor(pos[1], pos[2]-len(a:char)) | |
else | |
" not inside a quote | |
" hapens when cur <= start or end <= cur_sol or cur == start == end | |
exe "norm ysiw".a:char | |
call cursor(pos[1], pos[2]+len(a:char)) | |
endif | |
endfunction | |
nmap <silent> "" :call Toggle_Surround('"')<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment