如何修改Vim NERDTree中光标选中文件夹的高亮颜色?
Got it, let's get that annoying white selected directory color sorted out so it stays gray and doesn't clash with your file colors. Here's exactly what you need to do:
Step 1: Identify the relevant highlight group
NERDTree uses specific highlight groups for selected items. The one controlling your selected directory's text color is NERDTreeDirSelected. You can confirm its current settings by running this command in Vim:
:hi NERDTreeDirSelected
This will show you the current foreground/background colors (look for ctermfg/ctermbg for terminal Vim, or guifg/guibg for GUI Vim like GVim).
Step 2: Override the highlight group in your vimrc
Add these lines to your ~/.vimrc (or ~/.config/nvim/init.vim if you're using Neovim) to set the selected directory to a gray tone that matches your unselected folders:
For Terminal Vim:
Terminal colors use 256-color codes. Grays range from 240 (dark gray) to 247 (light gray). Pick the shade that fits your setup:
" Set selected NERDTree directory to dark gray (adjust the number for lighter/darker) autocmd VimEnter * highlight NERDTreeDirSelected ctermfg=242 ctermbg=NONE
Setting ctermbg=NONE keeps the background the same as unselected items, so only the text color stays consistent.
For GUI Vim (GVim, MacVim, etc.):
Use a hex color code for precise gray. #888888 is a neutral mid-gray—adjust the value if you want lighter/darker:
" Set selected NERDTree directory to mid-gray autocmd VimEnter * highlight NERDTreeDirSelected guifg=#888888 guibg=NONE
Step 3: Apply the changes
Either restart Vim, or run this command to reload your config immediately:
:source ~/.vimrc
Now when you navigate NERDTree, selected directories will stay gray instead of switching to white, so you won't mix them up with files anymore.
内容的提问来源于stack exchange,提问作者Tallboy

