fuser
fuser

Reputation: 293

Command for replace nth symbol in vim

I am trying to write command in Vim which can delete 9th and 11th symbols in third line. I did this 3s/.{9,11}// but it did not work. It would be grateful to do this with your suggestions. Here is an example. I have three lines

three metres above the sea

three metres below the sea

need some help in vim

So I want to delete 9th symbol in third line which is "e" letter in word "some" and 11th symbol which is letter "h" in word "help".

Upvotes: 1

Views: 1546

Answers (2)

Kent
Kent

Reputation: 195269

only for the 3rd line:

:3norm! 9|x10|x

or

:norm! 3G9|x10|x

Apply on whole buffer:

:%norm! 9|x10|x

Upvotes: 4

Brian Tiffin
Brian Tiffin

Reputation: 4126

Moved a comment to an answer

For Vim, many of the regex specials require backslash escapes. %c is the column match op. So

:3s/\%9c.//

will replace the "any character" at position 9 with nothing. You can also concatenate substitutions, but things will change between each expression. In this case, after deleting column 9, 11 (the 'h' in help) would actually be at position 10.

:3s/\%9c.//|s/\%10c.//

Upvotes: 3

Related Questions