itchyny / lightline.vim

A light and configurable statusline/tabline plugin for Vim
MIT License
6.77k stars 316 forks source link

quickfix closing makes bar disappear #639

Closed byrnat closed 2 years ago

byrnat commented 2 years ago

Hi, I'm using lightline+vimtex for live previews, and when I try to compile my .tex file from nvim, errors are shown in the quickfix menu. At this point, the status line still looks/works fine. However, after fixing the errors and compiling again, the quickfix window disappears, and lightline seems to think that my current (still active) window and displays the bar for an inactive window. With latex error: image After fixing error: image I can get it back by creating and closing a new window, but is there something I can do to have lightline recognize my window as the active one after quickfix gets closed? Thanks!

itchyny commented 2 years ago

Provide the complete vimrc and steps to reproduce the issue. How do you close the quickfix window?

byrnat commented 2 years ago

vimrc (sorry it's a mess):

call plug#begin('~/.vim/plugged')

command! -nargs=1 Silent
\   execute 'silent !' . <q-args>
\ | execute 'redraw!'

" Declare the list of plugins.
Plug 'lervag/vimtex', {'for': 'tex'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'dylanaraps/wal.vim'
Plug 'jiangmiao/auto-pairs'
Plug 'neomutt/neomutt.vim'
Plug 'preservim/nerdcommenter'
Plug 'freitass/todo.txt-vim'
Plug 'sainnhe/gruvbox-material'
Plug 'romainl/Apprentice', {'branch': 'fancylines-and-neovim'}
Plug 'chriskempson/base16-vim'
Plug 'dylanaraps/crayon'
Plug 'itchyny/lightline.vim'
Plug 'ap/vim-css-color'
Plug 'godlygeek/tabular'
Plug 'preservim/vim-markdown'
Plug 'mileszs/ack.vim'
Plug 'tmhedberg/SimpylFold'
Plug 'goerz/jupytext.vim'
Plug 'octol/vim-cpp-enhanced-highlight'
Plug 'catppuccin/nvim', {'as': 'catppuccin'}
" List ends here. Plugins become visible to Vim after this call.
call plug#end()

syntax on

let g:vimtex_compiler_progname='nvr'

" Transparency
" highlight Normal     ctermbg=NONE guibg=NONE
" highlight LineNr     ctermbg=NONE guibg=NONE
" highlight SignColumn ctermbg=NONE guibg=NONE

set hidden
set nobackup
set nowritebackup
set shortmess+=c
set updatetime=300

set guicursor=
set autoindent
set smartindent
set enc=utf-8
set fileencoding=utf-8
set linebreak
set textwidth=0
set noexpandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set number relativenumber
set cmdheight=3
set smartcase
set ignorecase
setlocal foldmethod=syntax
set nofoldenable

let maplocalleader="\\"

command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')

" Highlight TODO, FIXME, NOTE, etc.
" if has("autocmd")
    " if v:version > 701
    " autocmd Syntax * call matchadd('Todo', '\W\zs\(TODO\|FIXME\|CHANGED\|BUG\|HACK\)')
    " autocmd Syntax * call matchadd('Debug', '\W\zs\(NOTE\|INFO\|IDEA\)')
    " endif
" endif

function! EnableSuggest()
  let b:coc_suggest_disable = 0
  inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
  inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
endfunction

let b:coc_suggest_disable = 1
autocmd Filetype java,python,cpp call EnableSuggest()
autocmd FileType python let b:coc_root_patterns = ['.git', '.env', 'venv', '.venv', 'setup.cfg', 'setup.py', 'pyproject.toml', 'pyrightconfig.json']

let g:vimtex_quickfix_ignore_filters = [
      \ 'Underfull',
      \ 'Overfull',
      \ '\headheight is too small',
      \]

autocmd Filetype tex let g:vimtex_syntax_enabled = 1
" autocmd Filetype tex noremap \f :w <CR> :!latexindent -s -w % <CR> :e <CR>
autocmd Filetype tex noremap \f :w <CR> :!latexindent -o=% % <CR> :e <CR>
autocmd Filetype tex noremap \b ^C\begin{<C-R>"}<CR>\end{<C-R>"}<Esc>ko
autocmd Filetype tex inoremap <C-b> <Esc>^C\begin{<C-R>"}<CR>\end{<C-R>"}<Esc>ko
" autocmd Filetype tex noremap \p i\newpage<CR><CR>\section*{Problem }<Esc>i
autocmd Filetype tex noremap <C-p> i\section*{Problem }<Esc>i
autocmd Filetype tex inoremap <C-p> <Esc>i\section*{Problem }<Esc>i
autocmd Filetype tex noremap <C-A-p> i\subsection*{}<Esc>i
autocmd Filetype tex inoremap <C-A-p> <Esc>i\subsection*{}<Esc>i

if has("nvim-0.5.0") || has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

if executable('ag')
  let g:ackprg = 'ag --vimgrep'
endif

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

" Use <c-space> to trigger completion.
" if has('nvim')
"   inoremap <silent><expr> <c-space> coc#refresh()
" else
"   inoremap <silent><expr> <c-@> coc#refresh()
" endif

inoremap <C-_> <Esc> :normal \c <CR> a
noremap <C-_> :normal \c <CR>
inoremap <C-/> <Esc> :normal \c <CR> a
noremap <C-/> :normal \c <CR>
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
nnoremap <silent> ca  :<C-u>CocList diagnostics<cr>
inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
                \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
nnoremap <Esc> <Esc>:noh<CR>
nmap <leader>rn <Plug>(coc-rename)
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

noremap <leader>t :Ack! "TODO\|FIXME\|CHANGED\|BUG\|HACK" <CR>
noremap <C-n> <Esc> :cn <CR> 
noremap <C-p> <Esc> :cp <CR> 

nnoremap <space> za
nnoremap <C-space> zA

" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')

" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call     CocAction('fold', <f-args>)

" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')

nnoremap <C-j> :m .+1<CR>==
nnoremap <C-k> :m .-2<CR>==
" inoremap <C-j> <Esc>:m .+1<CR>==gi
" inoremap <C-k> <Esc>:m .-2<CR>==gi
" vnoremap <C-j> :m '>+1<CR>gv=gv
" vnoremap <C-k> :m '<-2<CR>gv=gv

let NERDSpaceDelims = 1

" set background=dark
" let g:gruvbox_material_background='soft'
" let g:gruvbox_material_palette='material'
" let g:gruvbox_material_palette='original'
" let g:gruvbox_material_transparent_background=1

set notermguicolors t_Co=16

" colorscheme gruvbox-material
" colorscheme default
let g:catppuccin_flavour = "macchiato"
colorscheme catppuccin

let g:lightline = {'colorscheme': 'catppuccin'}

let g:markdown_enable_spell_checking=0
let g:markdown_fenced_languages=['bash', 'python', 'cpp', 'java']
let g:vim_markdown_folding_style_pythonic = 1
autocmd FileType markdown setlocal ts=4 sw=4 noet

let g:vimtex_fold_enabled=1
autocmd FileType c,cpp setlocal foldmethod=syntax
set fillchars=fold:\ 

hi Folded ctermfg=White
hi Todo ctermfg=Black ctermbg=Magenta
hi Normal ctermbg=none
hi Comment ctermfg=Gray
hi LineNr ctermfg=Gray

hi Pmenu ctermbg=0
hi PmenuSel ctermbg=1
hi PmenuSbar ctermbg=0

let g:cpp_experimental_simple_template_highlight = 1
" let g:cpp_experimental_template_highlight = 1
let g:cpp_no_function_highlight = 1
" let ts = &tabstop
" autocmd FileType python exec 'setlocal tabstop=' . ts

Steps to reproduce:

  1. Make a new .tex file
  2. Type something that would give you a compile error (e.g. a lone "$")
  3. Try to compile from vimtex (this opens the quickfix window)
  4. Fix the error (remove the extraneous "$")
  5. Compile again

Thanks!

itchyny commented 2 years ago

I don't install latexmk so cannot make the plugin work, but quick look at the document leads me to the callback events VimtexEventCompileSuccess and VimtexEventCompileFailed. I would try the following configuration.

autocmd User VimtexEventCompileSuccess call lightline#update()
autocmd User VimtexEventCompileFailed call lightline#update()

If this configuration does not work, the plugin may close the quickfix window after emitting these events. If the plugin automatically validate the file after changes, this is likely the issue of autocmd without ++nested flag. Try finding the autocmd command in that plugin which invokes the validations, and add ++nested flag. Without this, other plugins including lightline cannot detect current window changes like cclose.

byrnat commented 2 years ago

Second suggestion worked, thanks so much! Great statusline btw :)

jackcogdill commented 2 years ago

I had a similar issue where :cclose would not update Lightline if I was not inside of the quickfix window. Presumably it has to do with the AsyncRun plugin, since that's what opened the quickfix window.

I am using this generic solution for any window close event:

autocmd vimrc WinClosed * call lightline#update()