Lua nvim_command highlight not working unless manually run - vim

I have the following line at the very end of my init.lua
vim.api.nvim_command('hi CursorLineNr guibg=bg')
But it doesn't work. When I launch nvim, the CursorLineNr highlight group is still wrong. And yet, when I manually type :hi CursorLineNr guibg=bg, it works.
I'm not sure if this has to do with any Packer plugins finishing execution after the very last line of my init.lua or something?

I have no idea if this is "correct", but it worked for me:
vim.api.nvim_command[[
autocmd ColorScheme * highlight CocErrorSign guifg=#bf616a
]]

Make sure to put highlight settings after the colorscheme is set in your init.lua because it resets the highlight.
vim.cmd("colorcheme gruvbox")
vim.cmd("hi CursorLineNr guibg=bg")
In this order

Related

vim remove underline from line number

I upgraded vim (macOS) using brew:
$ brew info vim
vim: stable 8.1.2100 (bottled), HEAD
After the upgrade, the line numbers at the right are underlined, for example, from the attached picture line number 1 appears like 1_____, any idea how to remove the underline?
Happens only when having :set relativenumber
Latest versions defaults to underline: https://github.com/vim/vim/blob/017ba07fa2cdc578245618717229444fd50c470d/src/highlight.c#L256
CursorLineNr term=bold cterm=underline ctermfg=Yellow gui=bold guifg=Yellow
My templates was using only:
hi CursorLineNr term=bold ctermfg=012 gui=bold
The fix was to define cterm:
hi CursorLineNr term=bold cterm=bold ctermfg=012 gui=bold
I found the fix for this in the .minttyrc as this was driving me crazy as well.
There is a setting in there for Term=vt100
Edit the .minttyrc in your home dir and comment out or remove the line
Term=vt100.
Save the file and close the CLI and reopen a new one. The underline should now be gone from vi from then on. I hope this helps.

Set working in file but not in .vimrc

When I put set scroll=10 in my .vimrc it does not work, but it does work when I enter the command in command mode.
I have many other commands in my .vimrc, what reason could there be for this set to not be getting through? It is the last line in my .vimrc.
:verbose set scroll?
should tell you which plugin script has last modified that option. If you don't find the culprit this way, you could workaround by setting it at the last possible moment by putting this in your ~/.vimrc
:autocmd VimEnter * set scroll=10

jshint vimrc SpellBad customization does not stick

Using
" Customize jshint highlights
hi clear SpellBad
hi SpellBad cterm=underline,bold ctermfg=white ctermbg=black
I was able to customize my jshint SpellBad highlights to the colors I desire when I first open a buffer containing jshint errors. As can be seen here, my background is black and the line with the error is in bold white and underlined. Exactly as I specified using those definitions in .vimrc above.
The problem is, when I switch around between buffers or open a that buffer later again, my custom jshint SpellBad colors no longer apply and I get the "default" colors which I do not want.
Why is this so? And how do I make my custom jshint SpellBad colors stick?
Because your custom highlight settings will be cleared after every :colorscheme commands.
try:
autocmd ColorScheme * hi clear SpellBad
\| hi SpellBad cterm=underline,bold ctermfg=white ctermbg=black

Why does mvim clear highlight groups on startup?

I recently started using vim-makegreen with mvim.
The issue is that the red/green bars do not work with mvim. They do work with mvim -v (or otherwise console vim).
After further investigation it appears that the highlight groups that are defined as:
hi GreenBar term=reverse ctermfg=white ctermbg=green guifg=white guibg=green
hi RedBar term=reverse ctermfg=white ctermbg=red guifg=white guibg=red
within makegreen.vim are cleared by mvim just prior to calling the .gvimrc file. After mvim has started I get:
:hi RedBar
RedBar xxx cleared
:hi GreenBar
GreenBar xxx cleared
Does anyone have any insights into why mvim is clobbering highlight groups? The only work around that I have found thus far is to redefine them again inside .gvimrc. But this is clearly a pain. Trying to figure out if I am missing something here.
Update
I just stripped down my .vimrc and using pathogen I only place makegreen in bundle dir. The result is the same behavior.
My .vimrc has only one line:
call pathogen#infect()
The bundle directory only contains makegreen bundle. The autoload directory only has the pathogen.vim. I removed .gvimrc.
I then start mvim and execute :hi RedBar and get the same result as above. I used an echo statement to confirm that makegreen.vim is being sourced.
I installed mvim with brew install macvim. The version of macvim is 7.3(64) and I am on OSX Lion.
Update 2
I just took it a step further and removed the reliance on pathogen. Now I only have makegreen.vim in plugin directory and an empty .vimrc file. Same result.
Add let macvim_skip_colorscheme=1 to your ~/.vimrc. See the comment before the colorscheme is loaded in your global gvimrc:
" Load the MacVim color scheme. This can be disabled by loading another color
" scheme with the :colorscheme command, or by adding the line
" let macvim_skip_colorscheme=1
" to ~/.vimrc.
if !exists("macvim_skip_colorscheme") && !exists("colors_name")
colorscheme macvim
endif
All color schemes clear the highlights.
I had the same problem.
The workaround was to redefine GreenBar and RedBar in ~/.vimrc (or python.vim, etc.)

Set vim colorscheme in modeline

I'm trying to set my colorscheme in the modeline. I tried it a few ways, but none of them works. I get an "Unknown option: colorscheme" error.
# vim: colorscheme dark_foo:set ft=foo:
How can it be set in the modeline?
The modeline consists of option settings. There is no "colorscheme" option. colorscheme is just a command that essentially executes "runtime colors/foo".
You can get an approximation of what you're asking for by creating an autocmd that sets your colorscheme and is triggered by some option that is actually settable in your modeline.
detailing answer of Laurence, example: force js highlighting:
first line of file you want to get the intended highlighting: # vim: ft=javascript
If you want you can then deviate from the default colorscheme via .vimrc:
autocmd FileType javascript colorscheme badwolf

Resources