nicoX
nicoX

Reputation: 311

VIM arrow keys with sudo

I have identical .bashrc and .bash_profile files. When I sudo vim <file> in insert mode the arrow keys create a, b, c ,d instead of going left/right/up/down.

Upvotes: 0

Views: 529

Answers (2)

Kennedy
Kennedy

Reputation: 1

Other option is to edit the system wide configuration file. On Ubuntu this could be one of either

  • /etc/vim/vimrc.tiny
  • /etc/vim/vimrc

In my system default /etc/vim/vimrc.tiny I changed

set compatible 

to

set nocompatible

After this even when using sudo the arrow keys did not result in A, B, C ,D instead of going left/right/up/down.

See this link for an explanation about what "compatible" is

https://superuser.com/questions/543317/what-is-compatible-mode-in-vim

Upvotes: 0

Brett Y
Brett Y

Reputation: 7688

When you do sudo vim <file> you are running vim as the sudo user, so your users .vimrc is not being loaded, and the sudo user does not have a .vimrc of its own. You should see the same behavior with vim -u NONE.

The solution is to do the following:

:set nocompatible

This is done by vim implicitly when you have a .vimrc.


An alternative to using sudo vim <file> is to set you $EDITOR environment variable to vim by adding the following to your .bashrc

export VISUAL=vim
export EDITOR="$VISUAL"

Then, to edit files that require sudo premissons use: sudo -e <file>

Upvotes: 3

Related Questions