Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you enable file specific tab indent settings in VIM?

I believe there is a method to write a comment in a file that vim will use to override default tabbing and indent values.

Can someone point me to information about this feature and how to use it?

like image 381
cmcginty Avatar asked Apr 30 '10 02:04

cmcginty


People also ask

How do I enable tabs in Vim?

vimrc provides for a very convenient way to move between tabs. When in insert mode, press [Esc] to get to command mode, then use [Ctrl]+T plus a directional arrow to go to the tab you want: up to go to the first tab, down to the last, and left or right to go to the previous or next tab.

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 you set a tab to indent to 4 spaces in Vim?

As for tabs, there are two settings. 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.


1 Answers

Per-file settings can be done using "modeline magic".

The basic idea is that you can add a comment to an individual file like this:

/* vim: set tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab */ 

Within vim, you should review:

  • :help auto-setting
  • :help modeline
  • :help modelines
like image 72
Tim Henigan Avatar answered Sep 26 '22 03:09

Tim Henigan