vimrc make comments italic

前端 未结 5 1570
说谎
说谎 2021-02-01 14:08

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

In my ~/.vimrc file I have:

highlight Comment ctermfg=         


        
5条回答
  •  Happy的楠姐
    2021-02-01 14:32

    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

    foo
    

    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.

提交回复
热议问题