I'd like to load a vim syntax theme from .vimrc.
The strange thing is that the theme looks different when loaded from .vimrc as it does when called from within vim with colo molokai_dark.
The .vim file doesn't have if has("gui_running") or t_Co (only in the 256 color terminal support-section) like mentioned here.
Why is that the case and how can I control this behavior?
thx in advance!
You don't mention / show the actual changes, nor your actual configuration, and the colorscheme itself looks good, so I can only offer a workaround:
You can emulate the "from within Vim" via the following autocmd in your ~/.vimrc:
autocmd VimEnter * colorscheme molokai_dark
Related
I would like to set up VIM for Cobol development and wanted to have the lines form column 7 to 11 marked so as to indicate the code areas. However, when I added this line of code in my vimrc file it colorized the NERDTree too.
set colorcolumn=7,11,73,80
autocmd VimEnter * NERDTree
autocmd VimEnter * wincmd p
How can I make the NERDTree columns not colorized and keep colorization only on the working file?
With the following line in your vimrc:
set colorcolumn=7,11,73,80
you define a global value for a window-local option which is reused for every new window. It is set for the 1st window, which passes it on to the 2nd window, etc.
Since that specific value for that specific option only is to be applied to Cobol buffers, you are supposed to use Vim's built-in filetype plugin support:
Make sure you have either of those lines in your vimrc:
filetype plugin on
filetype plugin indent on
filetype indent plugin on
See :help :filetype.
Create after/ftplugin/cobol.vim under your Vim runtime. On a typical Unix system, it should look like this:
$HOME/.vim/after/ftplugin/cobol.vim
And add the line below:
setlocal colorcolumn=7,11,73,80
We use :help :setlocal to make sure that the option won't be passed on to other windows.
When I open up a file in macvim it is like this http://imgur.com/a/3cLqB#0.
I have set ,V to :source ~/.vimrc<CR>.
After I have this file open, I press ,V, and the syntax highlighting changes to this http://imgur.com/a/3cLqB#1.
The difference is that (,),;,, become from blue, white, and ->,.,? become from blue, darker blue.
Why does that happen? This is my vimrc file https://gist.github.com/pvinis/4979592
--
Update: I found out that Valloric/vim-operator-highlight is the plugin that changes the colors. so the first picture is the correct picture.
I also found out, that as soon as i do :syntax on, the colors reset. Is there a way to check if syntax is already on?
Problem:
When reloading .vimrc, some highlight groups are messed up.
It depends on what plugins you have and what colorschemes you are using.
I've noticed that some highlight links were broken, and some highlight groups were cleared.
Affected highlight groups
In my particular setup I've noticed broken hi links or cleared groups on:
SignColumn
GitGutter (which uses SignColumn)
powerline-status (which uses status line)
Notice the affected areas after reloading:
(reloading means saving the modified file. Using :wa in this example)
Solution
Unfortunately the listed answers or any combination of options that I've tried does not preserve or reinstate the hi groups after reloading.
Running manually colorscheme <your-coloscheme> after reloading fixes everything, but when doing it with Vimscript it does not.
Hopefully someone will share a proper solution to this annoying small issue.
Ugly hack
Reloading vimrc:
On any change to my vim config files, I execute reload.vim:
.vimrc:
" .....
augroup reload_vimrc " {
autocmd!
autocmd BufWritePost ~/.vim/*.vim,~/.vim/vimrc source ~/.vim/reload.vim
augroup END " }
reload.vim: restores broken links and cleared groups
What we have to do is to reinstate the hi groups after sourcing vimrc.
To find the correct values for an affected area, e.g. for SignColumn, type:
:hi SignColumn, BEFORE any reloading has occurred.
The outcome is (where xxx is a preview):
You have to do this for every affected hi.
In the following snippet I initially fix SignColumn to match my solarized colorscheme.
Then I fix some GitGutter color issues:
e.g., GitGutterAdd is linked to GitGutterAddDefault which is preserved, but from GitGutterAddDefault to DiffAdd is broken, so I reinstall that one. And so on so forth.
reload.vim:
source ~/.vim/vimrc
hi SignColumn ctermfg=12 ctermbg=0 guifg=Cyan guibg=Grey
" GitGutterAdd -> GitGutterAddDefault (preserved)
hi link GitGutterAddDefault DiffAdd
" GitGutterChange -> GitGutterChangeDefault (preserved)
hi GitGutterChangeDefault ctermfg=3 ctermbg=0 guifg=#bbbb00
" GitGutterDelete -> GitGutterDeleteDefault (preserved)
hi GitGutterDeleteDefault ctermfg=1 ctermbg=0 guifg=#ff2222
" GitGutterChangeDelete -> GitGutterChangeDefault (preserved)
" (which we already fixed above)
" Powerline highlight groups
" (see this attached Gist for solution)
Everything works as it should:
Fixing powerline-status colors:
This one is a bit more tricky, but the principle is the same. All highlight groups of powerline start with Pl_. But some of them might not exist yet. For example, if you haven't entered visual mode yet, then the respective groups for visual mode won't be populated yet. So, enter insert, visual, and normal modes to populate the groups and then copy them. You can find them at the bottom of the output of the hl command. Then, paste them in your reload.vim and adapt them to be legit hl commands.
It may sound like a lot of work but it isn't.
Here's a gist with the full reload.vim, and some gifs to guide you through.
I had something very similar to this happening. I was able to solve it by making sure these were in the correct order:
syntax on
let g:solarized_termtrans=1
let g:solarized_termcolors=256
set background=dark
colorscheme solarized
I also used this for reloading
augroup reload_vimrc
autocmd!
autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END
With those two I could do live updating of my vimrc without having to reload. I am using iTerm2 with Terminal vim. Hopefully this helps someone else out as I have spent quite a bit of time trying to get this live reloading working. Also make sure you have the newest versions of the solarized theme. I know it seems mundane to mention but it might make a difference.
I guess that the highlightings are defined / changed by some plugin. The re-execution of :colorscheme resets those definitions. The plugins would have to hook into the ColorScheme event with an :autocmd, but most don't.
To work around this, try wrapping the :colorscheme in a guard:
if ! exists('g:colors_name') || g:colors_name !=# 'Tomorrow-Night-Eighties'
colorscheme Tomorrow-Night-Eighties
endif
This works for me
"auto reload vimrc once changed
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
" This fixes the color changes and things not working :D
autocmd! BufWritePost .vimrc filetype plugin indent on
endif
I have absolutely no idea why, (probably for the same reason that doing :source ~/.vimrc manually works) but for me replacing
autocmd BufWritePost *vimrc,*exrc :source %
with
autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\<cr>")
fixed the problem.
autocmd BufWritePost *vimrc,*exrc :call feedkeys(":source %\<cr>")
Fixed it right away for me. Must be some weird issue with the ordering. I also have a keystroke to resource the file and this always works even when the autocmd was failing.
Most likely unrelated to your particular case, but I had a similar problem so I thought I'd share since it's the first StackOverflow result on Google.
My issue with reloading was in two phases: using the dark Solarized theme, reloading .vimrc would first change the colors slightly, then, reloading a second time, it would switch to the light Solarized theme.
The lines about colors in my .vimrc were:
set background="dark"
let g:solarize_termcolors=256
colorscheme solarized
The problem? The first line shouldn't have quotes:
set background=dark
I can now reload .vimrc without changing the colors. I'm not sure why it would work one time and work a different way after though. I realized that after commenting out everything but these lines as others have suggested.
set syntax enable after colorscheme
The question is really simple, when i run TagbarToggle i want the cursorline option to be True in that window (if it is in the "main" window).
something like:
if &cursorline
call set_cursorline_in_tagbar()
endif
Of course i could just set it manually every time, but that's just not the Vim way.
It looks like TagBar sets its own FileType: tagbar, this could be used in an autocmd:
autocmd FileType tagbar setlocal cursorline
Another option would be to set a custom highlighting for TagBar's own syntax groups that fits your need, as shown in the documentation.
I managed to fix it, for some reason TagBar sets nocursorline in the initWindow() function
I simply replaced it with cul. And now everything is working as it should.
But why would he set nocursorline?
I noticed that with different colorschemes VIM is underlining/highlighting some words. Why is this and how to turn it off ?
with another colorscheme
I'm using spf13-vim configuration and connecting remotely with Putty.
VIM is correctly assuming this file to be a python file (:set filetype returns "python")
It seems like your Vim is doing spell-checking for you. You can turn this off by adding
set nospell
in your .vimrc file. To turn it back on in a file, you can do:
:setlocal spell spelllang=en_us
for spell-checking with American English. :setlocal changes settings for current buffer, while :set makes the changes for all currently open buffers. You can read more about how spell-checking with Vim works here.
It may be useful for you to automatically enable spell checking for certain files. For example, to enable spell checking in .tex files, you can add the following to your .vimrc:
" Enable spell checking when opening .tex files
autocmd!
au BufNewFile,BufRead *.tex setlocal spell spelllang=en_us
" Or if you have filetype detection enabled:
" au FileType tex setlocal spell spelllang=en_us
Note that autocmd! clears the previously defined au commands and is needed only once.
Most filetypes (like python) in Vim come with a syntax that defines highlight groups (see them via :highlight). A colorscheme then provides combinations of foreground / background color and/or formatting like bold and italic, for terminals, color terminals, and/or GVIM.
Choose a colorscheme that you find visually appealing; some come with Vim, many more can be found on the Internet, most at http://www.vim.org/.
If you're just annoyed by one or two minor things in a particular colorscheme, you can modify the items via the :highlight command. To disable a highlighting, use, e.g.
:highlight clear Statement
or (when the group is linked to another group, effectively inheriting its appearance)
:highlight link Statement NONE
(These must be issued after the :colorscheme command that sets your preference.)
I have came across two kinds of highlight that I don't like.
1.indent highlight and tab arrow reminder, you can solve it by adding
let g:indent_guides_enable_on_vim_startup = 0
set nolist
to ~/.vimrc.local
2.highlight the usual words, like Chinese words and wrong spell words, you can solve it by adding
set nospell
to ~/.vimrc.local
The one IDE feature that I always missed and invariably plug into vim is tab completion.
I'm a big fan of SuperTab, but one thing I can't stand is the fact that it treats the parts of CSS class names and IDs with dashes as individual words.
I've found a couple of possible solutions for camelCase and underscore_completion but I can't seem to find anything that supports plain-old-dashes.
This is not a CSS-specific problem: Vim uses the value of iskeyword to perform completion.
Type :set iskeyword? to see what characters are considered to be part of keywords. The default on a Mac is supposed to be #,48-57,_,192-255.
You can add the dash to the list with this command:
:set iskeyword+=-
Add this line to your ~/.vimrc to make this setting stick:
set iskeyword+=-
This seems to work for me:
autocmd FileType css,scss set iskeyword=#,48-57,_,-,?,!,192-255
Taken from here: VIM: How to autocomplete in a CSS file with tag ids and class names declared in HTML file
For future readers: if you want the benefits of dashes for edit/movement commands, but want full property autocompletion, try adding this to your .vimrc:
augroup css_dash_autocompletion
autocmd FileType scss,css autocmd! css_dash_autocompletion InsertEnter <buffer> set isk+=-
autocmd FileType scss,css autocmd css_dash_autocompletion InsertLeave <buffer> set isk-=-
augroup END
The first ! prevents duplicate event firing. Thanks to ZyX for the structure. If you re-source your .vimrc, you will need to :e any (S)CSS files you have open to pick up the change.