YouCompleteMe considers underscores _ as word characters, which is desirable in most programming languages. But in TeX and LaTeX, this is not the case, especially where the underscore has a reserved marker for subscripts.

What I want is to remove underscores as word characters, so that it does not recognise constructions like alpha_ or sum_ as words.

How can a disable _ as a word character?

A MWE (I use Neovim wiht vim-plug):

" ~/.config/nvim/init.vim file
call plug#begin('~/.local/share/nvim/plugged')
  Plug 'sirver/ultisnips'
  Plug 'ycm-core/YouCompleteMe'
call plug#end()
# custom snippet file
snippet _ "subscript" iA
% main `main.tex` file

  $\sum_}$  % <- Here is the problem.

In the above problem line, if I type \sum, YCM suggests me the word sum_ for autocompletion. Ignoring that and continue typing _, the snippet is not expanded correctly as _{}, but _}, where the cursor lies just before }. Notice that this happens only for the second and subsequent \sums.

Edit: This happens for any word followed by an underscore, if that word previously appeared in the code and YMC parsed it. So this produces the same problem:

Hi_}  % <- Same problem
  • You should check :h 'iskeyword'. Also I'm fairly sure we have a duplicate of this question but I can't find it right now.
    – statox
    Mar 29, 2022 at 16:26
  • @statox Yeah, :verbose set isk? returns @,48-57,_,192-255, last set by the plugin vimtex. Do you think that changing this will fix the problem, e.g. by let g:tex_isk='@,48-57,192-255?
    – Gargantuar
    Mar 29, 2022 at 20:54

1 Answer 1


As @statox mentioned in the comments, setting iskeyword solves the problem.

For those who want a specific solution:

It is a good practice to write filetype plugins for every filetype you use (in this case, .tex files), it keeps your init.vim file clean and tidy. Add the following line into your ~/.config/nvim/ftplugin/tex.vim file:

setlocal iskeyword=@,48-57,192-255
  • 2
    For what it's worth you could even use set local iskeyword-=_ this way you only remove _ and keep the other settings
    – statox
    Mar 30, 2022 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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