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.


A better way of swapping lines is to use


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

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

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.