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 just Vim.
surround.vim is going to be your easiest answer. If you are truly set against using it, here are some examples for what you can do. Not necessarily the most efficient, but that's why surround.vim was written.
ciw'Ctrl+r"'
ciw
- Delete the word the cursor is on, and end up in insert mode.'
- add the first quote.Ctrl+r"
- Insert the contents of the "
register, aka the last yank/delete.'
- add the closing quote.
di'hPl2x
di'
- Delete the word enclosed by single quotes.hP
- Move the cursor left one place (on top of the opening quote) and put the just deleted text before the quote.l
- Move the cursor right one place (on top of the opening quote).2x
- Delete the two quotes.
va':s/\%V'\%V/"/g
va'
- Visually select the quoted word and the quotes.:s/
- Start a replacement.\%V'\%V
- Only match single quotes that are within the visually selected region./"/g
- Replace them all with double quotes.