In Vim, when in Visual mode, I have to press Esc twice to exit it and turn off the selection. After one press of Esc I have to wait 2 seconds for the selection to turn off.
What can I do to exit Visual mode immediately when Esc is pressed?
This mode is also called the Character Visual mode of Vim. You can also perform the yank, delete and put functions here. Within this mode, move the cursor to highlight the text, as shown below. To get into the Vim Visual Line mode, press “Shift+V” while you are in Vim's Normal mode.
Just press Esc button and you will exit the Visual Mode. Then enter the mode you want to! Show activity on this post.
Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block. Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement. Press d (delete) to cut, or y (yank) to copy.
Executing following command helped me:
set timeoutlen=1000 ttimeoutlen=0
see: http://www.johnhawthorn.com/2012/09/vi-escape-delays/.
As Ingo explained. Just thought I would post the solution: https://github.com/Greduan/dotfiles/blob/47f92e4db29d4ead778d877a85082b271de130ed/vim/vimrc.vim#L332-L346
Works pretty well. It's a little bit confusing for me as well, so I can't really explain, but the code explains itself pretty well.
The point is it works, it simply makes <Esc>
work immediately even when on Terminal. I believe if you do have mappings set to <Esc>
it'll give you time to do those as well. However I'm not sure.
EDIT
Studied a bit and I can now explain it. Basically, if you're not using a GUI (like MacVim) then when you enter insert mode the ttimeoutlen
will be set to 0. Meaning that as soon as you click <Esc>
that'll work. However once you're in normal mode then it'll set the ttimeoutlen
to the number you prefer, letting you do mappings with <Esc>
.
Perfect solution I think, since if you have mappings in insert mode it'll be using control or something like that.
EDIT 2
Here's the code:
set timeout " Do time out on mappings and others set timeoutlen=2000 " Wait {num} ms before timing out a mapping " When you’re pressing Escape to leave insert mode in the terminal, it will by " default take a second or another keystroke to leave insert mode completely " and update the statusline. This fixes that. I got this from: " https://powerline.readthedocs.org/en/latest/tipstricks.html#vim if !has('gui_running') set ttimeoutlen=10 augroup FastEscape autocmd! au InsertEnter * set timeoutlen=0 au InsertLeave * set timeoutlen=1000 augroup END endif
With time I've removed the condition that the GUI isn't running and it still works as far as I can tell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With