Vim/YCM - change warning highlight color - vim

I'm using the YouCompleteMe plugin for vim on Mac OSX, primarily for C++. Right now it highlights both errors and warnings in a pinkish color, but I want warnings to be highlighted in a yellow-ish sort of color. I think I'm supposed to place these 3 lines somewhere:
highlight YcmWarningLine guibg=#ffffcc
highlight YcmWarningSign guibg=#ffffcc
highlight YcmWarningSection guibg=#ffffcc
Problem is I don't know which file to place them in. Where do I place them, and in general am I going about this the right way?

Highlight groups are global, only the syntax definitions that parse individual filetypes are specific. Syntax scripts canonically use :hi def to avoid overriding group definitions already customized by the user. Therefore, it is sufficient to place those commands into your ~/.vimrc, but after any :colorscheme command.
If you switch colorschemes on the fly (without restarting Vim), you'll notice that your custom highlightings will disappear. To keep them, you additionally need to reinstall them. Duplicate the :hi commands and prepend
:autocmd ColorScheme *
to them.

Those and other vim configuration settings should be added to your ~/.vimrc.

Related

How to use different colorscheme and syntax highlighting in vim?

Suppose I want to use this colorscheme:
https://github.com/NLKNguyen/papercolor-theme
I copied the PaperColor.vim file into .vim/colors and made my .vimrc:
syntax on
colorscheme PaperColor
background=light
Now, I want to use this syntax highlighting for haskell files: https://github.com/raichoo/haskell-vim/tree/master/syntax
There are two syntax highlighting files. Which one am I supposed to use, and where do it put them?
Thanks!
Do I put it in ./vim/syntax and vim auto-loads all files in ./vim/syntax folder?
It seems like to load haskell.vim automatically. But doesn't load cabal.vim. Wondering if it only loads haskell.vim when I open .hs files? I'm trying to make it like that. Can vim load multiple syntax files at once?
TL;DR: Everything's (mostly) fine. There's a difference between colorschemes and syntax scripts.
Most filetypes (like python) in Vim come with a syntax that defines highlight groups (see them via :highlight python<C-d>). These particular groups (e.g. pythonFunction) are then linked to a set of default groups (:help highlight-groups, e.g. Identifier). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic (separately for terminals, color terminals, and/or GVIM) for the default groups.
highlight group → default group → color + style
pythonFunction → Identifier → term=underline ctermfg=3 guifg=DarkCyan
So, for a set of beautifully matching colors that please your personal taste, you choose a colorscheme. For you, that would be colorscheme PaperColor. Note that the background needs to be set before choosing the color (and you've missed the :set command):
syntax on
set background=light
colorscheme PaperColor
The syntax scripts know how to parse a certain syntax (for you: both haskell and cabal; what gets activated depends on filetype detection, which usually does the right thing, but you could also manually override it (:setlocal syntax=cabal); I think the former is for Haskell source code while cabal is a package definition). They basically recognize certain syntax elements, and link them to generic highlight groups (like Statement, String, Comment, and so on). Now how these are then colored (e.g. bold green) is determined by your chosen colorscheme.
As you can see, colorschemes and syntax scripts each have a distinct role, and play together. While the former is a global personal choice, the latter is activated based on the detected filetype, which is different for each buffer.

Highlighting set of specific keywords in gvim

I have tried highlighting specific words by adding them in .vimrc, colorscheme file and also in syntax.vim(I changed one at a time, not altogether).
syn match mygroupwords '\c\<\(-word1\|-word2\)'
hi def link mygroupwords colo_words12
hi colo_words12 guifg=red1 gui=bold guibg=white
But somehow it seems to be getting overwritten by default syntax highlighting
i need to highlight keywords irrespective of color-scheme or file-type which have following words-
Ex; -word1 , -word2
Any suggestions?
explanation of your failed attempts
A colorscheme just provides color definitions for predefined highlight groups; that's the wrong place for actual syntax matches! ~/.vimrc is the first configuration that is read; if a filetype is detected and a corresponding syntax script is loaded, that will override your syntax definition.
syntax extensions
If your desired highlightings are extensions to an existing syntax, you can place :syntax match commands in a syntax script in the after directory. For example, to extend Python syntax, put it in ~/.vim/after/syntax/python.vim. That may still fail if the original syntax obscures the match; sometimes, this can be solved via containedin=...
independent marks
If your highlightings are independent of syntax and filetype, there's a different built-in mechanism: :match (and :2match, and additional variants via :call matchadd(...)):
:match mygroupwords /\c\<\(-word1\|-word2\)/
This goes on top of (and is independent of) syntax highlighting. However, it is local to the current window. So, if you put this into your .vimrc, it will only affect the first window (but any files viewed in there). To apply this globally to window splits and tab pages, you have to use :autocmds. It's not trivial to get this totally right. If you need such a full solution, have a look at my Mark plugin; this supports multiple colors, allows presetting with :[N]Mark /{pattern}/ (similar to :match), and highlights in all windows.

Set colors for custom syntax keywords in Vim?

I'm using a syntax file in vim that defines a number of filetype-specific syntax keywords. To color files of this type I've also created a colorscheme file for the share directory that attempts to highlight these syntax keywords, however they don't take effect when I open files of that extension.
My color file does however highlight normal groups such as Normal, Special, Comment, etc. As well, when I attempt to move these highlight commands to my .vimrc file, they still have no effect. However, after the file is loaded in vim, entering the highlight commands manually works as intended.
Is there something special I need to do in order to use syntax keywords defined in the syntax files? Do I maybe need to specify the load ordering of my syntax files & color files in my .vimrc?
EDIT: using :scriptnames, I am able to see that my custom colorscheme file loads long before the syntax file, which in fact loads dead last. However, my .vimrc file specifies the colorscheme CustomPersonal as the last line, far after syntax on.
Vim has a built-in mechanism for overriding syntax groups, so if you do everything right (even in your ~/.vimrc), this should work. The solution suggested by #MatthewStrawbridge might work, but feels wrong, because colorschemes are global in Vim, and therefore shouldn't be specified in an ftplugin.
Here's how the overriding works:
Most filetypes (like python) in Vim come with a syntax that defines highlight groups (see them via :highlight). These particular groups (e.g. pythonFunction) are then linked to a set of default groups (:help highlight-groups, e.g. Identifier). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic (separately for terminals, color terminals, and/or GVIM) for the default groups.
highlight group → default group → color + style
pythonFunction → Identifier → term=underline ctermfg=3 guifg=DarkCyan
So, for a set of beautifully matching colors that please your personal taste, you choose a colorscheme. In order to tweak some particular associations, you can change the linking of highlight group to default group, e.g.:
:hi link pythonFunction Special
This can already be done in ~/.vimrc. As long as the syntax script correctly uses :hi def link, the original link established by you will be kept; the def[ault] parameter ensures that the link will only be created if no link exists yet.
Your .vimrc will be run when you first start Vim; the syntax file won't be applied until the file loads, and it sounds like it's overriding your settings.
Instead you could put your custom color scheme in ~/.vim/after/syntax/<filetype>.vim instead of CustomPersonal.vim (or at least call it from there).
Another alternative would be to add an autocmd to your .vimrc to source CustomPersonal.vim in response to a suitable event.

How do you set up formatting in vim?

Earlier, when I used open .py files in vim on ubuntu, they would be well formatted, with separate colours for separate segments of the program. Now, when I am using VIM on ubuntu, all the text in the .py file appears black. How can I correct this?
Formating in Vim means text formatting; e.g. indenting lists and breaking long lines. You're concerned about syntax highlighting, which is purely about the visual appearance of code.
First, it needs to be turned on.
:syntax on
does that.
Second, you probably want Vim to automatically detect the used language (e.g. Python) and choose the correct syntax plugin for you.
:filetype on
does that, though you usually enable more via :filetype plugin indent on.
To make these settings persistent, put them into your ~/.vimrc configuration.
Check man vim. In a nutshell, find a copy of a vimrc file, one might be under /usr/share/vim/ subtree. It may be named vimrc_example.vim. Copy to your home directory and rename it as .vimrc.

Can you remove default color schemes from vim in a vimrc?

I've reduced the number of custom color schemes in vim to the bare minimum of great ones, but I still have all of the crazy defaults, like elflord, which I'd rather not have to tab through. Can I remove these without hacking my MacVim install and having to do it in the next update?
Obviously this is splitting hairs, but configuring my .vimrc in the first place is splitting hairs.
tmcw,
My installation of vim73 has the colors stored in \path\to\vim\vim73\colors.
In there I see elflord.vim and a host of other files.
Presumably removing them from this directory should remove them altogether.
Then, you can just tab through whatever you want.
Edit: If you want to have something that goes in and removes the files from the colors directory after an update, perhaps you may have to write a script to manage that--I'm not really sure.
HTH
I presume you are tabbing through your colorschemes for editing different filetypes? why not just set up your colorscheme preference in corresponding filetype-specific entries using autocmd FileType or via individual vim files in the ftplugin directory. Make sure you have filetype plugin on
How many colorschemes do you actually use? If it's just a few (and you really need to change them frequently, like whether it's dark or bright daylight), I'd define shortcut commands, like:
command -bar Col1 colorscheme default
command -bar Col2 colorscheme darkblue
You could remove the colorschemes from $VIMRUNTIME/colors/, but you're right about having to do this after every Vim upgrade.
A (complex) alternative would be writing a custom :Colorscheme command, with a custom completion that uses something like a blacklist to suppress certain schemes. As a bonus, with the cmdalias plugin, you could even overwrite the original :colorscheme command, to make this fully transparent.

Resources