Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove the first character in N lines in vim?

Tags:

vim

When I paste into vim I often get a # character at the start of each line I've pasted.

Is there an easy way I can remove the first char on N lines (without regex)?

Thanks!

like image 809
Alistair Colling Avatar asked Sep 02 '15 16:09

Alistair Colling


People also ask

How do I delete all lines starting with vi?

To remove all lines containing a particular string in the vi or Vim text editors, you can use the g command to globally search for the specified string and then, by putting a "d" at the end of the command line, specify that you want all lines containing the specified string deleted.

How do I delete 10 lines in vi?

To delete a line in Vi or Vim, switch to normal mode first. If you're into command mode or insert mode, you can switch back to normal mode by pressing Escape. Highlight the line that you want to delete, then hit dd or D on the keyboard. The editor will automatically remove the whole line from the file.


1 Answers

Go to the first occurrence of # in the pasted text.

Enter blockwise visual mode.

ctrl-V 

Select first character in each line pasted.

<count>j

where count = N - 1

Delete the selected text.

x

Btw, your concern should have been to avoid getting # altogether when you paste. The solution to which is :set paste

like image 113
Sagar Jain Avatar answered Jan 01 '23 00:01

Sagar Jain