Jack Evans
Jack Evans

Reputation: 25

Vim Join opened Html tags to same line

So I've started using snippets with vim, now sometimes I like the closing tag to be put on a newline but other times I like the closing tag to be on the same line.

After typing a html tag and pressing the autocomplete key it's formatted as shown below, with the cursor position shown by the caret symbol

<td>
    ^
</td>

Currently, if I want both tags on the same line I have to move the cursor up a line and repeatedly hit Shift+J to join the lines, but this takes multiple key strokes

Is there a fast way (without moving the cursor from it's current position), to join the two lines together to look like, from the above code snippet

<td>^</td>

Upvotes: 1

Views: 239

Answers (2)

pooroldpedro
pooroldpedro

Reputation: 311

or:

:.,/td>/j

meaning from the current line (.) to (,) search for "td>" (/td>/) join the lines (j)

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172758

You can utilize Vim's built-in inner tag text object to delete (dit) or change (cit) the whitespace / text inside the tags. (This assumes the tags are indented; without indent, you still need a J to join the end tag to the current line.)

Upvotes: 2

Related Questions