3

I've read that in insert mode in vim, one can use <C-Left> and <C-Right> to move by words. This works for me, but only as far as I don't run vim inside tmux terminal splitter.

When inside tmux, <C-Left> instead throws me out of the insert mode and gives an error:

E388: Couldn't find definition

This error is explained in the help to have something to do with definition searching. However, I don't want any definition to be searched for, I want just to move one word to the left. As well, <C-Right> does nothing more than throwing me out of the insert mode, not what I would like.

Reading somewhere that this might be connected to set (no)esckeys, I tried it with both settings of this flag, with the very same result. As well, I have seen the answers in How to get shift+arrows and ctrl+arrows working in Vim in tmux? but they don't appear to help me.

My current .tmux.conf:

# This File is : ~/.tmux.conf

# use "|" and "-" to do vertical/horizontal splits
# (press CTRL B and then - or |, CTRL D to close it)
unbind %
bind | split-window -h
bind - split-window -v

# use the vim motion keys to move between panes
# (press CTRL B and then h,j,k,l for the move)
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# use vim motion keys while in copy mode
# To copy, press CTRL B and then [, move, space, move, enter.
# To paste, press CTRL B and then ]
setw -g mode-keys vi

# make vim work properly inside tmux
setw -g xterm-keys on
set -g default-terminal "screen-256color"

And .vimrc:

" tabs, indentation, line numbering
set ts=4 sts=4 number autoindent sw=4

" sage is python
au BufNewFile,BufRead *.sage set filetype=python

if &term =~ '^screen'
  " Page keys http://sourceforge.net/p/tmux/tmux-code/ci/master/tree/FAQ
  execute "set t_kP=\e[5;*~"
  execute "set t_kN=\e[6;*~"

  " Arrow keys http://unix.stackexchange.com/a/34723
  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
1
  • @romainl Ok, so I have seen the two answers in the other thread and as well the post linked in the second of them, but none of the solutions work for me. What can I do now?
    – yo'
    Commented Jan 16, 2014 at 11:58

1 Answer 1

1

Your Vim doesn't correctly detect the <C-Left> keycodes sent by the terminal (and probably others, too). Instead, it dissects the codes, ESC takes it out of insert mode, and a [D then causes the strange error.

You can try fiddling with your TERM setting, but in general it's difficult to make special keys (like cursor and function keys) work with modifiers like Shift and Ctrl in the terminal. (Those also don't work for me on Ubuntu with gnome-terminal.) The easiest workaround is to use the graphical GVIM instead.

1
  • That's [D, by the way.
    – romainl
    Commented Jan 16, 2014 at 12:49

Not the answer you're looking for? Browse other questions tagged .