I built vim from source. But for some reason I can no longer underline my current line when vim loads .vimrc. I have to type underline commands manually which makes it work.

Here is the output of my version command

VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov  5 2018 21:28:01)
Included patches: 1-510
Compiled by user@user-fedora-PC0PVGAT
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          -toolbar
+cindent           +insert_expand     +path_extra        +user_commands
+clientserver      +job               +perl              +vartabs
+clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           +python/dyn        +viminfo
+conceal           +linebreak         +python3/dyn       +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       +lua               +ruby              +writebackup
+dialog_con        +menu              +scrollbind        +X11
+diff              +mksession         +signs             +xfontset
+digraphs          +modify_fname      +smartindent       -xim
-dnd               +mouse             +startuptime       -xpm
-ebcdic            -mouseshape        +statusline        +xsmp_interact
+emacs_tags        +mouse_dec         -sun_workshop      +xterm_clipboard
+eval              -mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/home/user/myfs/opt/vim/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -fPIC -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-z,relro  -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,--enable-new-dtags -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld   -L/usr/local/lib -Wl,--as-needed -o vim    -lSM -lICE -lXt -lX11 -lSM -lICE  -lm -ltinfo -lelf  -lselinux   -ldl  -L/usr/lib -llua -Wl,--enable-new-dtags -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -fstack-protector-strong -L/usr/local/lib  -L/usr/lib64/perl5/CORE -lperl -lpthread -lresolv -ldl -lm -lcrypt -lutil -lc    -lruby -lpthread -ldl -lcrypt -lm

Here is my .vimrc

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

Plugin 'tpope/vim-sensible.git'
Plugin 'tpope/vim-fugitive'
Plugin 'christoomey/vim-system-copy.git'
Plugin 'tpope/vim-surround'
Plugin 'majutsushi/tagbar'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'tomtom/tcomment_vim'
Plugin 'Valloric/YouCompleteMe'
Plugin 'rdnetto/YCM-Generator'
Plugin 'godlygeek/tabular.git'
Plugin 'jiangmiao/auto-pairs.git'
Plugin 'mileszs/ack.vim'
Plugin 'Yggdroot/indentLine.git'
Plugin 'vim-scripts/xoria256.vim.git'
Plugin 'itchyny/lightline.vim.git'
Plugin 'kana/vim-textobj-user.git'
Plugin 'kana/vim-textobj-line.git'
Plugin 'edkolev/tmuxline.vim.git'
Plugin 'jeaye/color_coded.git'
Plugin 'christoomey/vim-tmux-navigator.git'
Plugin 'tpope/vim-vinegar.git'
Plugin 'vim-scripts/Conque-GDB.git'
" Plugin 'w0rp/ale.git'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

colorscheme xoria256

" To ignore plugin indent changes, instead use:
"filetype plugin on

" Highlight the search pattern.
let mapleader="\<Space>"

set directory=/tmp
set history=1000
set hlsearch
set incsearch
set ignorecase
set smartcase
set showbreak=…
set linebreak
set listchars=tab:►-,eol:¬,trail:●
set relativenumber
set number
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
" Underline current cursor line
set cursorline
hi clear CursorLine
hi CursorLine gui=underline cterm=underline

nnoremap <leader>l :set list!<cr>

nnoremap <silent><F8> :nohlsearch<cr>

nnoremap <leader>vv :vsp<cr>
nnoremap <leader>ss :sp<cr>

" Toggle the Tlist window using <F4>
nnoremap <silent><F4> :TagbarToggle<cr>

nnoremap <leader>fb :CtrlPBuffer<cr>
nnoremap <leader>fm :CtrlPMixed<cr>
nnoremap <leader>ff :CtrlP getcwd()<cr>
nnoremap <leader>ft :CtrlPTag<cr>

nnoremap <silent><leader>sv :source ~/.vimrc<cr>
nnoremap <silent><leader>ev :edit ~/.vimrc<cr>
nnoremap <silent><leader>et :edit ~/.tmux.conf<cr>

nnoremap <silent><F9>       :cprev<cr>zz
nnoremap <silent><F10>      :cnext<cr>zz
nnoremap <silent><C-F9>     :lprev<cr>zz
nnoremap <silent><C-F10>    :lnext<cr>zz
nnoremap <silent><M-F9>     :cfirst<cr>
nnoremap <silent><M-F10>    :clast<cr>
nnoremap <silent><leader>mm :set lines=10000 columns=1000<cr>
nnoremap <silent><leader>mn :set lines=999 columns=90<cr>

" ================ Plugin Configuraiton  ====================

" -------------- YouCompleteMe  -----------------
let g:ycm_always_populate_location_list            = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_error_symbol                             = 'E>'
let g:ycm_warning_symbol                           = 'W>'
let g:ycm_confirm_extra_conf                       = 0

" -------------- lightline  -----------------

" display the plugin name at the mode component?
function! LightlineMode()
  return expand('%:t') ==# '__Tagbar__' ? 'Tagbar':
        \ expand('%:t') ==# 'ControlP' ? 'CtrlP' :
        \ &filetype ==# 'unite' ? 'Unite' :
        \ &filetype ==# 'vimfiler' ? 'VimFiler' :
        \ &filetype ==# 'vimshell' ? 'VimShell' :
        \ lightline#mode()

let g:lightline = {
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ],
      \             [ 'gitbranch', 'readonly', 'filename', 'modified' ] ]
      \ },
      \ 'component_function': {
      \   'gitbranch': 'fugitive#head',
      \   'mode': 'LightlineMode',
      \ },
      \ }

" -------------- indentLine -----------------
let g:indentLine_char = '|'

" -------------- tagbar -----------------
let g:tagbar_autoclose        = 1
let g:tagbar_autofocus        = 1
let g:tagbar_sort             = 1
let g:tagbar_autoshowtag      = 1
let g:tagbar_foldlevel        = 99
let g:tagbar_show_linenumbers = -1

" -------------- Ack -----------------
let g:ackprg = 'ag --nogroup --nocolor --column'

These are the lines I'm talking about:

" Underline current cursor line
set cursorline
hi clear CursorLine
hi CursorLine gui=underline cterm=underline

Here is what it looks like now

enter image description here

Here is what I expect it to look like

enter image description here

To make it look as I expect it, I need to enter the following commands manually

set cursorline
hi clear CursorLine
hi CursorLine gui=underline cterm=underline

My question is why vim no longer reacts to these commands from vimrc?

Here is my system description:

$ uname -a
Linux user-fedora-PC0PVGAT 4.18.16-200.fc28.x86_64 #1 SMP Sat Oct 20 23:53:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/os-release
VERSION="28 (Workstation Edition)"
PRETTY_NAME="Fedora 28 (Workstation Edition)"
VARIANT="Workstation Edition"


After I started vim I ran a following command

:verbose hi CursorLine

The result was

CursorLine     xxx term=underline ctermbg=237 guibg=#3a3a3a
    Last set from ~/.vim/bundle/xoria256.vim/colors/xoria256.vim line 42

Given that CursorLine was set from the plugin, my question is why this is happening? I didn't have any issues using a standard vim package, i.e. one installed with a package manager, dnf in this particular case


I should say that my vim is located in an nonstandard location, ~/myfs/opt/vim

  • please show the output of :verbose :hi CursorLine right after Vim starts and when cursorline setting is wrong. – Christian Brabandt Nov 7 '18 at 6:27
  • @ChristianBrabandt How do I show it when the cursor line is wrong? – flashburn Nov 7 '18 at 6:36
  • I don't understand. I thought after startup the cursorline does not look like expected. Therefore type :verbose :hi CursorLine to see where it was last set. – Christian Brabandt Nov 7 '18 at 6:37
  • @ChristianBrabandt Let me correct myself. I thought you wanted 2 different outputs. One after I start vim and one while vim is loading .vimrc. I added output of the command in the original post at the end. – flashburn Nov 7 '18 at 6:42
  • @ChristianBrabandt I gues the question now is why it is last set from the plugin rather then from .vimrc? – flashburn Nov 7 '18 at 6:44

As you can see from the output of :verbose :hi CursorLine, your CursorLine setting is reset by the colorscheme you are using.

There are a couple of approaches you can use to change that.

  1. Simply comment out the line in the colorscheme.
  2. Use a VimEnter autocommand, to have your configuration setting set after Vim has startup:

    augroup CustomCursorLine
    au VimEnter * :hi! CursorLine gui=underline cterm=underline
    augroup END

(Note: The autogroup is there so that the autocommand is reset whenever your vimrc file is read. That why, after re-sourcing your vimrc the same event won't accumulate multiple times).

  1. Use the ColorScheme autocommand to reset your Cursorline setting whenever a different colorscheme is sourced. That should work like this:

    augroup CustomCursorLine
    au ColorScheme * :hi! CursorLine gui=underline cterm=underline
    augroup END

Option 3 is the one I personally would recommend. Using a VimEnter autocommand often feels a bit like a hack, so I personally try to avoid it. Changing the colorscheme might ask for trouble later, if you update your plugin (however the vim-scripts repository is unmaintained, so there most likely won't be any updates anyhow).


Suggestion by @ChristianBrabandt didn't exactly work. I had to modify it slightly to the following:

set cursorline
augroup CustomCursorLine
    au ColorScheme * :hi clear CursorLine
    au ColorScheme * :hi! CursorLine gui=underline cterm=underline
augroup END

I will still accept his answer since this is what led to a solution.

  • Im not sure youre guaranteed correct ordering there (perhaps?). It seems simpler to just a like continuation and | command separator – D. Ben Knoble Nov 8 '18 at 4:14
  • @D.BenKnoble Can you elaborate more? I don't understand what you mean. – flashburn Nov 9 '18 at 1:12
  • I mean im not sure if youre guaranteed the two commands (clear and highlight) will fire in the proper order. Id have to check the docs. But you could make one command by separating them with a “bar” (|) – D. Ben Knoble Nov 9 '18 at 2:39
  • @D.BenKnoble You mean make it au ColorScheme * :hi clear CursorLine | :hi! CursorLine gui=underline cterm=underline. Am I right? – flashburn Nov 9 '18 at 17:31
  • Yes! Thats what I mean; typing on mobile made it difficult to type it all the way out – D. Ben Knoble Nov 9 '18 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.