When I'm in insert mode and I have the expandtab
option switched on, pressing Tab ↹ results in inserting the configured number of spaces.
But occasionally I want to insert an actual tab character.
Do you know how to do this?
While in insert mode or command mode (the : prompt at the bottom of the editor), type CTRL + V then TAB . Using CTRL + V signals Vim that it should take the next character literally. Even in insert mode.
Use tab key to switch windows and current file path.
Smart tabs plugin or the newer vim-stabs plugin (which stands for smarter-tabs). The plugin ensures that tabs are only used for indentation, while spaces are used everywhere else.
You can use <CTRL-V><Tab>
in "insert mode". In insert mode, <CTRL-V>
inserts a literal copy of your next character.
If you need to do this often, @Dee`Kej suggested (in the comments) setting Shift+Tab to insert a real tab with this mapping:
:inoremap <S-Tab> <C-V><Tab>
Also, as noted by @feedbackloop, on Windows you may need to press <CTRL-Q>
rather than <CTRL-V>
.
You can disable expandtab option from within Vim as below:
:set expandtab!
or
:set noet
PS: And set it back when you are done with inserting tab, with "set expandtab" or "set et"
PS: If you have tab set equivalent to 4 spaces in .vimrc (softtabstop), you may also like to set it to 8 spaces in order to be able to insert a tab by pressing tab key once instead of twice (set softtabstop=8).
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