0

I'm not sure the right words to use to express what I want, which is why I'm probably having trouble finding it myself. I have a css-like file:

attr_of_super_long_length: value1,
shorter_attr: value2,
medium_length_attr: value3

I want to be able to put my cursor over the v in value1 and copy its x coordinate, and then go to the v in value2 and push it to the same indented x coordinate in 1 keystroke (eg, not highlight and > <). Any ideas? Thanks!

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
pachun
  • 926
  • 2
  • 10
  • 26

2 Answers2

1

There are some great plugins for alignment like Align and tabular. I used Align for a while, but I've moved to tabular because I like this functionality for making tables. In tabular you could accomplish this by visually selecting these values and then doing the command :Tab /:\zs using standard vim regex (see :help pattern). As Tom Whittock mentioned, this question has already been asked and solved here.

Community
  • 1
  • 1
Conner
  • 30,144
  • 8
  • 52
  • 73
0

You basically want to left-align to a particular column, but not the entire line (like :left does), but only the text to the right of the cursor.

Fortunately, I have written a plugin for that, and I published it right now: AlignFromCursor

With the cursor on the v of value2 in your example, you press 28<Leader>le or issue :LeftAlignFromCursor 28, and it'll result in this:

attr_of_super_long_length: value1,
shorter_attr:              value2,
medium_length_attr: value3

For value3, you can simply repeat with .

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324