Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting specific column tab stops in Vim

I am reasonably familiar with Vim's option for tabstop, softtabstop, shiftwidth, expandtabs, etc.

However, I'm wondering if there is a way in Vim to set specific column tab stops.

I need tab stops in the following columns: 7, 11, 14, 17, ... every 3 after that.

Thanks in advance.`

like image 925
DuncanKinnear Avatar asked Nov 03 '11 01:11

DuncanKinnear


People also ask

How do I set a tab stop in Vim?

All the above works for new files. To convert tabs to spaces in the currently opened file in Vim, enter the Normal mode by pressing Esc key. Now use the retab command by pressing the ':' (colon) character and Vim will convert the existing tabs to spaces.

How do I set tab to 4 spaces in vi?

Within Vim, type a colon and then "set tabstop=4" which will set the tabs to display as four spaces. Hit colon again and type "set expandtab" which will insert spaces for tabs.

How do I set an indent in Vim?

To indent the current line, or a visual block: ctrl-t, ctrl-d - indent current line forward, backwards (insert mode) visual > or < - indent block by sw (repeat with . ) then try hitting the F5 key while in insert mode (or just :set paste ).

How do I change tabs in Vim?

To directly move to first tab or last tab, you can enter the following in command mode: :tabfirst or :tablast for first or last tab respectively. To move back and forth : :tabn for next tab and :tabp for previous tab. You can list all the open tabs using : :tabs. To open multiple files in tabs: $ vim -p source.


1 Answers

I found this thread http://vim.1045645.n5.nabble.com/Arbitrary-tab-stops-td1211888.html. Seems like that feature exists for a while as a patch.

+                       *'vartabstop'* *'vts'*
+ 'vartabstop' 'vts'    string  (default 8)
+           local to buffer
+           {only available when compiled with the |+vartabs|
+           feature}
+           {not in Vi}
+   A list of the number of spaces that a  in the file counts for,
+   separated by commas.  Each value corresponds to one tab, with the
+   final value applying to all subsequent tabs. For example: 
+       :set vartabstop=4,20,10,8
+   This will make the first tab 4 spaces wide, the second 20 spaces,
+   the third 10 spaces, and all following tabs 8 spaces.
+ 
+   Note that the value of |'tabstop'| will be ignored while 'vartabstop'
+   is set.
+ 
like image 75
yosukesabai Avatar answered Oct 05 '22 23:10

yosukesabai