I recently was doing some Vim editing and noticed the behavior was very different for two important keys.

The only difference I made was I started bash using:

env -i bash --init-script ~/.bashrc.custom.sh

I use home, end to move the cursor around in vim.

But instead of home, end moving the cursor... pressing these keys would enter vim's insert mode and output 'H' and 'F' characters.

I want the old behavior.

When I start bash normally I get the old behavior.

How do you fix the home, end keys producing 'H' and 'F'?

Make sure the environment variable TERM is set. For example set the environment variable from bash via export TERM=xterm THEN open vim. Once in vim you can check that it worked by doing set term.


Apparently vim checks the environment variable TERM to decide what how to handle terminal control characters (more info on vim handling terminal control characters open vim help by doing vim command help term).

I was missing the TERM variable, vim would use the default and set term=ansi.

So for my situation I made sure set the TERM environment variable was set (in my ~/.bashrc.custom.sh).

I set the value of export TERM=xterm.

Now when I open vim the value of set term is xterm and I get the expected behavior from home, end.

  • actually, you should export TERM to whatever terminal you are really using (or even better, never delete the TERM variable to begin with) . always using xterm might cause weird behaviour. – Christian Brabandt Aug 11 at 7:15

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.