I want to make use of Shift+Tab to left-shift (unindent) a block of text, instead of Ctrl+d. How to do it?


The basics of simple mappings are explained in Vim's excellent user manual at :help 05.4.

You want some key combination (Shift + Tab) to do what's already provided by Vim's Ctrl + D command, so you map <S-Tab> (using :help key-notation now) to <C-d>. As Vim is a mode-based editor, you need to consider the mode; :help i_CTRL-D is for insert mode.

As your target is a built-in Vim command, you should use :noremap; it makes the mapping immune to remapping and recursion.

inoremap <S-Tab> <C-d>

To try this out, just execute the above command (entering command-line mode via :, and concluding with Enter). To make this persist across Vim sessions, put it into your ~/.vimrc configuration, and restart Vim.

The original <C-d> command will still work; you've just created an alias. As you've defined an alternative, you could remap that key now, or (if it bothers you, if you frequently mistakenly trigger it) turn it off by mapping to the special <Nop> target:

inoremap <C-d> <Nop>
  • 2
    Is shift tab really mappable though? Or is it the same as control I?
    – D. Ben Knoble
    Nov 14 '19 at 13:08
  • 3
    @D.BenKnoble: If Shift-Tab is different from Tab (and it is for me, even in the terminal), then it's also different from Ctrl-I. Nov 14 '19 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.