m (Join Up moved to Move comment line to end of next line: Page moved by JohnBot to improve title) |
(general and comment cleanup) |
||
Line 9: | Line 9: | ||
|rating=0/9 |
|rating=0/9 |
||
|text= |
|text= |
||
⚫ | |||
+ | |||
Let's say you have some C or Java that looks like this: |
Let's say you have some C or Java that looks like this: |
||
+ | <pre> |
||
− | |||
− | |||
// get the age of the person |
// get the age of the person |
||
− | |||
age = person.getAge(); |
age = person.getAge(); |
||
+ | </pre> |
||
− | |||
− | |||
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": |
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": |
||
+ | <pre> |
||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
− | <map> <CS-j> ddpkJk |
||
⚫ | |||
− | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
⚫ | |||
== Comments == |
== Comments == |
||
− | Good idea but why do ddp ? That's deleting a line and pasting it back :). |
||
− | <map> <CS-j> kJj would suffice. The last j will leave the cursor just below the joined line. |
||
− | |||
− | anishmuttreja--AT--gmail.com |
||
− | , November 17, 2005 10:54 |
||
− | ---- |
||
⚫ | |||
− | It seems ddp is also a good tip for quick adjacent line swapping. |
||
− | |||
− | '''Anonymous''' |
||
− | , November 17, 2005 11:46 |
||
− | ---- |
||
− | yup, ddp is for the line swap. |
||
− | |||
− | btw, the <CS-j> mapping for Control-Shift-J works on my Windows machine, but I just tried it on Linux and it's not working. Any ideas? |
||
− | |||
− | matahijau |
||
− | , November 17, 2005 13:53 |
||
− | ---- |
||
− | It should be <C-S-j> |
||
− | |||
− | '''Anonymous''' |
||
− | , November 18, 2005 12:20 |
||
− | ---- |
||
− | The mapping is somewhat unintuitive for me. In comparision to the "J" command |
||
− | |||
⚫ | |||
− | |||
− | Which means you are at the line where you want to append another line (in this case the above one). |
||
− | |||
− | '''Anonymous''' |
||
− | , November 22, 2005 5:06 |
||
− | ---- |
||
A better way of swapping lines is to use |
A better way of swapping lines is to use |
||
:m+ |
:m+ |
||
Line 79: | Line 42: | ||
, November 27, 2005 16:50 |
, November 27, 2005 16:50 |
||
---- |
---- |
||
− | Thanks Gerald, I like the refined version. |
||
− | |||
− | matahijau |
||
− | , November 30, 2005 7:58 |
||
− | ---- |
||
− | Sorry, I can't resist saying something... |
||
− | |||
− | I know it's useful and often tempting to combine code and comments onto one line, but seeing a macro for it suggests it will happen very frequently. |
||
− | |||
− | When two separate things (namely, code and comments) are on the same line, your source diffs start to lose meaning. What changed between two versions of a file? The code or the comment? There's also a tendency to include longer comments, so you end up with things like below, which are a mess when you want to modify the comment. |
||
− | |||
− | count++; // increment counter by 1 |
||
− | // because it's important |
||
− | // and we should increment it here |
||
− | |||
− | Here's a nice write-up by the late, great Jef Raskin: [http://acmqueue.com/modules.php?name=Content&pa=printer_friendly&pid=290&page=1 http://acmqueue.com/modules.php?name=Content&pa=printer_friendly&pid=290&page=1] |
||
− | |||
− | Just my 2 cents... |
||
− | |||
− | '''Anonymous''' |
||
− | , May 2, 2006 19:56 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.612354 seconds--> |
Revision as of 21:01, 30 October 2007
Tip: #1050 - Move comment line to end of next line
Created: November 17, 2005 7:04 Complexity: basic Author: matahijau Version: 5.7 Karma: 0/9 Imported from: Tip#1050
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.
Comments
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
Gerald Lai , November 27, 2005 16:50