Vimtex: Question: deoplete configuration for vimtex does not work as expected.

Created on 1 Jun 2020  Â·  15Comments  Â·  Source: lervag/vimtex

Running Vim 8.2 on Ubuntu 18.04.

With the configuration recommended in the document:

call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

When I run vim in the terminal, I receive the following message:

Error detected while processing /home/a/.vimrc:
line  149:
E117: Unknown function: deoplete#custom#var
Press ENTER or type command to continue

Everything is working well if the configuration is not imposed.

Would greatly appreciate your help!!!

Most helpful comment

I always put configurations immediately after Plug ..., which leads to the mistake. Now the problem is solved, and you saved me!

My first question is simple: are you really using deoplete? Let's assume you answer yes. Then: You are probably using something like vim-plug to install your plugins, and you are adding your configuration for vimtex before the call plug#end().

I can see I was not so clear, especially that I did not clearly state that you should _not_ add your configuration before plug#end(). But I did pinpoint your issue on my first try. In any case, thanks @Shougo for helping out!

All 15 comments

My first question is simple: are you really using deoplete? Let's assume you answer yes. Then: You are probably using something like vim-plug to install your plugins, and you are adding your configuration for vimtex before the call plug#end().

If I'm wrong, then please provide a full minimal configuration and example to reproduce your problem.

This is my minimal vimrc, in which honza/vim-snippets and SirVer/ultisnips are used to test if deoplete works.

set nocompatible
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')

Plug 'lervag/vimtex'
let g:tex_flavor = 'latex'
Plug 'honza/vim-snippets'
Plug 'SirVer/ultisnips'
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
let g:deoplete#enable_at_startup = 1

call plug#end()

filetype plugin indent on
syntax on

Given this vimrc, I can use deoplete with UltiSnips in minimal.tex. But when I add

call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

I receive the following message:

➜ vim minimal.tex
Error detected while processing /home/ganx/.vimrc:
line   17:
E121: Undefined variable: g:vimtex#re#deoplete
E116: Invalid arguments for function deoplete#custom#var
Press ENTER or type command to continue

Then I press ENTER, and receive the following message:

"minimal.tex" 4L, 77C
Error detected while processing function vimtex#init[4]..<SNR>34_init_state[1]..vimtex
#state#init[1]..<SNR>36_get_main[16]..<SNR>36_get_main_from_texroot:
line    2:
E121: Undefined variable: g:vimtex#re#tex_input_root
E116: Invalid arguments for function matchstr(l:line, g:vimtex#re#tex_input_root)
Error detected while processing function vimtex#init[4]..<SNR>34_init_state[1]..vimtex
#state#init:
line    1:
E714: List required
Error detected while processing /home/ganx/.vim/plugged/vimtex/indent/tex.vim:
line  103:
E121: Undefined variable: g:vimtex#re#not_bslash
line  104:
E716: Key not present in Dictionary: re_amp
Press ENTER or type command to continue

Hm. You need to load vimtex/re.vim before use it.
I think vimtex has loading functions.

@lervag I think the documentation should be fixed.
The autoload variable does not load scripts automatically instead of autoload functions.
:help autoload

Note: Oh, this is my fault.
autoload variables are loaded automatically.

I think you need to call vimtex#init() before use the variable.

@Shougo Thanks for your replies!

Would greatly appreciate if you could tell me how to call vimtex#init() before use the variable!

Really??

call vimtex#init()
call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

I tried this, but receive the following message:

➜ vim minimal.tex
Error detected while processing /home/ganx/.vimrc:
line   17:
E117: Unknown function: vimtex#init
line   18:
E121: Undefined variable: g:vimtex#re#deoplete
E116: Invalid arguments for function deoplete#custom#var
Press ENTER or type command to continue

You must call the function after call plug#end().

Please read this.

Then: You are probably using something like vim-plug to install your plugins, and you are adding your configuration for vimtex before the call plug#end().

And you have uploaded vimrc is not real minimal.
Because it does not have the configuration.

call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

Hm. call vimtex#init() is not needed.

So,

set nocompatible
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')

Plug 'lervag/vimtex'
let g:tex_flavor = 'latex'
Plug 'honza/vim-snippets'
Plug 'SirVer/ultisnips'
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
let g:deoplete#enable_at_startup = 1

call plug#end()

call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

filetype plugin indent on
syntax on

This is the correct answer.

Why you must not configure deoplete after plug#end()?
This is vim-plug's feature.
vim-plug adds runtimepath when plug#end() is called.
So you cannot use the plugins before plug#end().

@Shougo Greatly appreciate your patience!

Hm. call vimtex#init() is not needed.

So,

set nocompatible
if empty(glob('~/.vim/autoload/plug.vim'))
  silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')

Plug 'lervag/vimtex'
let g:tex_flavor = 'latex'
Plug 'honza/vim-snippets'
Plug 'SirVer/ultisnips'
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
let g:deoplete#enable_at_startup = 1

call plug#end()

call deoplete#custom#var('omni', 'input_patterns', {
        \ 'tex': g:vimtex#re#deoplete
        \})

filetype plugin indent on
syntax on

This is the correct answer.

I always put configurations immediately after Plug ..., which leads to the mistake. Now the problem is solved, and you saved me!

I always put configurations immediately after Plug ..., which leads to the mistake. Now the problem is solved, and you saved me!

My first question is simple: are you really using deoplete? Let's assume you answer yes. Then: You are probably using something like vim-plug to install your plugins, and you are adding your configuration for vimtex before the call plug#end().

I can see I was not so clear, especially that I did not clearly state that you should _not_ add your configuration before plug#end(). But I did pinpoint your issue on my first try. In any case, thanks @Shougo for helping out!

I just have checked the issue because it complains behavior about deoplete.

I recently updated the plugins and also experiencing this issue.
The vimrc file was not touched, and working smoothly before.

@xarthurx The issue is closed as resolved. No activity for two months. Can you please open a new issue and describe it properly? Please take the time to make a minimal example.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nbanka picture nbanka  Â·  5Comments

adimanea picture adimanea  Â·  5Comments

lervag picture lervag  Â·  5Comments

Davidnet picture Davidnet  Â·  4Comments

vanabel picture vanabel  Â·  6Comments