Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
656 views
in Technique[技术] by (71.8m points)

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

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

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

I want to be able to remove the quotes surrounding the first two columns. What is the best way to do this with Vim (I'm currently using gVim)?

I figured out how to at least delete the beginning quote of each line by using visual mode and then enter the command '<,'>s!^"!!

I'm wondering if there is a way to select an entire column of text (one character going straight down the file... or more than 1, but in this case I would only want one). If it is possible, then would you be able to apply the x command (delete the character) to the entire column.

There could be better ways to do it. I'm looking for any suggestions.


Update

Just and FYI, I combined a couple of the suggestions. My _vimrc file now has the following line in it:

let @q=':%s/"([0-9]*)"/1/g^M'   

(Note: THE ^M is CTRLQ + Enter to emulate pressing the Enter key after running the command)

Now I can use a macro via @q to remove all of the quotes from both number columns in the file.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

use visual block commands:

  • start mode with Ctrl-v
  • specify a motion, e.g. G (to the end of the file), or use up / down keys
  • for the selected block specify an action, e.g. 'd' for delete

For more see :h visual-mode


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...