How to remove quotes surrounding the first two columns in Vim?

前端 未结 8 1099
遥遥无期
遥遥无期 2020-12-15 21:53

Say I have the following style of lines in a text file:

\"12\" \"34\" \"some text     \"
\"56\" \"78\" \"some more text\"
.
.
.
etc.

I want

8条回答
  •  有刺的猬
    2020-12-15 22:40

    Although this case was pretty simple to fix with a regex, if you want to do something even a bit more advanced I also recommend recording a macro like Bryan Ward. Also macros come easier to me than remembering which characters need to be escaped in vim's regexes. And macros are nice because you can see your changes take place immediately and work on your line transformation in smaller bits at a time.

    So in your case you would have pressed qw to start recording a macro in register w (you can of course use any letter you want). I usually start my macros with a ^ to move to the start of the line so the macro doesn't rely on the location of the cursor. Then you could do a f" to jump to the first ", x to delete it, f" to jump to the next " and x to delete that too. Then q to finish recording.

    Instead of making your macro end on the next line I actually as late as today figured out you can just V (visually line select) all lines you want to apply your macro to and execute :normal @w which applies your macro in register w to each visually selected line.

提交回复
热议问题