Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm writing C code using vim and are searching for a possibility to right-align my comments so that they all end at col 80. To give a short example:

int a = 80; /* initialize a */
int b = 7; /* initialize b */
printf("%d + %d = %d", a, b, a+b); /*calculate the result */

should turn into

int a = 80;                               /* initialize a */
int b = 7;                                /* initialize b */
printf("%d + %d = %d", a, b, a+b); /*calculate the result */
                                                           ^col 80

I have installed vim-easy-align to do other formattings but did not find out yet how to perform this alignment. Maybe someone knows how?

I do not insist on vim-easy-align. If you have another plugin that does the job.. Just tell me ;).

share|improve this question

1 Answer 1

My AlignFromCursor plugin provides a <Leader>ri mapping and :RightAlignFromCursor command which do that. Just place the cursor in the whitespace before the comment (either manually or via a :[range]normal command) and invoke the mapping or command. It uses 'textwidth' or a prefixed [count].

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.