5

How can I make Vim not remove lines below with Ctrl and Left Arrow?

So I just found a dangerous setting with Vim on Linux.

If I press Ctrl and Left Arrow then whole rows below start vanishing. With autosave disabled this could accidentally destroy hours of work.

How do I disable this dangerous behaviour in .vimrc for example?

5
  • With autosave disabled typing ':1,$d<enter>' could also accidently destroy hours of work. What terminal emulation do you use, and is it set correct? Commented Jun 1, 2019 at 10:53
  • 1
    But, undo? This is probably just a misconfigured escape sequence gone awry. @Luuk or :%d, but again, u... Commented Jun 2, 2019 at 2:14
  • 3
    OP, can you add the text displayed when you start vim, press i, Ctrl-V, then Ctrl-Left ? Commented Jun 2, 2019 at 3:15
  • 1
    please also show what terminal you are using and what is $TERM set to? Commented Jun 12, 2019 at 8:59
  • This happened for me also when I used vim under tmux. The way to fix is described here: superuser.com/a/402084/315705 - it worked for my case. Commented Jan 30, 2021 at 11:18

2 Answers 2

3

I had a similar problem when using the git-bash inside the "Windows Terminal" tool. When using the git-bash standalone, everything worked fine in vim. But when using inside the Windows Terminal everything related to the ctrl key was strange. ctrl + right arrow deleted a lot of stuff, ctrl + end switched a character between upper and lower case instead of jumping to the end, etc.

Putting set term=xterm into my ~/.vimrc resolved the errors. This may be not a generic solution for the issue, but there isn´t such either (as of all the many different terminals used).

As mentioned in the comments https://superuser.com/questions/401926/how-to-get-shiftarrows-and-ctrlarrows-working-in-vim-in-tmux/402084#402084 seems a nice hint either.

2
  • 1
    Welcome to Vi and Vim! Commented Aug 20, 2021 at 13:10
  • Unfortunately, setting this my ~/.vimrc file resulted in difficult to read visual queues when using vimdiff Commented Nov 20 at 2:01
0

I had this problem as well. Semi related to my terminal. I had switched to Alacritty a while back, but I also did a full system re-install a few months ago, so versions of everything changed, and that may have masked that as a source of issues. Issue was not present in other terms.

I updated my in vim key bindings, made no change to my term settings. I wanted same behavior for my ctrl+left/right in insert and command mode, to switch between vim tabs. For the insert mode binding, it escapes first with , does the navigation and returns to insert mode with the literal i (even if you are in replace mode, so watch out). Relevant lines from my ~/.vim/vimrc

"nav left/right within tabs map [1;5D gT map [1;5C gt imap [1;5D <ESC>gTi imap [1;5C <ESC>gti 

I also had some other control codes that have now been stripped out. I think these were needed for tmux or screen nesting, possibly another term .. I cant recall. Example pre-stripepd entry:

imap ^V^[[1;5C <ESC>gti 

For your specific issue and desire, you could manually re-bind them to something else. Maybe to command mode b/w/e to jump to to prev/next word.