-1

Is it possible to have a 'smart tab' working as follows: 'move forward to the columns corresponding to the beginnings of the words in the line above'

For example, in the situation below:

enter image description here

I would like a 'smart tab' that, pressed once would move to the column below the '=' sign, and pressed twice would move to the column below the 'b' in 'basepoint' in the line above.

Currently I do this by pressing the regular 'tab' and pressing the space bar as required, but I was wondering if there was a more efficient way, especially as the programming language I am using requires me to save tabs as spaces.

1
  • If you have tabs around the = sign, that's what should happen. The softtabstop option being responsible for the 'length' of a tab, so you only can only align with tabs on columns which are a multiple of softtabstop value. I hope it makes sense.
    – Biggybi
    Oct 31, 2020 at 10:50

1 Answer 1

1

Although that's not the answer to your question, it might be interesting to have a look into the plugins vim-lion or tabular. Both of them allow you to reformat the text so that you align it according to specific characters, e.g. =, and both of them are written only in vimscript.

Example of usage vim-lion:

some header = test
  a = 42
  morethana = 43
  somethingelse = 17

if you now put your cursor in the line a = 42 and press gl)=, the output will change to

some header = asdf
  a             = 42
  morethana     = 43
  somethingelse = 17

The )-part is composable, so that you could also use ip to change it to the whole paragraph regardless on where your cursor is positioned.

Similarly, you could use tabular by visually selecting the desired lines and write :Tabularize /= to align all the =. If you don't select anything, the alignment will be used for the overall paragraph. Although this is a more verbose way to do it compared to the vim-lion-way, you can also align by character-combinations (e.g. <- as used in GNU R).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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