How to use only tab (not space) in vim

I prefer to use tab than white space (may be slightly different from most others)

But I found that when I hit Enter at the end of the line, it will add some white spaces , but not a tab . So I have to delete them and click the tab .

I want to know how to install vim as:

  • use only tab for line indentation
  • the tab looks like 4-spaces, but actually it is a tab
  • when you hit Enter at the end of a line, a new line starts only with tabs

I searched for this for a while, but did not find a good answer. Thank you in advance




UPDATE

@Alok's answer has proven itself in most cases. But I just found, sometimes it depends on the type of file. For example, if you are editing a haml file and there is vimfiles/indent/ in vimfiles/indent/ , then all tabs will be converted to space . Therefore, if you want it to be a tab , you should modify (or delete) the corresponding indent file.

+46
vim indentation
Sep 10 '10 at 6:13
source share
1 answer

Settings you are looking for:

 set autoindent set noexpandtab set tabstop=4 set shiftwidth=4 

As a separate line:

 set autoindent noexpandtab tabstop=4 shiftwidth=4 

autoindent can be replaced with smartindent or cindent , depending on your tastes. Also see filetype plugin indent on .

http://vim.wikia.com/wiki/Indenting_source_code

+58
Sep 10 '10 at 6:18
source share



All Articles