How to insert tab character when expandtab option is on in Vim

vim

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?

Best Answer

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>.