I have set expandtab
in my .vimrc
file to convert tab
to multiple space
characters. However some files (like Makefile) need actual the tab
character inserted.
Is there an easy way to force the insertion the tab
while I am typing?
Instead of just pressing Tab, first press Ctrl-V and then press Tab.
This can be used to insert a variety of special chars. See :help i_CTRL-V
for details.
Ctrl-V also works in command-line mode (:help c-CTRL-V
), and even in some other programs entirely. (e.g. bash, mutt.)
If you have Ctrl-V mapped to something else, try Ctrl-Q. This has the same effect in Vim as Ctrl-V, but some terminals use it for control flow, in which case Vim won't ever see it.
<c-v>009
in case of broken Tab key or hardcore ASCII purist :-)
Commented
Feb 11, 2015 at 15:38
Rather than change your behavior (which is error prone).
I would set up vim to behave differently for this file type.
So in my normal editing I expand tabs. But specifically for make
files I set the noexpandtab
so that tabs are retained.
Add the following to your ~/.vimrc file:
" Normal action
set expandtab
if has("autocmd")
" If the filetype is Makefile then we need to use tabs
" So do not expand tabs into space.
autocmd FileType make set noexpandtab
endif