How to set environment variable in vimrc?

Viewed 2515

My home and end key is not working in neovim. I am connecting via Mtputty. I found that setting terminal in environment variable made it as work.

export TERM=putty-256color

But whenever i close the session , next time i had to set. So i tried to add it in .vimrc. I am setting TERM environment path via vimrc like below.

if has('nvim')
  let $TERM = 'putty-256color'
endif

But it is not working .

How to set environment variable in vimrc?

1 Answers

:let $VARNAME = expression is the way to proceed -- Note: only expressions that evaluate as integers or strings will be valid: :h expression.

It's quite likely that nvim has already processed $TERM value. Changing it while nvim is already running is too late. Updated environment variables will mostly be used by subprocesses and plugins that read them at the last moment.

IMO, you'd better define an alias on nvim that'll mask the default program, and set the environment variable before running \nvim, e.g.:

# bash function
nvim() {
    export TERM=putty-256color 
    \nvim "$@"
}
Related