bash 无法更改终端中的默认编辑器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/647032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 18:02:21  来源:igfitidea点击:

Unable to change the default editor in terminal

bashvimeditorpico

提问by Léo Léopold Hertz ??

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

我的服务器上的默认编辑器是 pico。我使用 Bash 和 Linux。

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

我试图将 Vim 更改为我的默认编辑器,但未成功

echo vim > $EDITOR

How can I change Vim my default editor?

如何更改 Vim 的默认编辑器?

[edit]

[编辑]

The following code does not work in .bashrc

以下代码在 .bashrc 中不起作用

export EDITOR='vim'

回答by Jochen Walter

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.)

到您的 .bashrc 应该真的可以解决问题。(没有必要的引号,根据您使用的引号,它们可能是您问题的原因。)

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

source ~/.bashrc修改 .bashrc 后必须打开一个新的 shell(或者在提示符下输入),修改才能生效。

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

您希望从哪个程序启动 vim?

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).''

编辑:我没有使用过 git,但文档(http://www.kernel.org/pub/software/scm/git/docs/git-commit.html)读取“编辑器用于编辑提交日志消息将从 GIT_EDITOR 环境变量、core.editor 配置变量、VISUAL 环境变量或 EDITOR 环境变量(按此顺序)中选择。''

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.

解决了这个问题。

回答by 4levels

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

您可以使用 git 配置选项 core.editor 来设置您喜欢的编辑器,例如 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:

如果您没有 shell 访问权限,您还可以通过编辑主目录(全局)或 git repo(如果它不存在则创建它)中的 .gitconfig 文件来更改此设置:

...
[user]
  name = Your Name
  email = [email protected]
[core]
  editor = nano
...

回答by Grzegorz Brz?czyszczykiewicz

Check this command:

检查此命令:

sudo update-alternatives --config editor

回答by Grzegorz Brz?czyszczykiewicz

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

should do the job

应该做这份工作

回答by Philluminati

I don't have an EDITORenvironmental variable. Perhaps you could specify your distribution? My bashrcdoes define this:

我没有EDITOR环境变量。也许你可以指定你的分布?我bashrc确实定义了这个:

alias vi='vim'

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

并且据说如果 vim 找不到.vimrc在您的主目录中调用的文件,它会在“兼容模式”下运行并且您只能获得 vi 功能,直到您说类型:nocp

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

如果它基于您的EDITOR环境变量,您可以在 BASH 中像这样设置它:

export EDITOR='vim'

回答by user1306828

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

由于 MAC X 中的情况发生了变化,因此您必须在用户基本目录的 .profile 文件中添加以下内容

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

按回车并重新启动

回答by threeta

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

如果您希望 vi 成为您的默认历史编辑器(这就是我在这里的原因)

edit ~/.bashrc and add

编辑 ~/.bashrc 并添加

set -o vi

设置 -o vi

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

文件中的任何位置。然后所有可爱的 vi 命令历史都可用(esc k 等)。

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

对不起,如果这有点偏离主题,但我的搜索让我来到这里......

回答by Eric Wiener

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

我需要在虚拟环境中手动安装 Vim。唯一对我有用的命令是:

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

Source

来源

回答by bentford

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

这是 git 文档所说的内容: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).

用于编辑提交日志消息的编辑器将从 GIT_EDITOR 环境变量、core.editor 配置变量、VISUAL 环境变量或 EDITOR 环境变量(按此顺序)中选择。

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

以下是关于导出的 BASH 手册页摘录(括号是可选的):

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

导出 [-fn] [名称[=单词]]