0

I am trying to write command in Vim which can delete 9 and 11 symbols in third line. I did this 3s/9, 11/// but nothing happened as I expected it to be. It would be grateful to do this with your suggestions. To be more precise: I want to remove 9th symbol and 11th symbol in third line. For example I have three lines

  1. three metres above the sea
  2. three metres below the sea
  3. 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".

1
  • 1
    The command you wrote replaces the literal string 9, 11 on line 3. (Or it would without the extra / at the end.) It is not very clear what you are trying to achieve here. Pleas show some example input and desired output. Are you trying to delete the first 9 characters on line 3 or minimum 9 maximum 11 characters? If so based on what? Or do you want to remove the first or all occurrences of the strings "9" and "11"? Please update your question to be more precise.
    – Bram
    Nov 5, 2015 at 21:08

2 Answers 2

2

Matching multiple times is explained in section 27.4 Matching multiple times of chapter 27 of the user manual (see :help usr_27.txt).

The following command will delete the first 9, 10 or 11 characters of line 3 if the line contains at least 9 characters. If the line contains less characters it will return E486: Pattern not found:

:3s/.\{9,11}//

Not sure if that is what you want, if not update your question please.

0
0

In editing mode, type:

08lxl.
  • 0 move cursor to beginning of line
  • 8l move cursor forward 8 characters
  • x delete character under cursor
  • l move cursor forward 1 character
  • . repeat last command (x)

If you want to bind that to a key (e.g. ,):

:map , 08lxl.

every time you press , in edit mode after that, it will execute those commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .