Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding allign to comments #18

Closed
petermlm opened this issue Oct 30, 2013 · 3 comments
Closed

Adding allign to comments #18

petermlm opened this issue Oct 30, 2013 · 3 comments
Labels

Comments

@petermlm
Copy link

I was wondering if the plugin could be extended by adding alignment to comments. Like in the following python code:

var1 = 10 # This is a variable
var2 = 1000 # This is another variable

Which would produce:

var1 = 10   # This is a variable
var2 = 1000 # This is another variable

Also, for comment using /**/. Like

/*
* This is a comentary
*/

Which would became

/*
 * This is a comentary
 */
@junegunn
Copy link
Owner

Both cases are possible.

For the first case, <Enter>-<Space> will do the trick. Spaces in the comments are ignored, so it matches the spaces just before #. The detailed explanation can be found here: https://github.com/junegunn/vim-easy-align/blob/master/EXAMPLES.md#aligning-in-line-comments

The second one is a little tricky, you have to understand some alignment options. Without a custom alignment rule, it can be done with the following command:

EasyAlign/*/\?/l0r0ig[]dl

  • */\? Using regular expression:
  • l0 Left margin: 0
  • r0 Right margin: 0
  • ig[] Do not ignore delimiters in strings or comments
  • dl Delimiters are aligned to the left

Longer form may be easier to read:

EasyAlign /*/\?/ { 'left_margin': 0, 'right_margin': 0, 'ignore_groups': [], 'delimiter_align': 'l' }

This can be also done in interactive mode

  • <Enter> Start interactive mode
  • <Down> Set margins to zero
  • <CTRL-G> Empty ignore_groups option
  • <CTRL-D> Set delimiter_align option to left
  • <CTRL-X> and input regular expression

If you do this often, you might want to a define custom alignment rule as follows:

let g:easy_align_delimiters = {
\ '/': { 'pattern': '*/\?', 'ignore_groups': [], 'delimiter_align': 'l', 'left_margin': 0, 'right_margin': 0 }
\ }

Then you can do it with a single keystroke: /

Does this answer your question?

@petermlm
Copy link
Author

Yes. Yes it does. Thank you very much!

@junegunn
Copy link
Owner

Good to hear that. Feel free to ask me if you have any question. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants