Vim: no highlighting at startup - vim

I am using vim together with NERDTree and MiniBufExplorer. My colorscheme is peaksea. If I start vim, no syntax is highlighted in the first buffer. The other buffers have syntax highlighted. I have "syntax enable" in my vimrc. If I type :edit the syntax gets highlighted. So I tried
autocmd VimEnter * edit
but still nothing is highlighted. Did anyone encounter a similar problem or has anyone an idea how to fix this?

I remapped F12 to redo my syntax highlighting in case it gets messed up:
nnoremap <F12> :syntax sync fromstart<cr>
Maybe you can just run it as an autocmd event in your vimrc based on reading a new buffer?
autocmd BufReadPost * :syntax sync fromstart

Related

How do I map <CR>/<Enter> properly in Vim

I found vimrc key remapping of / in vim-better-default plugin and added to my config.
The remapping works as expected, but this remap also causes an issue with jump using the relative number. For example, when I run 5<CR>, I need to type enter once more for it to work and it only jumps for 4 lines. The output in the bottom display is :.,.+4
I tried adding these but it did not work either.
autocmd CmdwinEnter * nnoremap <CR> <CR>
autocmd BufReadPost quickfix nnoremap <CR> <CR>
Thanks,

Vim spell check does not work with text file

I tried spell check for text file by adding this to my vimrc
augroup set_spell
autocmd!
autocmd FileType text :setlocal spell spelllang=en_us
augroup END
nnoremap <F10> :setlocal spell! spelllang=en_us<CR>
And it did not work
I tried :set spell and nothing happened
For some reasons, when I ran :source $MYVIMRC (still in that window), it worked. Though I can add sourcing command to my vimrc but I don't like the glitchy feeling of it.
What am I supposed to do?
Edit: I have found the solution
It's the problem with this vim rainbow plugin
https://github.com/frazrepo/vim-rainbow
So I uninstall that one and install this instead https://github.com/luochen1990/rainbow
Open the file and immediately do a :set ft? and :set spell?. Make sure they return text and spell respectively. If text is not returned, then the filetype is not being detected. If text is returned but spell is not, then the autocommand is not working.
Additionally, you should wrap autcommands in an augroup. See :h autocmd-groups. It might look like this:
augroup set_spell
autocmd!
autocmd FileType text setlocal spell
augroup END
Because this is a FileType autocommand, you are probably better off skipping the augroup and autocommands altogether and just putting the line setlocal spell in an ftplugin file. It would normally go in ~/vim/ftplugin/text.vim.
As a more general solution: Sometimes theme plugins overwrite SpellBad highlight group(It's one those gui vs terminal problems). Even though spell check works it just doesn't highlight. Without deleting your theme you can just add more style to the SpellBad highlight group as you wish:
Simply add this to your .vimrc:
"underline spell errors in terminals
hi SpellBad cterm=underline
or any other style really:
hi SpellBad ctermfg=Cyan cterm=bold
Be warned, these do not overwrite all existing styles. To truly overwriting it you may need to use hi clear SpellBad first.
See :h highlight for all the details. For the other Spell groups see :h hl-SpellBad.

gVim on Windows: imap does not map ç (cedilla) when read from _vimrc

Weird issue here: I'm trying to avoid the Esc key to exit from insert mode. I stumbled upon this article: http://vim.wikia.com/wiki/Avoid_the_escape_key and I liked the following solution:
" Two letters.
:imap çç <Esc>
When in gVim I type:
:imap çç <Esc>
I does work. But when I try to make it default by putting it in my _vimrc file:
imap çç <ESC>
I doesn't work. It gives me no error, but does not work. Every other letter works, but it seems that specifically the letter ç doesn't.
You could write :
au VimEnter * imap çç <ESC>
in your .vimrc . au is short of autocmd and it is used to tell vim that you want to execute this one as a semicolon command. VimEnter is telling vim to execute it on startup.
The syntax is :
autocmd events pattern command
You could also see the help for autocmd
Try using the following:
Add
scriptencoding utf-8
set encoding=utf-8
at the very beginning of your vimrc.
Be sure that vimrc is saved in UTF-8 itself.

Execute autocommand in vim

I am using SimpleFold for folding vim. I mapped it to a key setting:
map <unique> <silent> <Leader>f <Plug>SimpleFold_Foldsearch
However, I would like to set it up as an auto command. I tried adding this line to my .vimrc file:
autocmd FileType ruby <Plug>SimpleFold_Foldsearch
But, I just get an error now when I open a ruby file. Can anybody help me setup the autocmd so that it works?
:autocmd is executing Ex mode commands, so your code is wrong. You should be using :normal or feedkeys():
autocmd FileType ruby :execute "normal \<Plug>SimpleFold_Foldsearch"

Syntax highlighting changes after save in Vim

I have installed Markdown syntax plugin.
When I'm on a new buffer not associated with any file, and paste the source portion of the site http://rosylilly.github.com/markdown.html into it, the colors appear nicely as it should for the markdown syntax.
However, after saving the file, the colors change. Any idea how I can fix this?
Can you, before and after saving do
:verbose set filetype
:verbose set
Tip: use :redir > file.txt to capture the output so you won't have to copy/paste which can be difficult with gvim - for command output
You could also look at the autocommands when saving:
:verbose au BufWrite
:verbose au BufWritePre
:verbose au BufWritePost
This would serve to discover what plugin/script is causing the highlighting to go haywire.

Resources