Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete backwards from cursor to the end of the previous line in Vim?

Tags:

vim

vi

Say I want to edit the following line:

var myVar = 
    "I am a string!";

So that it looks like this:

var myVar = "I am a string!";

Is there a movement that goes to the end of the previous line?

like image 764
DJ Madeira Avatar asked May 27 '15 20:05

DJ Madeira


People also ask

How do you undo backwards in Vim?

d<leftArrow> will delete current and left character. d$ will delete from current position to end of line. d^ will delete from current backward to first non-white-space character. d0 will delete from current backward to beginning of line.

How do we cut to the end of the line Vim?

Cutting (Deleting) dd - Delete (cut) the current line, including the newline character. 3dd - Delete (cut) three lines, starting from the line where the cursor is positioned, d$ - Delete (cut) everything from the cursor to the end of the line.


1 Answers

What you want is the line join command, J.

In normal mode, put your cursor anywhere on the var myVar = line and type J (capital j).

Direction-wise motions work with J - 5J indents 5 lines below the cursor, etc. You can also select a range of lines using visual mode (v to start visual mode selection) and join them all into one using J.

The &joinspaces option affects this behavior as well. When it's "on" (set joinspaces or set js) it adds two spaces after a sentence-ending mark (i.e. '.', '?', or '!') when joining lines. set nojoinspaces or set nojs to turn that off and insert only one space.

like image 122
amphetamachine Avatar answered Oct 25 '22 05:10

amphetamachine