2

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'?

1 Answer 1

1

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.

2
  • 1
    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. Commented Aug 11, 2018 at 7:15
  • Always using xterm means the weird behaviour is, at least, expected
    – jalanb
    Commented Feb 5, 2020 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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