vim 如何在mac上获得像在devcontainers中一样的git编辑器体验?

ttp71kqs  于 2023-11-19  发布在  Mac
关注(0)|答案(2)|浏览(167)

我是一个Visual Studio Code devcontainers的狂热用户,其中一个原因是我可以很容易地获得一个非常漂亮的git编辑体验来做一些事情,比如写提交消息和rebase。
x1c 0d1x的数据



我知道这个颜色编码是通过vim通过devcontainer feature提供的,ghcr.io/guiyomh/features/Vim。下面是我的devcontainer.json:

{
    "name": "testgiteditor",
    "image": "mcr.microsoft.com/devcontainers/base:bullseye",
    "features": {
      "ghcr.io/guiyomh/features/vim": {}
    }
  }

字符串
devcontainer特性只不过是安装脚本的 Package 器,在本例中,安装脚本是https://github.com/guiyomh/features/blob/main/src/vim/install.sh
我想在我的主机上获得同样的体验(这是一台Mac),但简单地安装Vim并不能给给予同样的体验



我不明白在我的容器中安装Vim有什么特别之处,可以提供这种漂亮的体验。有人知道我如何在我的主机mac上获得同样的体验吗?
如果有帮助的话,下面是容器中vim --version的输出:

VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Oct 01 2021 01:51:08)
Included patches: 1-2434
Extra patches: 8.2.3402, 8.2.3403, 8.2.3409, 8.2.3428
Modified by [email protected]
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               -farsi             +mouse_sgr         +tag_binary
+arabic            +file_in_path      -mouse_sysmouse    -tag_old_static
+autocmd           +find_in_path      +mouse_urxvt       -tag_any_white
+autochdir         +float             +mouse_xterm       -tcl
-autoservername    +folding           +multi_byte        +termguicolors
-balloon_eval      -footer            +multi_lang        +terminal
+balloon_eval_term +fork()            -mzscheme          +terminfo
-browse            +gettext           +netbeans_intg     +termresponse
++builtin_terms    -hangul_input      +num64             +textobjects
+byte_offset       +iconv             +packages          +textprop
+channel           +insert_expand     +path_extra        +timers
+cindent           +ipv6              -perl              +title
-clientserver      +job               +persistent_undo   -toolbar
-clipboard         +jumplist          +popupwin          +user_commands
+cmdline_compl     +keymap            +postscript        +vartabs
+cmdline_hist      +lambda            +printer           +vertsplit
+cmdline_info      +langmap           +profile           +virtualedit
+comments          +libcall           -python            +visual
+conceal           +linebreak         -python3           +visualextra
+cryptv            +lispindent        +quickfix          +viminfo
+cscope            +listcmds          +reltime           +vreplace
+cursorbind        +localmap          +rightleft         +wildignore
+cursorshape       -lua               -ruby              +wildmenu
+dialog_con        +menu              +scrollbind        +windows
+diff              +mksession         +signs             +writebackup
+digraphs          +modify_fname      +smartindent       -X11
-dnd               +mouse             -sound             -xfontset
-ebcdic            -mouseshape        +spell             -xim
+emacs_tags        +mouse_dec         +startuptime       -xpm
+eval              +mouse_gpm         +statusline        -xsmp
+ex_extra          -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+extra_search      +mouse_netterm     +syntax            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -Wdate-time -g -O2 -ffile-prefix-map=/build/vim-DtwDbo/vim-8.2.2434=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim -lm -ltinfo -lselinux -lacl -lattr -lgpm -ldl


这是在我的Mac上运行相同程序的输出:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Oct 19 2023 08:52:34)
macOS version - x86_64
Included patches: 1-2049
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +file_in_path      +mouse_urxvt       -tag_any_white
+arabic            +find_in_path      +mouse_xterm       -tcl
+autocmd           +float             +multi_byte        +termguicolors
+autochdir         +folding           +multi_lang        +terminal
-autoservername    -footer            -mzscheme          +terminfo
-balloon_eval      +fork()            +netbeans_intg     +termresponse
+balloon_eval_term +gettext           +num64             +textobjects
-browse            -hangul_input      +packages          +textprop
++builtin_terms    +iconv             +path_extra        +timers
+byte_offset       +insert_expand     +perl              +title
+channel           +ipv6              +persistent_undo   -toolbar
+cindent           +job               +popupwin          +user_commands
-clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           -python            +viminfo
+cmdline_info      +libcall           +python3           +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con        +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             +sound             -xattr
-dnd               -mouseshape        +spell             -xfontset
-ebcdic            +mouse_dec         +startuptime       -xim
+emacs_tags        -mouse_gpm         +statusline        -xpm
+eval              -mouse_jsbterm     -sun_workshop      -xsmp
+ex_extra          +mouse_netterm     +syntax            -xterm_clipboard
+extra_search      +mouse_sgr         +tag_binary        -xterm_save
-farsi             -mouse_sysmouse    -tag_old_static
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X -DMACOS_X_DARWIN -g -O2 -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L/usr/local/lib -o vim -lm -lncurses -lsodium -liconv -lintl -framework AppKit -L/usr/local/opt/lua/lib -llua5.4 -mmacosx-version-min=13.5 -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/perl/lib/perl5/5.38/darwin-thread-multi-2level/CORE -lperl -L/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.12/lib/python3.12/config-3.12-darwin -lpython3.12 -framework CoreFoundation -lruby.3.2 -L/usr/local/Cellar/ruby/3.2.2_1/lib

n6lpvg4x

n6lpvg4x1#

好吧,这个很有趣。
报价myself
Vim的斯巴达式默认设置长期以来一直是一个有争议的主题,在Vim 7.4和Vim 8.0之间,决定为新用户提供一个更友好的基本设置。(见上文)。事实上,它按预期工作:只需启动Vim而无需自定义配置,确实提供了比以前稍微更舒适的体验。
defaults.vim中启用的一个公认有用的功能是语法突出显示。这是您在devcontainer中使用的。
当时,这个新方案并没有得到社区的广泛认可,因为虽然它确实为新的vimmer提供了更好的开箱即用体验,但它打破了几个长期以来的期望,特别是关于与vi的兼容性。
引用我自己的话:
这种方案的诸多问题之一是,开始掌握Vim的终身旅程意味着创建自己的vimrc,这实际上禁用了defaults.vim。这使新用户处于比以前更糟糕的位置:每个人都喜欢讨厌斯巴达式的默认设置,也不知道如何找回他们已经习惯的公认有用的东西,因为defaults.vim基本上是一个黑盒。干得好!
:help defaults.vim提供了一种简单的方法来禁用该机制,如果你不喜欢它:

let skip_defaults_vim = 1

字符串
事实证明,苹果负责Vim包的人似乎并不特别喜欢它,从/usr/share/vim/vimrc中可以看出:

" Configuration file for vim
set modelines=0     " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible    " Use Vim defaults instead of 100% vi compatibility
set backspace=2     " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup

let skip_defaults_vim=1


现在,您的机器上似乎至少有两个Vim:默认的Vim位于/usr/bin/vim,其运行时目录位于/usr/share/vim,Homebrew的Vim位于/opt/homebrew/bin/vim,其运行时目录位于/opt/homebrew/Cellar/vim/<version>/share/vim/vim90
这就是事情变得有点复杂的地方。如上所示,默认Vim的系统vimrc禁用了defaults.vim,因此语法突出显示。但是Homebrew Vim * 没有 * 系统vimrc,所以默认情况下应该启用语法突出显示。
由于默认情况下没有启用语法突出显示,这可能意味着Git使用的是默认的Vim,而不是Hombrew的Vim。
我可以看到两个解决方案...

  • Configure Git将Homebrew Vim用作core.editor
  • 或者创建一个~/.vimrc,包含以下内容(并且,可选地,摆脱Homebrew Vim),按照:help defaults.vim
unlet! skip_defaults_vim
source $VIMRUNTIME/defaults.vim

iezvtpos

iezvtpos2#

只要调用:syntax enable(作为命令或在vimrc中),就应该启用语法高亮显示(如果默认情况下没有启用的话)。请参阅:help :syntax-enable以获取参考。
同时,romainl's thorough root cause analysis仍然有效。我也同意写一个自己的vimrc是学习Vim的必要步骤。

相关问题