Quickest Way to Revert Spaces to TABs in VIM
Only this configuration helped me solve this problem.
filetype plugin indent on
filetype detect
autocmd FileType make set noexpandtab
Just use the magical escape key available in insert mode.
On the *NIX's it is ^V by default when you are in insert mode. On Windows, you need to find out what the magical escape character is - ^V is taken for something else; I think it may be ^Q or ^S?
So! In your makefile:
this: this.c
<C-V><Tab>cc this.c
where the usual meanings apply:
means hit ctrl-V (you should see a ^ hiding away under the cursor) - hit the tab key. Bingo.
Works for me.
Note: if you use vim settings or startup code which smashes tabs as you read a file, this obviously is a short-term fix. I prefer to learn how to use the retab command to ensure a file is tab-clean, because I don't like a file to be touched unless I consciously choose to do so.
Just type set noexpandtab
. Perhaps you bind this to a function key.
VIM will automatically enable the TAB for a makefile, assuming you name it "makefile," as opposed to "Makefile." Not sure why VIM still doesn't detect the type with a lower-uppercase difference, but such is life. (@Sedrik)
That aside, other alternative solutions are:
Filetype Binding (@ThorstenS @tungd):
autocmd FileType make setlocal noexpandtab
RealTime Switch (@ThorstenS):
Assuming the .vimrc configuration mentioned in the question, do:
:set noet
(to switch from spaces to TAB)
and :set et
(to switch back)