Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

While moving the cursor across a vim process open in a tmux session, every now and then, why does it leave a trail of ghost characters - ^[OB, ^[OA?

Tags:

vim

tmux

These disappear if I do a page-up and page-down. Why does this happen and how do I rectify it?

http://i.stack.imgur.com/DnMYl.png

I recently fiddled around with my vimrc. Could that be the cause?

UPDATE: I figured out the cause. I had added to functions that automatically updated the cwd name and the current git branch in my vim statusline. This caused vim to be laggy and everytime it lagged on a up/down/left/right key hit, it printed out the ghost characters ^[OA, etc. It's possible that stuff got complicated because I was using vim in tmux, but I saw the ghost characters outside tmux also. So, probably not. I've turned off those two functions in my .vimrc and my vim statusline is presently less awesome than it used to be :( Wish there's a way out.

like image 578
Vighnesh Avatar asked Aug 08 '11 19:08

Vighnesh


3 Answers

^[OB and ^[OA are how your terminal represent <down> and <up>.

I've seen these (and their friends ^[OC and ^[OD) appear in the "command line" or omni-completion menus and during usage of a couple of plugins in vim in tmux.

My solution was to map them to the directional keys:

map ^[OA <up>
map ^[OB <down>
map ^[OC <right>
map ^[OD <left>

In case you don't know, you must not type ^[ as two characters, you must do <C-v><Esc>.

That is, while in --INSERT-- mode press the Control key and the V key together then hit the Escape key. Doing so will input the correct single character that looks like ^[.

like image 82
romainl Avatar answered Oct 24 '22 06:10

romainl


This issue is discussed at length on the Vim Wiki article. There seem to be multiple causes, I personally encountered this issue when running vim under tmux.

A solution from there that worked for me and seems less hacky than mapping the keys was the following config:

set term=cons25

like image 44
Andy Smith Avatar answered Oct 24 '22 08:10

Andy Smith


Hard to say without knowing what's in your vimrc, but you can confirm whether it's something in there by starting it up without running it and seeing if it still happens using the following...

vim -u NONE

like image 32
Costa Avatar answered Oct 24 '22 06:10

Costa