How can I quickly quote/unquote words and change quoting (e.g. from \'
to \"
) in Vim? I know about the surround.vim plugin, but I would like to use
For users of VSCodeVim you can do
vwS"
"
with whatever you would like to wrap by.w
with any other selection operatorVisual mode map example to add single quotes around a selected block of text:
:vnoremap qq <Esc>`>a'<Esc>`<i'<Esc>
I don't know any builtin vim command for this, but using r"f'r"
to change from ' to " and r'f"r'
to change from " to ' works if you stand on the first ' or ". The command r'
replaces whatever character is under your cursor with ', and f"
moves you forward to the next ".
In addition to the other commands, this will enclose all words in a line in double quotes (as per your comment)
:s/\(\S\+\)/"\1"/
or if you want to reduce the number of backslashes, you can put a \v
(very-magic) modifier at the start of the pattern
:s/\v(\S+)/"\1"/