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

前端 未结 8 1218
遥遥无期
遥遥无期 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:33

    Control-V is used for block select. That would let you select things in the same character column.

    It seems like you want to remove the quotes around the numbers. For that use,

    :%s/"\([0-9]*\)"/\1/g
    

    Here is a list of what patterns you can do with vim.


    There is one more (sort of ugly) form that will restrict to 4 replacements per line.

    :%s/^\( *\)"\([ 0-9]*\)"\([ 0-9]*\)"\([ 0-9]*\)"/\1\2\3\4/g
    

    And, if you have sed handy, you can try these from the shell too.

    head -4 filename.txt | sed 's/pattern/replacement/g'
    

    that will try your command on the first 4 lines of the file.

提交回复
热议问题