Toerndev
Toerndev

Reputation: 727

Vim: Appending line from first word, to previous line

This should be too simple, but I have wanted to know for a long time and haven't seen this question, it's hard to search for.

I often want to delete from somewhere in a line to the beginning of the code on next line. For instance, in C-ish syntax, let's say I want to remove the first boolean in:

if (long_boolean_expression1 &&
    long_boolean_expression2) {
  /* code */
}

and get:

if (long_boolean_expression2) {
  /* code */
}

Here I can do 0wdb. from the second line. (Is there anything shorter or more intuitive? There must be a single command that does 0w but I can't find it.)

When editing HTML though, nothing seems to work. Whenever I need to do something like turning this:

<table>
  <tr>

into this:

<table><tr>

I end up doing it with backspace in insert mode, because all my attempts to do it in normal mode fail, often deleting too much and leaving me with:

<table<tr>  <!-- Fail! -->

How do I do this?

Upvotes: 1

Views: 2661

Answers (2)

jeffszusz
jeffszusz

Reputation: 435

Try putting your cursor on the l and typing DJ.

D is to delete until the end of line from cursor, J is to join next line to current one.

For your HTML example, just try J on the first line to join the second line to it.

Upvotes: 9

jahroy
jahroy

Reputation: 22692

SHIFT+J joins two lines together.

Upvotes: 5

Related Questions