Unable to change the default editor in terminal

本秂侑毒 提交于 2019-11-27 01:46:37

问题


My default editor is pico at my server. I use Bash and Linux.

I tried to change Vim to be my default editor unsuccessfully by

echo vim > $EDITOR

How can I change Vim my default editor?

[edit]

The following code does not work in .bashrc

export EDITOR='vim'

回答1:


Adding

export EDITOR=vim

to your .bashrc should really do the trick. (There a no quotes necessary and, depending on what quotes you used, they may be the cause for your problem.)

You must open a new shell (or enter source ~/.bashrc at the prompt) after modifying .bashrc for the modification to take effect.

What is the program from which you want vim to be started?

EDIT: I haven't used git, but the documentation (http://www.kernel.org/pub/software/scm/git/docs/git-commit.html) reads ``The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).''

So check whether one of these variables is set:

echo $GIT_EDITOR $VISUAL $EDITOR
git config --get-all core.editor

For me,

export VISUAL=vim

solved the problem.




回答2:


You can use the git config option core.editor to set the editor of your liking, eg nano

$ git config [--global] core.editor "nano"

You can also change this by editing the .gitconfig file in your home directory (global) or git repo (create it if it doesn't exist) if you don't have shell access:

...
[user]
  name = Your Name
  email = your@email.address
[core]
  editor = nano
...



回答3:


I don't have an EDITOR environmental variable. Perhaps you could specify your distribution? My bashrc does define this:

alias vi='vim'

and supposedly if vim can't find a file called .vimrc in your home directory it runs in "compatibility mode" and you only get vi features until you say type :nocp

If it is based on your EDITOR environmental variable you would set it like this in BASH:

export EDITOR='vim'



回答4:


vim=/usr/bin/vim #or wherever vim binary is
export EDITOR=vim

should do the job




回答5:


Check this command:

sudo update-alternatives --config editor



回答6:


Since things have changed in MAC X you will have to add following in .profile file in base directory of the user

export EDITOR='vim'

you can follow following instructions:

1> open terminal

2> type - cd  [hit return/enter (this will take you to base directory)]

3> type - echo "export EDITOR='vim'" >> .profile (hit return/enter and you are done)

4>  (restart terminal)

=========================

OR just type:

echo "export EDITOR='vim'" >> ~/.profile

hit enter and restart




回答7:


Since none of these answers are helping me:

Here is what the git docs are saying: http://www.kernel.org/pub/software/scm/git/docs/git-commit.html

The editor used to edit the commit log message will be chosen from the GIT_EDITOR environment variable, the core.editor configuration variable, the VISUAL environment variable, or the EDITOR environment variable (in that order).

Here is the BASH man page excerpt on export (brackets are optional):

export [-fn] [name[=word]]




回答8:


if you want vi to be your default history editor (which is why I'm here)

edit ~/.bashrc and add

set -o vi

anywhere in the file. Then all the lovely vi command history is available (esc k etc).

Sorry if this is slightly off topic, but my search landed me here....




回答9:


I needed to install Vim manually in a virtual environment. The only command that worked for me was:

`sudo update-alternatives --install /usr/bin/editor editor /usr/bin/vim 100

Source



来源:https://stackoverflow.com/questions/647032/unable-to-change-the-default-editor-in-terminal

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!