1

I would like to add a # to the beginning of the 15 next lines (to comment everything).
I know how to do it for 1 line : i -> #.
My second question would be the opposite, how to delete the first character of the 15 next lines ?
at the moment, i'm doing r1l (remove 1 letter) for each line.

How can I achieve this ?

1
  • 2
    Please try to ask only one question at a time even if the question are related
    – Kiwy
    Feb 10, 2015 at 11:37

2 Answers 2

2

To add the character press the following keystrokes:

  • ctrl-v
  • down arrow (15 times or 15G to go to line number 15 directly)
  • I (Capital letter)
  • #
  • esc

To delete the character press the following keystrokes:

  • ctrl-v
  • down arrow (15 times or 15G to go to line number 15 directly)
  • x

Please pay attention to lower and capital letters. They are important in vim.

3
  • Your answer to delete the first character us working great ! But the answer to add a character to each line is not working :( Feb 10, 2015 at 11:22
  • I edited the answer. Check it once more.
    – ztik
    Feb 10, 2015 at 11:26
  • My bad, I didnt press esc and # only appearded on the first line. Thanks a lot :) Feb 10, 2015 at 11:27
2

You can also use search and replace and add a range to it:

:.,15s/^/#/

To undo just:

:.,15s/^#//

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.