Vim: How to Delete Text Enclosed In Quotes
Instructions
Navigate to the first character after the quote/double-quote and type the following in Vim:
di"
This is useful if you have something like the following:
{ "title": "Vim: How to Delete Text Enclosed In Quotes", "permalink": "vim-how-to-delete-text-enclosed-in-quotes", "published": "2023-08-12 14:00", "categoryIDs": "5,5:0,5:1,5:5", "description": "In Vim, 'di\"' is the one to use for deleting text in quotes.", "thumbnail": "", "smallimage": "", "largeimage": "" }
So, to navigate to the first character that starts with a double-quote, simply type /"e;
and the insertion point will highlight the double-quote. To get to the next double-quote, press the
n
key again until you get to the one you want. After that, press
the l
key to move to the first character and type the following:
di"
The output will be as follows:
{ "title": "", "permalink": "vim-how-to-delete-text-enclosed-in-quotes", "published": "2023-08-12 14:00", "categoryIDs": "5,5:0,5:1,5:5", "description": "In Vim, 'di\"' is the one to use for deleting text in quotes.", "thumbnail": "", "smallimage": "", "largeimage": "" }
And now, you can type whatever you want by pressing the i
key on your keyboard.
Press the ESC (escape) key to get out of INSERT
mode and back into
normal mode. To save changes and quit the Vim text editor, type :wq
.
Bonus: If you have delimiters with quotes while writing the code such as:
"This is some \"quote\"!"
Vim will automatically delete the delimiters with quotes along with them, so performing
di"
will delete everything that is in between quotes.
""
And you do not need to be inside quotes in order to delete inside the quotes! How cool is that? *grinning face*
Oh, and you can also use the "change inside" sequence as well:
ci"This puts you into
INSERT
mode so you can type text inside quotes.
Audience
This is for Linux users experienced in using the Vim text editor. Vim users should already know
the basics such as :q!
for quitting the text editor without saving changes,
:wq
for saving changes and quitting the text editor, i
for going into
INSERT
mode and use the ESC (escape) key to get back into normal
mode. All keyboard commands are beyond the scope of this short article that I wrote.
Conclusion
Hopefully this keyboard command can be of help to you. If you are a Linux user, please give Vim a try.
Original Source
In Vim, how can I delete everything between quotes including the quotes?
Note that I was searching for information about deleting text inside quotes and not including the quotes.
Article published: 2023-08-12 14:00
Categories: The World of Computers, Computers, Information Technology, Scripting and Programming,