Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 844  / 1 Year ago, mon, april 10, 2023, 5:06:02

I use neovim. I changed my .zshrc to open nvim when I type vim in the terminal.


My configuration is from my Mac where I didn't use Sudo much (now I use Ubuntu, I use sudo all the time).


When I do sudo vim {anything}, Vi opens or it might be Vim but its not neovim.


In my zshrc I have:


alias vim="nvim"
EXPORT EDITOR="nvim"

How do I activate nvim to open files when I use sudo?


More From » sudo

 Answers
7

The reason sudo vim opens vim is because vim on your system is set to open vim.basic through the Debian alternatives system. You override this for your personal user with an alias, but sudo does not use your user configuration, but the configuration of user root.


Rather than also setting up an alias for the root user, you better set up your system so vim points to nvim:


Execute the command


sudo update-alternatives --config vim

Select the option listing nvim (/usr/bin/nvim):


There are 2 choices for the alternative vim (providing /usr/bin/vim).

Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/vim.basic 30 auto mode
1 /usr/bin/nvim 30 manual mode
2 /usr/bin/vim.basic 30 manual mode

Press <enter> to keep the current choice[*], or type selection number:

In this case, I would enter 2.


After this, you can remove your alias definition.


[#494] Wednesday, April 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
skaing

Total Points: 462
Total Questions: 124
Total Answers: 113

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
skaing questions
;