vimrc make comments italic

浪尽此生 提交于 2019-12-31 10:01:10

问题


How do I change the ~/.vimrc to have the comments in my code italicized?

In my ~/.vimrc file I have:

highlight Comment ctermfg=blue

that makes the comments blue. What do I need to do differently to make them italic?


回答1:


highlight Comment cterm=italic gui=italic

You'll need a font with an italic set and a terminal capable of displaying italics. Also, if you're using a color scheme other than the default, the above line should come after the color scheme is loaded in your ~/.vimrc so that the color scheme doesn't override it.

The cterm makes it work in the terminal and the gui is for graphical Vim clients.




回答2:


First and foremost, you should check if you terminal is capable of displaying text in italics. In your terminal type (-e flag makes sure escape codes are interpreted)

echo -e "\e[3m foo \e[23m"

If you see foo then okay, otherwise you need to change terminal (Gnome Terminal and Konsole are good choices).

Then you should help Vim to recognise the kind of terminal you are using, put in you ~/.bashrc:

export TERM="xterm-256color"

Now you can try and see if this is enough, open a new file vim foo.html with the following content

<i>foo</i>

Do you see foo in italic? If no then you need to go a little further, right now Vim doesn't know the escape codes to switch to italic mode, you need to tell it (this is the hardest part, it took me a few years to figure that out).

Put the following two lines in your ~/.vimrc

set t_ZH=^[[3m
set t_ZR=^[[23m

These are the same escape codes we used before in the terminal, be aware that ^[ are not literal characters but represent the escape character, you can insert it in insert mode with CTRL-V followed by ESC (see :help i_CTRL-V)

Now reopen the file we created before foo.html and you should see foo in italic; if you don't then I can't help you any more. Otherwise you are almost done; there is one last step.

Put in you ~/.vimrc file

highlight Comment cterm=italic

after loading any colorscheme.




回答3:


In my case I had to put this in my vimrc file:

let &t_ZH="\e[3m"
let &t_ZR="\e[23m"
highlight Comment cterm=italic

Notice it is not the same as:

set t_ZH=^[[3m
set t_ZR=^[[23m
highlight Comment cterm=italic

The former worked for me, while the latter didn't.




回答4:


for GUI environments like gvim, a simple

highlight Comment gui=italic

does it.




回答5:


michaelmichael's answer should solve it for most cases. But, just in case you need this for a font in gvim that doesn't have italics (but oblique or something instead), you can try something like this in ~/.gvimrc

highlight Comment font=Bitstream_Vera_Sans_Mono_Oblique:h14

where h14 is the font size. This font should have the same cell size as your normal font though, so don't use an altogether different font.



来源:https://stackoverflow.com/questions/3494435/vimrc-make-comments-italic

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