0

I'm using these two binding for indentation and dedentation of a visual selected block of text.

" Indentation
vmap <TAB>  >gv

" Dedentation
vmap <S-TAB>    <gv

When I dedent with my binding everything is fine, but if I try to indent with <Tab> the text gets deleted. I am not using any plugins and this is my vimrc:

"-----------------------------------------------
" my .VIMRC, the root                           |
"-----------------------------------------------
" only if not set before:
" use vim-defaults instead
" of vi-defaults (easier, more user friendly)
if &compatible          
  set nocompatible      
endif

syntax on
set relativenumber  " hybrid
set number      " hybrid
set mouse=a

set shell=/bin/bash 

"case-insensitive searching
set ignorecase      
set smartcase

" Disable audible/visual bells
set noerrorbells
set novisualbell
set t_vb=

" setting formating stuff
set tabstop=4
set shiftwidth=4
set autoindent

"show matching pairs -> () [] {}
set showmatch

" copy to clipboard
noremap <C-y> "+y  

" paste from clipboard
noremap <C-p> "+p  

" Indentation
vmap <TAB>  >gv

" Dedentation
vmap <S-TAB>    <gv

The version I'm using is VIM - Vi IMproved 9.0 . Does anyone have the same problem or have an idea where the root of this problem is?

5
  • 1
    Try xnoremapvmap is probably not what you want. cf. How to debug my vimrc, How to debug a mapping
    – D. Ben Knoble
    Commented Jul 19, 2022 at 14:05
  • 1
    I have tested on Vim and gVim 9.00 on Windows and it seems to work fine for me :-|. Maybe should you give us more indication. What is the text that you select. What is the result after hitting tab in Visual mode. Commented Jul 19, 2022 at 16:16
  • @VivianDeSmedt It occured at any kind of text. When I hit tab, I'm tabbing in deleting the selected text and going in insert-mode.
    – hmaier
    Commented Jul 20, 2022 at 8:35
  • I have tried to reproduce your problem with the three type of Visual mode (Visual, Visual-Block, Visual-Line) it works fine on my Windows box with Vim 9.00 and on my Ubuntu box with Vim 8.2. Maybe could you try to start vim without .vimrc: vim -u NONE -i NONE enter the map command in the vim command mode : and try to reproduce the problem. Commented Jul 20, 2022 at 8:56
  • 1
    The answer explains why @VivianDeSmedt couldn't reproduce: likely the RHS of the mapping triggered another mapping that they didn't have (or that vim -u NONE -i NONE doesn't have).
    – D. Ben Knoble
    Commented Jul 20, 2022 at 13:55

1 Answer 1

1

Instead of using vmap which is recursivly and works in select- and visual-mode, I switched to xnoremap which isn't recursivly and restricts to only visual mode. Now it works fine!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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