I'm trying to set up some basic configuration for vim to make it more useful for myself. One of the things I'm trying to do is map shift+tab to a literal tab character, since my vim configuration sets tabs to be expanded with spaces by default. I attempted to map to the tab char using this reference but no dice.

When I try to strike shift+tab whilst insert mode is active, vim outputs a capital Z for about one second, then removes it and drops out of insert mode with a system error beep. I already tested the shift+tab stroke with ^V and it output ^[[Z into vim as described in the reference, so it's not my OS hijacking the keystroke. Not exactly sure what's causing this; input would be appreciated.

My .vimrc:

" Few basic settings first; I like syntax highlighting & line numbers
syntax on
set number

" Some settings with the list option
" I like to see non-printing characters like Tab & CR
set listchars=tab:▸\ ,eol:¬
set list

" Set tab behaviours: 4 spaces wide, expand <Tab> and >> with spaces
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
" This line maps shift+tab to a literal tab character
" Because I sometimes need a literal tab
set <s-tab>=    

The very last line shows the ▸ character in vim when set list is on

1 Answer 1


Try this:

:set t_kB=^[[Z

You don't type the ^[ characters literally; to get the actual escape sequence press control-v then press the escape key. Note that the t_kB option is the same as the <S-Tab> option.

However, this does not map <S-Tab> to <Tab>, it only tells Vim what escape sequence your terminal sends when you press those two keys. But at this point you can map <S-Tab> to <Tab>:

:noremap <S-Tab> <Tab>

To make Vim insert a literal tab character when an option like 'expandtab' is set:

:inoremap <S-Tab> <C-V><Tab>
  • Just tried it and it still didn't work. :( shift+tab expanded into four spaces instead. Jun 15, 2014 at 0:35
  • For the noremap command, did you type it exactly as it appears? Because you're meant to. Also, what's output of ":verbose set expandtab?", with the question mark as part of the command.
    – Heptite
    Jun 15, 2014 at 1:51
  • Also, are you trying to insert a tab into the file, or are you trying to change <S-Tab> to behave like <Tab> in Vim. The answer matters. If the latter, change :noremap to just :map.
    – Heptite
    Jun 15, 2014 at 2:02
  • I'm trying to change <S-Tab> so that it inserts a literal tab character into the file. <Tab> behaves as expected and indents the text with spaces. Jun 15, 2014 at 2:26
  • Sorry it took me a while to understand what you needed. Yeah, you probably still need to set t_tB, but the mapping you need is: :inoremap <S-Tab> <C-V><Tab>
    – Heptite
    Jun 15, 2014 at 23:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .