Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change enclosing quotes in Vim

In Vim, it's a quick 3-character command to change what's inside the current quoted string (e.g., ci"), but is there a simple way to change what type of quotes are currently surrounding the cursor?

Sometimes I need to go from "blah" to """blah""" or "blah" to 'blah' (in Python source code) and I'd ideally like to do it quickly using default key bindings.

like image 390
Mzzzzzz Avatar asked Sep 10 '10 18:09

Mzzzzzz


2 Answers

Try the surround.vim plugin. I find it an essential addition to any vim installation.

like image 98
Jay Avatar answered Nov 20 '22 05:11

Jay


Surround.vim is great, but I don't think it'll handle your triple-quoted needs directly.

The way I've done stuff along these lines (when surround wasn't appropriate) was to use %, make the change, then double-backtick to go back to the starting point. E.g. if the cursor is somewhere in a single-quoted string, do f'%, make the change, then double-backtick and ..

like image 2
dash-tom-bang Avatar answered Nov 20 '22 06:11

dash-tom-bang