0

I have a text file with many statements like: "1", "23",..... etc and I want to replace these occurrences with 1, 23,.... etc. That is just removing the quotes. How can I do this in VIM?

1
  • you should maybe run vimtutor. Commented Oct 11, 2011 at 9:25

3 Answers 3

4

Use :

:%s/"\(\d\+\)"/\1/g

Which means: replace any sequence of digits between double quotes with the sequence of digits itself.

For more reference:

:help :s
:help pattern
Sign up to request clarification or add additional context in comments.

1 Comment

Useful example of search command, but IMHO simple s/"//g do "just removing the quotes" as requested in the question
2

You type esc then:

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

This will substitute the pattern: " any digits " by any digits. Note that \1 will replicate what has been matched within these: \( \)

1 Comment

This will also delete any pair of successive double-quotes with no digits inside.
0

You can do it like this -

:%s/"\(\d\+\)"/\1/c

1 Comment

/c will ask for confirmation, and only once per line. You at least want to add the g flag also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.