Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select entire line in VIM, without the new line character

Tags:

vim

Which is the shortest way to select an entire line without the new line character in VIM?

I know that SHIFT + v selects the entire line, but with new line character.


To do this I go to the line and I press:

  • ^ (puts the cursor at the start of the line)
  • v (starts the visual select)
  • $ (selects the entire line including new line character)
  • Left (unselects the new line character)

I also know that I can create a recording that does such a thing. But I am asking if is there any built-in shortcuts...

like image 585
Ionică Bizău Avatar asked Nov 23 '13 17:11

Ionică Bizău


People also ask

How do I highlight an entire line in vim?

If you want to select the entire line in a file, press V. Now when you press k or j to go up and down, vim will select the entire line above and below your cursor.

Why does vim add a newline?

A sequence of zero or more non- <newline> characters plus a terminating <newline> character. And, therefore, they all need to end with a newline character. That's why Vim always adds a newline by default (because, according to POSIX, it should always be there). It is not the only editor doing that.

What is new line character in vim?

Use \r instead of \n . Substituting by \n inserts a null character into the text. To get a newline, use \r . When searching for a newline, you'd still use \n , however.

How do I move text to the next line in vim?

I know that pressing 'o' in normal or visual mode moves the cursor to a new line and switches the mode to insert.


1 Answers

Yes, g_ is what you are looking for. g_ is like $, but without the newline character at the end.

Use 0vg_ or ^vg_, depending if you want to copy from the beginning of the line, or the first character on the line, respectively.

like image 197
jerzy Avatar answered Sep 22 '22 06:09

jerzy