lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.45k stars 388 forks source link

supertab completion takes 20 seconds to complete a word when using many latex packages #2966

Closed thekswenson closed 3 months ago

thekswenson commented 3 months ago

Description

When I want to retype a long word that is already in my document, I press <tab>, using the supertab plugin. With vimtex enabled, it takes ~20 seconds to search all of the system tex libraries before showing the list of completions.

I'm filing a bug because this seems like it shouldn't be normal behavior. If it is normal, I'll close the bug. In that case, is there a workaround to get vimtex to stop searching ALL of the .sty (etc.) files on my system?

Steps to reproduce

  1. open the minimal example
  2. start typing a word that is already in the document, and press <tab>
" set the runtime path to include Vundle and initialize
set nocompatible              " be iMproved, required
filetype off                  " required

set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'ervandew/supertab'

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

set nocompatible
let &runtimepath  = '~/.vim/bundle/vimtex,' . &runtimepath
let &runtimepath .= ',~/.vim/bundle/vimtex/after'
filetype plugin indent on
syntax enable
\documentclass{minimal}

\usepackage{hyperref}
\hypersetup{hidelinks}
\usepackage{graphicx}
\usepackage{xspace}
\usepackage{xcolor}
\usepackage{subcaption}
\usepackage{amssymb,amsmath,amsthm}
\usepackage{algorithm,algorithmicx}
\usepackage[noend]{algpseudocode}
\usepackage{todonotes}
\usepackage{tikz,paralist,ifthen}  % For optproblem.

\begin{document}
Hello world!
\end{document}

Expected behavior

I expect a list of completions to show up in a reasonable amount of time.

Actual behavior

The list shows up after almost 20 seconds.

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: Ubuntu 24.04 LTS
  Vim version: VIM 9.1 (1-16)
  Has clientserver: true
  Servername: undefined (vim started without --servername)

VimTeX project: minimal2
  base: minimal2.tex
  root: /home/kms
  tex: /home/kms/minimal2.tex
  main parser: current file verified
  document class: minimal
  packages: algorithm algorithmicx algpseudocode amsmath amssymb amsthm graphicx
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
lervag commented 3 months ago

I get "We don’t support that file type." messages, so I'm not sure how to attach the minimal example files. I'll do so in comments.

Yes, I much prefer that you include the files verbatim; preferably as part of the main post.

In your "step 2", the sentence ends after "and press"... so, press what?

thekswenson commented 3 months ago

Sorry @lervag, I updated the post to say <tab>.

lervag commented 3 months ago

Ok, I tried to reproduce this. I did:

mkdir test
cd test
git clone https://github.com/ervandew/supertab
vim test.vim
vim test.tex

The contents of test.tex is the same as what you provided, whereas I simplified the test.vim file to this:

set nocompatible
set runtimepath^=~/.local/plugged/vimtex
set runtimepath^=supertab
set runtimepath+=~/.local/plugged/vimtex/after
filetype plugin indent on
syntax enable

nnoremap q :qall!<cr>

silent edit test.tex

Now, finally, I run vim --clean -u test.vim, which will open the test.tex file with VimTeX and supertab enabled. I start typing a word (in the document) and complete with <tab>, and I can see the delay you mention.

The delay is caused by VimTeX indirectly, because VimTeX will set the 'include' option. You can inspect its value with :set include after opening a LaTeX file. Now, what is happening is that keyword completion (CTRL-N), which is executed by supertab with <tab>, will scan for keywords from included files. This is the default behaviour in Vim. Notice that Neovim has changed this default. It is controlled by the 'complete' option:

                        *'complete'* *'cpt'* *E535*
'complete' 'cpt'    string  (default: ".,w,b,u,t,i")
            local to buffer
    This option specifies how keyword completion |ins-completion| works
    when CTRL-P or CTRL-N are used.  It is also used for whole-line
    completion |i_CTRL-X_CTRL-L|.  It indicates the type of completion
    and the places to scan.  It is a comma-separated list of flags:
    .   scan the current buffer ('wrapscan' is ignored)
    w   scan buffers from other windows
    b   scan other loaded buffers that are in the buffer list
    u   scan the unloaded buffers that are in the buffer list
    U   scan the buffers that are not in the buffer list
    k   scan the files given with the 'dictionary' option
    kspell  use the currently active spell checking |spell|
    k{dict} scan the file {dict}.  Several "k" flags can be given,
        patterns are valid too.  For example: >
            :set cpt=k/usr/dict/*,k~/spanish
<   s   scan the files given with the 'thesaurus' option
    s{tsr}  scan the file {tsr}.  Several "s" flags can be given, patterns
        are valid too.
    i   scan current and included files

So, I think you can remove the lag if you remove i from the complete option, i.e. add this to your vimrc:

set complete-=i
thekswenson commented 3 months ago

Thanks a ton for the very clear explanation of the problem, and the fix!

lervag commented 3 months ago

No problem 😊