alacritty: Jumping word by word using control + arrow keys doesn't works in vim

Which operating system does the issue occur on? Arch Linux(Linux y50 4.13.12-1-ARCH #1 SMP PREEMPT Wed Nov 8 11:54:06 CET 2017 x86_64 GNU/Linux)

If on linux, are you using X11 or Wayland? X11

Usually, Pressing Ctrl+Left/Right arrow keys makes the cursor jump word by word in left or right direction in vim.

In alacritty, When I press Ctrl+Left Arrow Key, It enters :5D in command mode in vim and pressing Ctrl+Right arrow key enters :5C in command mode.

I tried fixes like putting set nocompatible and set nocp in my .vimrc but it doesn’t works.

od -a output for Left and Right arrow keys. Left Arrow key -> ^[[1;5D Right Arrow key -> ^[[1;5C

Is there some way to make arrow keys work in vim? I am not comfortable with using hjkl yet and not having arrow keys to help is slightly frustrating.

Thanks. PS: This project is awesome. I have a few suggestions and PRs, I’ll create seperate issues for those.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 26 (9 by maintainers)

Most upvoted comments

Based on the discussion so far, this issue can be reproduced by base vim users who have their TERM environmental variable set as alacritty and not xterm-256color.

This might be a naive (or bad) suggestion, but what about forcing vim to read your terminal as xterm-256color as follows?

" somewhere in your .vimrc
set term=xterm-256color

This fixes the issue for me and has the simplicity of a one-liner, but not sure what side effects could arise.

The workaround I’m using is

if &term == 'alacritty'
    execute "set <xUp>=\e[1;*A"
    execute "set <xDown>=\e[1;*B"
    execute "set <xRight>=\e[1;*C"
    execute "set <xLeft>=\e[1;*D"
endif

(from https://superuser.com/a/402084/1182008)

This is better since it avoids having mappings starting with <Esc>, which would make vim wait for timeoutlen milliseconds whenever you press Escape.

Workaround to add in .vimrc :

map <ESC>[1;5A <C-Up>
map <ESC>[1;5B <C-Down>
map <ESC>[1;5C <C-Right>
map <ESC>[1;5D <C-Left>
imap <ESC>[1;5A <C-Up>
imap <ESC>[1;5B <C-Down>
imap <ESC>[1;5C <C-Right>
imap <ESC>[1;5D <C-Left>

@chrisduerr That does indeed make it work. Renaming alacritty to xterm-256color (main, common and direct) in alacritty.info and installing with sudo tic -xe alacritty,alacritty-direct alacritty.info. I verified it’s using the correct one (deleted all xterm terminfo’s and infocmp -x).

EDIT: Different name, as long as it starts with xterm also works, eg. xterm-alacritty (but alacritty-xterm does not). Possible solution?

@jonpas can you try compiling alacritty’s terminfo file with tic -x? (you may want to wait for #2134 to land first.) In your configuration, alacritty doesn’t appear to define kDN5, kLFT5, kRIT5 and kUP5, whereas xterm-256color does.

However, using tic -x doesn’t work for me – I think Vim is hard-coding support for xterm here, c.f. the following bug (about the same issue in rvxt-unicode): https://bugzilla.redhat.com/show_bug.cgi?id=474110

The xterm description has capabilities kLFT5 and kRIT5 to specify the sequences for control+left and control+right, but they don’t seem to be supported in applications. Definitely not in readline and vim as they use only the termcap interface.

Applications where ctrl+arrow keys work have the sequences hardcoded. Thomas, please correct me if I’m wrong.

so there may be no solution in alacritty apart from pretending to be xterm. The real fix would need to be in Vim itself, I guess; IIUC, Vim would need to switch from using termcap to using terminfo.

See also :help xterm-shifted-keys:

Newer versions of xterm support shifted function keys and special keys. Vim recognizes most of them. Use “:set termcap” to check which are supported and what the codes are. Mostly these are not in a termcap, they are only supported by the builtin_xterm termcap.

For the record, this doesn’t work for me

In addition to setting <xUp>, <xDown>, <xRight>, <xLeft>, set 'ttymouse' to sgr:

if &term == 'alacritty'
    set ttymouse=sgr
    execute "set <xUp>=\e[1;*A"
    execute "set <xDown>=\e[1;*B"
    execute "set <xRight>=\e[1;*C"
    execute "set <xLeft>=\e[1;*D"
endif

Or clear <DecMouse>:

if &term == 'alacritty'
    set <DecMouse>=
    execute "set <xUp>=\e[1;*A"
    execute "set <xDown>=\e[1;*B"
    execute "set <xRight>=\e[1;*C"
    execute "set <xLeft>=\e[1;*D"
endif

If that doesn’t help, post the output of :set! termcap.

Possible solution?

Upstream fix. This already had to be done for some Neovim features.

The only solution is to open a bug upstream and resolve this in vim, since this is a vim bug, not an Alacritty bug.

@jonpas Would you mind trying to export Alacritty’s terminfo with the name xterm-256color? This might just be vim hardcoding something for xterm.

The output of od -a in xterm(where arrow keys work just fine) is same as the output in alacritty.