How to change the color of the selected code (Vim scheme)?

允我心安 提交于 2019-12-03 10:58:15

问题


How do I change the color of the selected code in Vim?

There are three selection modes, Visual Line mode or Visual Block mode, and selecting with the mouse).

  hi CursorLine guibg=#DDDDDD gui=none
  hi CursorColumn guibg=#EEEEEE gui=none
  hi MatchParen guifg=#f6f3e8 guibg=#857b6f gui=none
  hi Pmenu   guifg=#f6f3e8 guibg=#DDDDDD gui=none
  hi PmenuSel  guifg=#000000 guibg=#DDDDDD gui=none
endif

" General colors
hi Cursor   guifg=NONE    guibg=#656565 gui=none
hi Normal   guifg=#000000 guibg=#FFFFFF gui=none
hi NonText   guifg=#808080 guibg=#FFFFFF gui=none
hi LineNr   guifg=#857b6f guibg=#FFFFFF gui=none
hi StatusLine  guifg=#000000 guibg=#FFFFFF gui=none
hi StatusLineNC guifg=#857b6f guibg=#FFFFFF gui=none
hi VertSplit  guifg=#444444 guibg=#FFFFFF gui=none
hi Folded   guibg=#AAAAAA guifg=#FFFFFF gui=none
hi Title  guifg=#000000 guibg=NONE gui=none
hi Visual  guifg=#000000 guibg=#FFFFFF gui=none
hi SpecialKey guifg=#808080 guibg=#FFFFFF gui=none

How do I know which line it is?


回答1:


Selection color for gvim is set by the following line:

hi Visual  guifg=#000000 guibg=#FFFFFF gui=none

You can use named color values instead of the #nnnnnn RGB codes. Your existing line is set for black foreground and white background, just as you observed.

For example, if you want a light blue background with white foreground:

hi Visual  guifg=White guibg=LightBlue gui=none

Be sure the color file you are editing is in the vim7x/colors directory so both vim and gvim can find it. Its exact location can vary a bit depending on your OS platform.




回答2:


How to set the color of the selected code in vi?

I'm using VIM 7.3 on Ubuntu and this does it for me within the editor:

:syntax on 
:hi Visual term=reverse cterm=reverse guibg=Grey

I'm using a colorscheme defined in the /home/youruser/.vim/colors/mycolorscheme.vim file. I set the command there and the changes take effect when vim starts.

syntax on
hi Visual term=reverse cterm=reverse guibg=Grey



回答3:


I just change my color scheme file (~/.vim/colors/solarized.vim), and set 'Visual' to the same value as 'CursorLine'.

I like the style of CursorLine as it is transparent and keep the selected elements's syntax highlight color.

Replace the line that contains exe "hi! Visual" with the following line:

exe "hi! Visual"     .s:fmt_uopt   .s:fg_none   .s:bg_base02  .s:sp_base1

or:

:highlight Visual cterm=NONE ctermbg=0 ctermfg=NONE guibg=Grey40

Like so:




回答4:


mu color scheme is molokai, and I found that this configuration is the best for me:

highlight Visual cterm=bold ctermbg=Blue ctermfg=NONE

check out my vimrc @https://github.com/reubinoff/myVimrc




回答5:


You should look at this nice collection of Vim schemes.

Maybe one of them suits your needs.



来源:https://stackoverflow.com/questions/3074068/how-to-change-the-color-of-the-selected-code-vim-scheme

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!