Fandom

Vim Tips Wiki

Move comment line to end of next line

Redirected from VimTip1050

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 1050 Printable Monobook Previous Next

created 2005 · complexity basic · author matahijau · version 5.7


Let's say you have some C or Java that looks like this:

// get the age of the person
age = person.getAge();

If you want to compact your code a bit you might want to stick the comment at the end of the statement instead of on its own line. Essentially you want to "join up":

map <C-S-j> kddpkJ

Used on the example above by placing the cursor on the second line and typing ctrl-shift-j, you will now have:

age = person.getAge(); // get the age of the person

ddp is used to swap the lines before joining, so the comment line is at the end of the newly joined line.

CommentsEdit

A better way of swapping lines is to use

:m+
:m-2

Hence, modifying "map <C-S-j> kddpkJ" and maintaining cursor position:

nmap <C-S-j> mz:m-2<CR>J`z

Also on Fandom

Random Wiki