Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can vim be made to only expand tabs to the left of text?

Using vim, I would like to effectively have expandtabs off if I'm to the left of any text on the line and on if I'm to the right of any non-whitespace character. (I would like to use tabs for indentation and spaces for alignment.)

Can this be done?

like image 917
chaos Avatar asked Jul 20 '09 01:07

chaos


1 Answers

Yes. Use the Smart Tabs plugin.

This script allows you to use your normal tab settings for the beginning of the line, and have tabs expanded as spaces anywhere else. This effectively distinguishes 'indent' from 'alignment'.

<tab> Uses editor tab settings to insert a tab at the beginning of the line (before the first non-space character), and inserts spaces otherwise.

<BS> Uses editor tab settings to delete tabs or 'expanded' tabs ala smarttab

To make Vim line up function arguments, add

set cindent
set cinoptions=(0,u0,U0

to .vimrc. The plugin will encode the whitespace as such:

int f(int x,
......int y) {
--->return g(x,
--->.........y);
}

This makes the alignment of "x" and "y" independent of the tab size (tabstop).

like image 99
Marius Andersen Avatar answered Sep 30 '22 03:09

Marius Andersen