How to make comments Italic in gVim? - vim

I am fairly new to Vim and mainly use gVim for most of my coding purposes. I am trying to figure out what to add in my _vimrc (in windows) to make my comments italic.
I tried adding
highlight Comment cterm=italic
but that didn't work. My modifications so far in my vimrc (if it matters) is:
color slate
set number
set nowrap
set guioptions+=b
if has('gui_running')
set guifont=Consolas:h10
endif
So what can I do so that my comments appear in italics (consolas, italic, size 10)?

The cterm definition is only for high color terminals; for the GUI, you need to use the gui= argument:
highlight Comment cterm=italic gui=italic
Also, put this after the :colorscheme command in your ~/.vimrc, or else it might get overridden.

Related

Changing background colors

Okay, I'm rather new to vim. I couldn't figure out how to change background colors. I'm editing my vimrc file to set these colors, but I couldn't find anything for background colors.
I'm using a color scheme and I just need to know how I could override it or what is to look for so I can change it in my colors/theme.vim file. I need to change two background colors. I point to them in the image attached.
As it turns out the big blue section is controlled by highlight NonText
I added my .vimrc file to this:
highlight NonText ctermfg=59 ctermbg=0 cterm=NONE guifg=#414e58 guibg=#232c31 gui=NONE
and that gave me exactly what I wanted.
VIM has some color scheme, which store under /usr/share/vim/vimcurrent/colors, and it named as desert.vim for example.
you can simply add one line in your vimrc file, which should be locate in your $HOME, if there is NOT, you can create one, and add:
colorscheme desert
also some command you can use to set the background color like:
set background=light
or
set background=dark
I think for SSH, light is better:) If you use X windows, I suggest to use bensday.vim, it can be download from web

Spelling errors hidden while highlighting line in vim

When there's a misspelling (with set spell), it highlights it red (good!), but when the line is highlighted as my current line the red goes away (bad). Removing set cul fixes the problem, but how do I keep the word marked red while being highlighted? I may have multiple words misspelled on a line and also while typing the misspellings are hidden until I go to the next which kinda sucks.
vimrc: https://gist.github.com/OscarGodson/d1b05d52df4ff160b891
colorscheme: https://github.com/tomasr/molokai
1) one could change the vim color scheme, or the SpellBad highlight scheme; one example of the second case is to add in vimrc the following,
hi clear SpellBad
hi SpellBad cterm=bold
2) (not a solution) someone might find 'spell checking while composing' is a bit annoying / distracting and prefer switching the spell checking off until they finish writing the article.
The problem is that the cursorline highlighting has priority over the syntax highlighting (spell errors belong to that), and that cannot be changed. (You can only specify the priority with the newer matchadd() functions.)
I've once raised this issue for error highlighting, but nothing came out of it. (I'd still like to implement a patch for that one day.)
The problem is only about overlap of background highlighting; in GVIM, most color schemes use the undercurl attribute to avoid that issue. In the console, you can only change the highlighting to foreground color, italic or bold attributes to work around it.
workaround
One clever workaround involves swapping the foreground and background colors while adding the reverse attribute: Turn
hi SpellBad cterm=NONE ctermbg=red ctermfg=white
to
hi SpellBad cterm=reverse ctermbg=white ctermfg=red
These two changes cancel each other out normally, but on a CursorLine, the foreground color now contributes to the coloring, turning hard-to-read white-on-cursorline to red-on-cursorline.
Curiously, and jumping off of both answers from the other posters, adding the following in my vimrc made my red background persist accidentally due to my terminal not being able to fulfill the "italic" switch because it can't mix font types like that (I think). I stuck it in the section of my vimrc that is tested for gvim because gvim underlines my spelling mistakes without issue. Give it a try!
if has("gui_running")
#all my gvim settings
else #we're in terminal
hi clear SpellBad
hi SpellBad cterm=bold,italic ctermfg=red
endif

Vim - Force extra spacing between lines for underlining

While using Vim for most of my coding, I typically prefer to have the current line under-lined so it's easier to see where I am in my code. I avoid using things like line-highlighting because it usually makes things harder to see with my bright-text-on-dark-background theme (ie: 'torte' colorscheme).
Here is part of my Vim colorscheme:
hi CursorLine guibg=#0F2130 ctermbg=NONE cterm=underline
hi CursorColumn guibg=#0F2130 ctermbg=darkgray cterm=NONE
I then enable these features in my .vimrc file (ie: ~/.vimrc).
So, in my case, the current line has a colored underline which is the inverted color of the character above it, while the current column has a dark-grey background, while all other text just has a black background.
The only problem I am having here is that I cannot see underscore ('_') characters while coding because the underline for the current line is the exact same color and thickness as the underscore characters. The only workaround, if its even possible, that would make sense here is to:
Increase the spacing between lines
Make the underline appear a few pixels further below my text
Is anything like this possible in Vim (not gVIM)?
Thank you.
If you are using gVim:
:hi! def link CursorLine SpellBad
It will use curl-underline.
Changing the linespace to 10+ will display _ above the Cursorline:
:set linespace=10
#kev: +1; It works in gVIM
However, it seems this just can't happen in Vim, as other commenters have noted.
In the end, I just set the background to be dark grey (ie: ctermbg=253), and then set the cursorline to be darker (ie: ctermbg=black cterm=NONE).
From there, I updated my BASHRC file to contain the following:
export TERM=xterm-256color
This, of all luck, ends up looking better than my previous colorscheme. I now have a modified version of the standard "slate" color scheme with a very dark gray background (ie: ctermbg=253) while the current line has a solid black background.

Completely disable italic text in GVim

In GVim I'm using a fixedsys-like font which looks good, but with italic text it breaks (chars partially unreadable, especially the last italic one if the next one is regular).
For this reason (and because I dislike italic text anyway) I'd like to completely disable italic text in Vim; without modifying any syntax highlighting related files.
When using the highly recommended Solarized theme, you can configure this using:
let g:solarized_italic=0
Whether syntax highlighting uses italic text or not is defined by your colorscheme. Any colorscheme rule can define term, cterm, and/or gui attribute lists, which are described at :help attr-list. You can either clear the relevant colorscheme rules or remove the italic attribute from them.
For example, if the following rule is in your colorscheme
hi IncSearch gui=italic guifg=#303030 guibg=#cd8b60
you would want to simply remove the gui=italic bit. You can also specify not to use any of the attributes from attr-list by setting gui=NONE.
When using the highly recommeded Dracula theme, you can configure this by adding the following to your ~/.vimrc:
let g:dracula_italic = 0
From dracula's documentation
Having issues with font styles (italic, bold, underline)?
Be sure your terminal supports these styles.
If running tmux, see tmux section.
If all else fails, disable the style by setting let g:dracula_<style-name> = 0 in your vimrc, where <style-name> is one of (italic, bold, underline, undercurl,
inverse)

vimrc make comments italic

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?
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.
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.
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.
for GUI environments like gvim, a simple
highlight Comment gui=italic
does it.
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.
Because I'm using the Solarized colorscheme, I had to edit .vim/colors/solarized.vim as recommended in Solarized #120 to replace lines 137-157 with the following:
if has("gui_running") || ( has("unix") && system("tput sitm") == "\033[3m" )
let s:terminal_italic=1
else
let s:terminal_italic=0
endif
That was in addition following the instructions in this Gist and adding these two lines to my .vimrc, using Ctrl-vEsc to enter ^[:
set t_ZH=^[[3m
set t_ZR=^[[23m
(Thanks to Gabriele Lana for the tip to add those lines to my .vimrc.)

Resources