In Vim, how can I delete everything between quotes including the quotes?

别说谁变了你拦得住时间么 提交于 2020-12-24 06:36:37

问题


For example, in the following:

Testing "deleting" within quotes

With the cursor inside of deleting, how can I delete the text within the quotes and include the quotes, leaving:

Testing within quotes

回答1:


You can use the following sequence:

da"

Keep in mind this only works on a single line, and will remove any trailing spaces after the last quote.

Edit

As pointed out by @James in the comments below, you can also use the di" sequence (delete inside) to delete the characters within the quotes without deleting the quotes.

You can also use this with ci" (change inside) to remove the characters and switch to insert mode, allowing you to easily replace text within quotes.




回答2:


We can use

da"

for your case or di" to delete ONLY the contents inside of ".

It is better to start with text-objects. Writing as an answer for completeness. Excerpt from :h text-objects, given below, suggest two forms i and a

This is a series of commands that can only be used while in Visual mode or after an operator. The commands that start with "a" select "a"n object including white space, the commands starting with "i" select an "inner" object without white space, or just the white space. Thus the "inner" commands always select less text than the "a" commands.

text-objects are useful to other character pair like (), {}, etc. For example, it is useful while changing

if ( i == true ) {
}

to

if (_) {
}

by using ci( or ci).




回答3:


Keep your cursor in first quotes and press d, then type /"/e It should delete the content between both double quotes as well as quotes. This is applicable for muliple lines as well.

Another way: Keep the cursor in first quotes and type df" It will also delete the text inside quotes and quotes too! Not applicable for multiple lines.

In both the ways, you execute commands in normal mode.



来源:https://stackoverflow.com/questions/36843099/in-vim-how-can-i-delete-everything-between-quotes-including-the-quotes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!