I write code for a large company and often work with other developer's code. I personally don't choose to use all the language/formatting stuff in Vim, but I do like to quickly switch between using tabs and using spaces when I hit the &lt;TAB&gt; key (to integrate with the "current" file formatting).

+

I write code for a large company and often work with other developer's code. I personally don't choose to use all the language/formatting stuff in Vim, but I do like to quickly switch between using tabs and using spaces when I hit the Tab key (to integrate with the "current" file formatting).

−

Here is a snippit from my vimrc which enables my default settings (using 4 spaces for every &lt;TAB&gt;) and a mapping to &lt;F9&gt; to toggle the settings:

+

Here is a snippit from my vimrc which enables my default settings (using 4 spaces for every tab) and a mapping to <F9> to toggle the settings:

I write code for a large company and often work with other developer's code. I personally don't choose to use all the language/formatting stuff in Vim, but I do like to quickly switch between using tabs and using spaces when I hit the Tab key (to integrate with the "current" file formatting).

Here is a snippit from my vimrc which enables my default settings (using 4 spaces for every tab) and a mapping to <F9> to toggle the settings:

I like this function for the same reasons, however, I encountered an error with the implementation of it which required me to make a few minor changes. The expandtab and noexpandtab were giving me errors on the Unix hosts, so I had to add the keyword "set" in front of them in three places, as shown below:

" virtual tabstops using spaces
set shiftwidth=4
set softtabstop=4
set expandtab
" allow toggling between local and default mode
function TabToggle()
if &expandtab
set shiftwidth=8
set softtabstop=0
set noexpandtab
else
set shiftwidth=4
set softtabstop=4
set expandtab
endif
endfunction
nmap <F9> mz:execute TabToggle()<CR>'z

Grrr...that was just a mistake in my copying it into the Tip. My implementation has the "set" in front of them as well. Mea culpa!

Here is a small add_on that allows to easily change (once instead of 4 times) the local tab value.
And function is changed to function! to allow local tests (:w + :so %) .