Skip to content

Instantly share code, notes, and snippets.

@jerdna-regeiz
Created January 24, 2019 10:11
Show Gist options
  • Save jerdna-regeiz/daf5f420f45d71d3665d767761f7a03f to your computer and use it in GitHub Desktop.
Save jerdna-regeiz/daf5f420f45d71d3665d767761f7a03f to your computer and use it in GitHub Desktop.
vim-surround toggling quotes
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