StrugglingProgrammer
StrugglingProgrammer

Reputation: 758

vimrc key remap seems to not work, but works in :Ex mode

In my vimrc, I have the following:

imap <S-Tab> <Esc><<i 

This will unindent by 1 tabs-length Shift+Tab in insert mode. Shift-Tab acts as if it is just a Tab when I have this in my vimrc though. However, if I run the following in :Ex mode:

:imap <S-Tab> <Esc><<i 

The remapping works properly. Does anyone know what might be causing the problem? There is no other remapping of in the vimrc. I ran

strace -o vim_strace vim

to verify that the correct vimrc is being sourced and no other strange vimrc's are being sourced.

Interestingly, I have the same exact vimrc on my local machine, and it works properly. That is, this problem is only occurring on a remote machine I am ssh'd into.

Does anyone have any ideas that might help solve this annoying problem?

Upvotes: 0

Views: 108

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172570

Maybe the mapping is overridden.

:verbose imap <S-Tab>

will tell you.

It may also be that <S-Tab> isn't properly handled in the terminal, and Vim just receives a plain <Tab>. You can check by entering <C-V><S-Tab> in insert mode, and check what gets inserted.

Upvotes: 1

Peter Rincker
Peter Rincker

Reputation: 45117

You don't even need the mapping because you can use a built in command <c-d> in insert mode. Think of it as decrease indent. See :h i_ctrl_d for more information.

If you wish to use <s-tab> then map <s-tab> to <c-d> by insert the following to your ~/.vimrc:

inoremap <s-tab> <c-d>

It should be noted that not all terminals can distinguish between <tab> and <s-tab>.

Upvotes: 1

Related Questions