将git默认的编辑器设置为vin

git默认编辑器现状

如下,很多linux发行版,未加修改的情况下,git的默认编辑器使用起来不太方便

复制代码
Signed-off-by: root <root@xxx.COM>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Committer: root <root@xxx.COM>
#
# On branch master
#
# Initial commit
#
# Changes to be committed:
#       new file:   1.tex
#











^G Get Help    ^O Write Out   ^W Where Is    ^K Cut Text    ^J Justify     ^C Cur Pos     M-U Undo       M-A Mark Text
^X Exit        ^R Read File   ^\ Replace     ^U Paste Text  ^T To Spell    ^_ Go To Line  M-E Redo       M-6 Copy Text

方法一:通过命令行设置

你可以使用 git config 命令来设置 Vim 为默认的编辑器。这个命令可以在你的仓库级别(只影响当前仓库)、全局级别(影响所有仓库)或系统级别(影响所有用户)上设置。

为当前仓库设置 Vim 为默认编辑器

复制代码
~ # git config core.editor "vim"

为所有仓库(全局)设置 Vim 为默认编辑器

复制代码
~ # git config --global core.editor "vim"

为系统上所有用户设置 Vim 为默认编辑器(需要管理员权限):

复制代码
~ # git config --system core.editor "vim"

方法二:通过环境变量设置

另一种设置默认编辑器的方法是设置环境变量 EDITOR。这会影响所有需要编辑器的程序,包括 Git。

在 Bash 中设置(仅对当前会话有效)

复制代码
~ # export EDITOR=vim

在 Bash 中永久设置

export EDITOR=vim 添加到你的 ~/.bashrc~/.bash_profile 文件中,然后重新加载配置文件(通过运行 source ~/.bashrc 或重新登录)。

复制代码
~ # git config --system core.editor "vim"
相关推荐
我叫黑大帅8 小时前
git 的 NFD 与 NFC 有什么区别?为什么我有个文件在 NFC 中间不会被当成改动,在 NFD 中就会当成改动
git·面试·github
呆萌很11 小时前
Git push 408 超时、远程断开解决办法
git
Lesile11 小时前
Hands-on Git experience
git
Co_Hui13 小时前
Git 基本使用
git
cooldream200913 小时前
AI 时代,Git 应该怎么学
人工智能·git
柒和远方14 小时前
V053: 从 Git 回退到 AI 工程治理:Vibe Coding 的 Harness 工作流与质量阀门
git·vibecoding
炸膛坦客17 小时前
Git 和 GitHub:(五)一文给出常用 Git 命令,持续更新中......
git·github
●VON17 小时前
鸿蒙 PC Markdown 编辑器 Alpha 评审:如何用退出条件判断阶段完成
网络·安全·华为·编辑器·harmonyos·鸿蒙
MGS浪疯17 小时前
我用 WorkBuddy 做了一个能记住前文的 AI 小说编辑器
人工智能·编辑器·腾讯云·腾讯云ai代码助手·workbuddy开发者分享季·codebuddy开发者分享季
门前大桥下.17 小时前
从git创建新分支后推送数据同步新的分支
git