Is there any way to make vim handle tab
pressing by the next two ways?
Result of usage should looks as follows (--->
it's tabs, _
it's spaces)
foo() {
--->int_a_____=_2;
--->int_count_=_12;
}
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. You can put these settings in a . vimrc (or _vimrc on Windows) in your home directory, so you only have to type them once.
A quick way to visualize whether there is a Tab character is by searching for it using Vim's search-commands : In NORMAL mode, type /\t and hit <Enter> . It will search for the Tab character ( \t ) and highlight the results.
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 ).
With both configurations in place, Vim will be using spaces anytime you hit <Tab> so, if you need to insert a real Tab character you may: On INSERT mode press <Ctrl> + v + <Tab> .
There is the Smart Tabs plugin. I don't use it, but it looks like it does what you want.
Edit: Actually, I have written my own implementation of this, because I wanted some additional features (like still use Tabs after a comment prefix), and needed it to integrate with my own variant of the SuperTab plugin, which also overrides the key. I've just uploaded my IndentTab plugin, so that you have a choice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With