I've been setting up my init.vim file to use NeoVim on Windows 10, and ran into an issue I'm struggling to understand.
At the start of my file, I set up a couple of :hi(ghlight) autocmds, and only the VertSplit seems to be ignored on starting. Even worse, I can run the command in the vim cmd bar and it'll work just fine.
Here's a snippet:
set wildmenu
set wildmode=longest:full,full " get bash-like tab completions
"set cc=120 " set an 80 column border for good coding style
filetype plugin indent on " allows auto-indenting depending on file type
set tabstop=4 " number of columns occupied by a tab character
set shiftwidth=4 " width for autoindents
set softtabstop=4 " see multiple spaces as tabstops so <BS> does the right thing
set number
set mouse=a
set undofile
set cursorline
set splitright
autocmd VimEnter :set laststatus 3<CR>
" THIS WORKS
autocmd VimEnter :hi CursorLine cterm=None guifg=#5c6773<CR>
" THIS DOESNT
autocmd VimEnter :hi VertSplit cterm=None guifg=#5c6773<CR>
Any help/advice on this? I've been googling but can't find anything about VertSplit or similar. Can also post the full conf if needed.
Thanks in advance!
It's really not a matter of googling. It's a matter of studying the documentation for the thing you are about to use and then, applying what you learned.
First, an autocommand is supposed to be made of at least these elements:
autocmd <event> <pattern> <command to execute when the pattern matches>
but you didn't specify a pattern for any of your three autocommands. This is easily fixable:
autocmd VimEnter * :set laststatus 3<CR>
autocmd VimEnter * :hi CursorLine cterm=None guifg=#5c6773<CR>
autocmd VimEnter * :hi VertSplit cterm=None guifg=#5c6773<CR>
Second, the <command> part is always an Ex command so you can drop the useless colon:
autocmd VimEnter * set laststatus 3<CR>
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773<CR>
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773<CR>
and the useless—and very likely to cause errors down the line—<CR>, which is really only useful in normal mode mappings:
autocmd VimEnter * set laststatus 3
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773
Now that your autocommands actually look like autocommands, you should address the last remaining issue: set laststatus 3, which:
prints the current value of laststatus,
throws an "Unknown option" error for 3.
Number options are set like this:
set optionname=999
so set laststatus 3 should be:
set laststatus=3
Which leaves you with this mostly correct (and working, at least in my Vim) snippet:
autocmd VimEnter * set laststatus=3
autocmd VimEnter * hi CursorLine cterm=None guifg=#5c6773
autocmd VimEnter * hi VertSplit cterm=None guifg=#5c6773
Related
I am using Vim 8.2. I would like to change the color of the StatusLine when I enter Command Line mode with / and :.
I have the following in my .vimrc. It is supposed to change the background and foreground colors of the StatusLine of the current window and the not-current windows
augroup InsertHook
autocmd!
" enter command line mode
autocmd CmdlineEnter * hi StatusLine gui=bold guifg=#7386A7 guibg=#FFE847
autocmd CmdlineEnter * hi StatusLineNC gui=NONE guifg=#FFE847 guibg=#9EA8BA
" leave command line mode
autocmd CmdlineLeave * hi StatusLine gui=bold guifg=#EFEEC9 guibg=#7386A7
autocmd CmdlineLeave * hi StatusLineNC gui=NONE guifg=#DFDBC5 guibg=#9EA8BA
augroup END
This kinda works, but only when I enter Command Line mode with a / and then type something. It does not work when I enter Command Line mode with a :.
I have played around with the above snippet of code, substituting CmdwinEnter and CmdwinLeave for CmdlineEnter and CmdlineLeave, respectively; and I have also tried CmdlineChanged, but I cannot get the color of the StatusLine to change instantly when entering Command Line mode with both : and /.
Any ideas?
Controlling the highlighting of the status line is unfortunately not that straightforward.
Here is a hack that changes the status line highlight for every window when you enter/leave the command line:
hi CmdlineEnter ctermbg=green ctermfg=white
hi CmdlineLeave ctermbg=blue ctermfg=white
augroup cmd
autocmd!
autocmd CmdlineEnter * let &statusline = '%#CmdlineEnter#%f'
autocmd CmdlineLeave * let &statusline = '%#CmdlineLeave#%f'
augroup END
I am not sure how it could be changed so that it only highlights the status line of the current window, though.
As you will see from my vimrc file below I am trying to 'set number' on InsertEnter. In normal mode I use 'set relativenumber' to make it easier to more around with j,k. The config below work on my macbook but not on a RHEL box i'm running. Instead of doing 'set number' for the whole file when I enter Insert mode it sets number only for the line I am on. The rest of the file lines continue to display as relativenumbers.
How do I fix this? Any idea what is going on here?
execute pathogen#infect()
call pathogen#helptags()
syntax on
syntax enable
filetype plugin indent on
colorscheme molokai
set rnu
autocmd FocusLost * :set number
autocmd FocusGained * :set rnu
autocmd InsertEnter * :set number
autocmd InsertLeave * :set rnu
set rtp +=/home/evolution/.vim/bundle/powerline/powerline/bindings/vim
set splitright
set ttymouse=xterm2
set backspace=2
set laststatus=2
set t_Co=256
set laststatus=2
set showtabline=2
set noshowmode
set nocompatible
set background=dark
set shiftwidth=4 " operation >> indents 4 columns; << unindents 4 columns
set tabstop=4 " a hard TAB displays as 4 columns
set expandtab " insert spaces when hitting TABs
set softtabstop=4 " insert/delete 4 spaces when hitting a TAB/BACKSPACE
set shiftround " round indent to multiple of 'shiftwidth'
set autoindent " align the new line indent with the previous line
set cursorline
hi CursorLine cterm=NONE ctermbg=52
let g:CommandTAcceptSelectionMap = '<C-t>'
let g:CommandTAcceptSelectionTabMap = '<CR>'
let g:airline#extensions#tabline#enabled = 1
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
map <C-l> :tabn<CR>
map <C-h> :tabp<CR>
I found that this works:
set rnu
function ToggleNumbersOn()
set rnu!
set nu
endfunction
function ToggleRelativeOn()
set nu!
set rnu
endfunction
autocmd FocusLost * call ToggleNumbersOn()
autocmd FocusGained * call ToggleRelativeOn()
autocmd InsertEnter * call ToggleNumbersOn()
autocmd InsertLeave * call ToggleRelativeOn()
Replace the autocommand with set number by set nornu
set nu
autocmd InsertEnter * :set nornu
autocmd InsertLeave * :set rnu
Mark as fixed when fixed
You may be interested in Vim 7.4 hybrid relative-absolute number mode.
set relativenumber
set number
This will show relative numbers but what would be zero will be the current line number.
However if that won't work for you then there are a few plugins that do what you ask: numbers.vim and numbertoggle
In my vimrc file i have this option set cursorline. I want to hide this line if that window is not in focus . Is there an option in vim to do that?
See this
Essentially, it's just the following autocmds:
augroup CursorLine
au!
au VimEnter * setlocal cursorline
au WinEnter * setlocal cursorline
au BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
But occasionally, you may want to define exceptions (i.e. permanently on or off) for certain windows. That's where my CursorLineCurrentWindow plugin may be helpful.
It sounds like you want the cursorline on when entering a vim buffer and off when leaving it. These commands in the vimrc file will achieve this:
autocmd BufEnter * set cursorline
autocmd BufLeave * set nocursorline
I'm trying to override the background of all colorschemes when using terminal windows - mostly because I find transparent terminal windows strangely exciting. All my best efforts of research points towards defining an autocmmand that will run everytime the colorscheme is changed. Currently the command looks like this:
autocmd ColorScheme * so rmbackground.vim
rmbackground.vim is a file of my own making which basically lists a bunch of hilightcommands like so:
hi Normal ctermbg=NONE
hi Comment ctermbg=NONE
...
Now the strange thing is that everything works correctly if I source the rmbackground.vim file manually, but the autocommand won't run as expected. Nor does it work if I specify a single hilight command as an autocmd instead of sourcing the whole rmbackground-file.
I feel very confused about the whole issue. below is my full vimrc and rmbackground.vim in case there are conflicts I'm not aware of. (The file is hideous at the moment since I've just started building my config but I hope you'll forgive me ;-) )
.vimrc
runtime bundle/vim-pathogen/autoload/pathogen.vim
call pathogen#infect()
"Turn on syntax
if has("syntax")
syntax on
endif
"Jump to last edited line
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif
"Indent correctly
if has("autocmd")
filetype plugin indent on
endif
set t_Co=256 "use 256 colors
let g:CSApprox_attr_map = { 'bold' : 'bold', 'italic' : '', 'sp' : '' }
set background=light
colorscheme twilight
set showcmd " Show (partial) command in status line.
set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
set smartcase " Do smart case matching
set hlsearch " Highlight search-terms
set incsearch " Incremental search
set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
set mouse=a " Enable mouse usage (all modes)
set history=1000
runtime macros/matchit.vim
set wildmenu
set wildmode=list:longest
set title
set scrolloff=3
set backupdir=~/.vim/tmp,~/.tmp,/var/tmp,/tmp
set directory=~/.vim/tmp,~/.tmp,/var/tmp,/tmp
set ruler
set backspace=indent,eol,start
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround "Round the indention nicely with other indents
set visualbell
"!autocmd
autocmd ColorScheme * so rmbackground.vim
rmbackground.vim
"Remove background set by colorscheme
hi Normal ctermbg=NONE
hi Comment ctermbg=NONE
hi Constant ctermbg=NONE
hi Special ctermbg=NONE
hi Identifier ctermbg=NONE
hi Statement ctermbg=NONE
hi PreProc ctermbg=NONE
hi Type ctermbg=NONE
hi Underlined ctermbg=NONE
hi Todo ctermbg=NONE
hi String ctermbg=NONE
hi Function ctermbg=NONE
hi Conditional ctermbg=NONE
hi Repeat ctermbg=NONE
hi Operator ctermbg=NONE
hi Structure ctermbg=NONE
The commands in .vimrc are executed sequentially. You're first setting :colorscheme, but the :autocmd comes only at the end.
Either you move the autocmd to before the :colorscheme command (so that it already applies to that), or you explicitly :source rmbackground.vim after the :colorscheme command, and have the :autocmd only for later dynamic changes.
In some colorschemes the current line highlighting changes background, in others, like Desert, the current line is underlined.
I want to change the current line highlighting in Desert to use a different background color instead of underlining. How can I do that?
My .vimrc:
set cursorline
highlight Cursorline cterm=bold
Update: .vimrc that solves the issue
colorscheme desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
color desert
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
desert is your colorscheme.(should come first)
put it in your ~/.vimrc
This works better (in every terminal) for me.
:hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white
It is setting of color for terminal: background color - ctermbg, and text color - ctermfg. For using in graphical window, add parameters guibg=darkred guifg=white
You can highlight the corresponding column as well, using the command:
:set cursorcolumn
It is useful to toggle highlighting on and off by pressing one key in the editor. Add these line to your vimrc:
:nnoremap H :set cursorline! cursorcolumn!<CR>
typing 'H' will toggle highlighting on and off (Map it to another key if you want)
You can find more info in the article:
http://vim.wikia.com/wiki/Highlight_current_line
for a style similar to the one you get in gvim in the terminal, preserving the syntax highlight:
" first thing is entering vim mode, not plain vi
set nocompatible
" force 256 colors on the terminal
set t_Co=256
" load the color scheme before anything
colorscheme darkblue " or desert... or anything
" the syntax cmd is when the colorscheme gets parsed, i think..
syntax on
" might not be on by default, this enable the cursor line feature
set cursorline
" set the prefered colours, pick one line here only.
" dark grey, better you can get if you don't support 256 colours
hi CursorLine cterm=NONE ctermbg=8 ctermfg=NONE
" light grey, no 256 colors
hi CursorLine cterm=NONE ctermbg=7 ctermfg=NONE
" dark redish
hi CursorLine cterm=NONE ctermbg=52 ctermfg=NONE
" dark bluish
hi CursorLine cterm=NONE ctermbg=17 ctermfg=NONE
" very light grey
hi CursorLine cterm=NONE ctermbg=254 ctermfg=NONE
" yelowish
hi CursorLine cterm=NONE ctermbg=229 ctermfg=NONE
" almost black
hi CursorLine cterm=NONE ctermbg=234 ctermfg=NONE
If you want to turn the underline on use either one of:
:hi CursorLine cterm=underline
:hi CursorLine gui=underline
Otherwise use one of those:
:hi CursorLine cterm=none
:hi CursorLine gui=none
I had a similar problem setting cursorline highlight, but mine was due to the mksession command that I was using to save the session information during vim exit. This session is then automatically restored during program startup, if it's run without any file arguments.
If anyone has .vimrc setup like this, you can add the following to .vimrc to set cursorline highlight correctly:-
function s:SetCursorLine()
set cursorline
hi cursorline cterm=none ctermbg=darkblue ctermfg=white
endfunction
autocmd VimEnter * call s:SetCursorLine()
A bit of explanation as to why this works. Along with various buffer and window information, mksession saves the current colorscheme name. This is restored during program startup through session restoration. However, since the session restoration is typically done after .vimrc has been run (typically using a function invoked through 'autocmd VimEnter *'), the cursorline highlight setting in .vimrc is reset by the default for the restored colorscheme.
The above function, invoked through the autocmd, will be run after all the initialization is complete and therefore successfully sets the cursorline highlight.
HTH.
You must add .vimrc end line:
highlight lineNr term=bold cterm=NONE ctermbg=none ctermfg=none gui=bold
set cursorline
highlight CursorLine term=bold cterm=NONE ctermbg=none ctermfg=none gui=bold
highlight CursorLineNr term=bold cterm=none ctermbg=none ctermfg=yellow gui=bold