17

I'm using vim in gnome-terminal (2.26.0): although I use 95% of the time "$" to navigate to the EOL and "0" for the opposite, every now and then I hit "Home" or "End".

When I use Home, the text I have in the current line is moved on line down, leaving me in insert mode in the current line and the letter H appears at the beginning of the line.

When I hit End, it's the same but with an F instead of H.

Why does it happen? How can I fix it? (fixing would mean to have the standard functionality when hitting these keys).

peterh
  • 9,698
  • 15
  • 68
  • 87
Mariano
  • 660
  • 6
  • 12

1 Answers1

28

This happens because pressing the home and end keys in a terminal sends an escape sequence consisting of several characters to vim, and vim isn't correctly associating these escape sequences back with the keys you pressed.

To fix this you need to adjust the term setting. Gnome-terminal is xterm compatible, so you could try adding this to your .vimrc:

set term=xterm-256color

The term setting is derived from the TERM environment variable, so you might want to investigate why it isn't set correctly in the first place.

Laurence Gonsalves
  • 125,464
  • 31
  • 220
  • 273
  • Had that setting in my .bashrc and I always assumed it was enough. I was obviously wrong. Thanks for your help. – Mariano Oct 06 '09 at 11:48
  • you saved my life :D was getting ^[[F sequence when using end key.. using cygwin here, hope this will help for all mintty users! – holms Apr 22 '13 at 09:15
  • If others get confused, the line `set term=xterm` should be added to *.vimrc*, not *.bashrc* – Beeno Tung Dec 17 '17 at 01:55
  • 2
    `set term=xterm-256color` seems better since it doesn't break the color schema – Beeno Tung Dec 17 '17 at 02:07
  • @beenotung yes, I was going to suggest that. I just updated the answer. Which colorschemes were you having trouble with with term=xterm? – Laurence Gonsalves Dec 17 '17 at 02:12
  • @LaurenceGonsalves I tried the default one (on archlinux) and torte. Basically any color schema were changed to grey-scale tone. – Beeno Tung Dec 27 '17 at 23:04