How can I make hard-coded strings heinous-looking in VIM? - colors

I was inspired by this (number 2) to make my hard-coded strings ugly.
How can I do this in VIM?

The language-based files are stored in $VIMRUNTIME/syntax, one .vim file per language, so that's where you need to go to change things.
For example, my C file is stored in C:\Program Files\Vim\vim70\syntax\c.vim and, if you add the following line near the end, before the let b:current_syntax = "c", you'll get the exact effect you require:
hi String guifg=#ff0000 guibg=#ffff00
For text-based VIM, the ctermfg and ctermbg options need to be used instead, something like:
hi String ctermfg=Red ctermbg=Yellow
I haven't tested these since I only use gvim nowadays.

In your .vimrc:
highlight String guifg=1 guibg=11

highlight clear String
highlight link String Error
A bit over the top IMO, so you might want to not make it permanent.

Related

How to change specific 'theme' colors in vim

I would like vim to roughly match the color scheme of a python file in textmate. Here is a comparison of the two:
For example, I want a comment to be blue instead of red. If I have the hex codes for each of these colors, is there a place that I can change this in the vimrc or somewhere else? For example, how would I pass a hex code into the vim colorscheme:
" syntax highlighting
hi Comment cterm=NONE ctermfg=#ddd gui=NONE guifg=#ddd
hi Constant cterm=NONE ctermfg=DarkGreen gui=NONE guifg=green3
I was able to achieve what you wanted in two different ways, the first one was much simpler, I just added
hi Comment guifg=#ddd
into my vimrc just after the colorscheme [colorscheme name].
The second method is better for a big amount of changes and it's much harder. It bases around changing your colorscheme. You would do as follows:
Check what's your current colorscheme, by typing the command :colorscheme while in vim. if it's one of the defaults (blue.vim, darkblue.vim, default.vim, delek.vim, desert.vim, elflord.vim, evening.vim, industry.vim, koehler.vim, macvim.vim, morning.vim, murphy.vim, pablo.vim, peachpuff.vim, ron.vim, shine.vim, slate.vim, torte.vim, zellner.vim), then you need to go to $VIMRUNTIME/colors and edit which is yours. Otherwise check your ~/.vim directory for "colors" or search where you store plugins for the name of your theme. For example if you use vim-plug then plugins and themes are stored in ~/.vim/plugged. Copy the folder to not mess up the original theme and use a different name.
2.After opening the folder of your theme open the only file in it - [theme].vim and search for the item you want to change, e.g. "Comment", change the hex value of the color, background etc.
Repeat to your liking to the time you'll get your theme looking how you want it to.
Set your colorscheme via colorscheme [name-you-picked-earlier]
The second option is also useful for creating full themes suited just to you.

Highlighting and syntax trouble in vim using rmarkdown

I would like to get Vim to stop highlighting list characters (-,*) and heading characters (#) in rmarkdown. You can find a screenshot here: https://imgur.com/a/0YSB8V8.
This is happening when I set the file type to either pandoc or rmd. This is also happening no matter what terminal or colortheme I use.
I have the plugins: vim-pandoc, vim-pandoc-syntax, and vim-rmarkdown installed.
I would like to know a way to make the two characters just appear normally.
I would also like to know if there is a way to make italicized text in tables and headings appear italicized. As far as modifying the appearance of italicized text, I've tried using: hi Italic ctermfg=red cterm=italic in my vimrc, but that does not seem to affect the text in between asterisks (*) in rmd files. I admit I don't know much about the way that syntax works in Vim. Do I need to modify after/ftplugin/rmd.vim or runtime/syntax/rmd.vim? What is the difference between the two?
Any help would be appreciated!
Your syntax highlighter does not seem to recognize the bullet points, but thinks that they mark the beginning of an italic span. Maybe you have a clash of plugins. You could also try another highlighter (e.g. vim-polyglot, supports italics).
vim-pandoc-syntax uses the conceal feature (:h conceal). You can recolor the highlighting group Conceal to change the appearance of the replacement characters.
You can put changes to existing syntax files in .vim/after/syntax/rmd.vim. Files in syntax are executed when they are needed for the first time, but at most once per session. Files in ftplugin are executed every time the file type is changed.

gvim: Colour lines differently containing TODO/HACK/etc?

Often I'll put comments in code like TODO/HACK/BUG: I'd love if these showed up glaringly when I did a diff of the code in vim.
Is there an easy way to set this up?
You can define a syntax group like this:
:syntax match TODOs ".*TODO.*\|.*BUG.*\|.*HACK.*"
This will match entire lines which contain either TODO, BUG or HACK in them.
Then you can use the highlight command to highlight it.
:highlight TODOs ctermbg=red ctermfg=yellow term=bold,italic
You can add both the lines to your vimrc or the syntax file for appropriate file types.

Getting hilighting in a vim color file

I'm trying to edit my colour scheme in vim, and I remember when I was using Fedora I could get an easy preview of the colour when I changed it.
If I had a line like:
let ColourAssignment['String'] = {"GUIFG": 'LightYellow', "CTERMFG": '118'}
The word ColourAssignment would get hilighted as the colour I set 'string' to.
I'm using a mac now, but I have the same plugins and .vimrc as I had when using fedora.
Does anyone know what I need to set, or what plugin I could use to get this behavior again?
It's not exactly what you ask for (it highlights the colors themselves, not the highlight group name), but I can highly recommend the Colorizer plugin.
Maybe you want :hi String guifg=LightYellow ctermfg=118 and :syn match String /ColourAssignment/?
Alternatively, there are online Vim colorscheme editors, such as:
http://bytefluent.com/vivify/
http://www.vimtax.com/
I found the exact solution I was looking for, it turns out there is a syntax file included with the bandit colour scheme that allows for this functionality.
The repository is:
https://github.com/vim-scripts/bandit.vim

How do I make vim syntax highlight a whole line?

I'd like to have vim highlight entire lines that match certain patterns. I can get all the text in a line to highlight (by doing syn match MyMatch "^.*text-to-match.*$"), but it always stops at the end of the text. I'd like to to continue to the end of the term, like highlighting CursorLine.
I've tried replacing $ with a \n^, hoping that would wrap it around. No change. (I didn't actually expect this would work, but there's no harm in trying.) I also tried adjusting the syn-pattern-offset (which I read about here: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:syn-pattern). Long story short, adding he=he-5 will highlight 5 fewer characters, but he=he+5 doesn't show any extra characters because there aren't characters to highlight.
This is my first attempt at making a vim syntax and I'm relatively new to vim. Please be gentle and include explanations.
Thanks!
(edit: Forgot to include, this is a multiline highlight. That probably increases the complexity a bit.)
It's not very adaptive as the filename (buffer) and line to full row highlight needs to be explicitly identified, but apparently the sign command can be used:
It is possible to highlight an entire
line using the :sign mechanism.
An example can be found at :help
sign-commands
In a nutshell:
:sign define wholeline linehl=ErrorMsg
:sign place 1 name=wholeline line=123 file=thisfile.txt
Obviously, you should pick a higlight
group that changes the color of the
background for the linehl argument.
source: Erik Falor, vim mailing list
From the documentation on syn-pattern:
The highlighted area will never be
outside of the matched text.
I'd count myself surprised if you got this to work, but then again, Vim is always full of surprises.
could also try
:set cursorline
:set cursorcolumn
change colors like this:
:hi cursorline
:hi cursorcolumn
using the usual term=, ctermfg=, ctermbg= etc
see this answer
VIM Highlight the whole current line

Resources