I am an avid user of Visual Studio Code devcontainers and one of the reasons is that I can easily get a very pretty git editing experience for doing things like writing commit messages and rebasing.
I know that this colour coding is provided by using vim
via a devcontainer feature, ghcr.io/guiyomh/features/vim. Here is my devcontainer.json:
{
"name": "testgiteditor",
"image": "mcr.microsoft.com/devcontainers/base:bullseye",
"features": {
"ghcr.io/guiyomh/features/vim": {}
}
}
A devcontainer feature is nothing more than a wrapper around an install script and in this case that install script is https://github.com/guiyomh/features/blob/main/src/vim/install.sh. That script doesn’t seem to do anything special, it basically runs apt-get -y install --no-install-recommends vim
I would like to get the same experience on my host machine (which is a mac) but simply installing vim doesn’t give the same experience
I don’t understand what is so particular about the vim installation in my container that provides this pretty experience. Does anyone know how I can get the same experience on my host mac?
In case it helps, here is the output from vim --version
in the container:
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
and here is the output from running the same on my 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
2
Answers
OK, this one is pretty funny.
Quoting myself:
One of the admittedly useful things enabled in
defaults.vim
is syntax highlighting. This is what you are used to in your devcontainer.At the time, the new scheme was not very well received by the community because, while definitely providing a better out-of-the-box experience to new vimmers, it broke several long-established expectations, specifically regarding compatibility with vi.
Still quoting myself:
:help defaults.vim
provides a simple way to disable that mechanism if you don’t like it:and it turns out that the people in charge of the Vim package at Apple don’t seem to be particularly fond of it, as can be seen in
/usr/share/vim/vimrc
:Now, you appear to have at least two Vims on your machine: the default one at
/usr/bin/vim
, with its runtime directory at/usr/share/vim
, and the Homebrew one at/opt/homebrew/bin/vim
, with its runtime directory at/opt/homebrew/Cellar/vim/<version>/share/vim/vim90
.This is where things get a bit complicated. As shown above, the system
vimrc
of the default Vim, disablesdefaults.vim
and thus syntax highlighting. But the Homebrew Vim doesn’t come with a systemvimrc
, so it should have syntax highlighting enabled by default.Since you don’t have syntax highlighting enabled by default, it probably means that Git is using the default Vim and not the Hombrew Vim.
I can see two solutions…
Configure Git to use Homebrew Vim as
core.editor
.Or create a
~/.vimrc
with the following content (and, optionally, get rid of Homebrew Vim), as per:help defaults.vim
:Just calling
:syntax enable
(as a command or invimrc
) should enable syntax highlighting if it wasn’t turned on by default. See:help :syntax-enable
for reference.At the same time, romainl’s thorough root cause analysis remains valid. I also agree that writing a
vimrc
of one’s own is a necessary step in learning Vim.