lervag / vimtex

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

Highlight of delimiters is lose after passing to another file in arg list #593

Closed Aster89 closed 7 years ago

Aster89 commented 7 years ago

I use tikz with externalization.

When I open multiple files with vi main.tex graph.tikz, the delimiters (\begin{...} ... \end{...}) are correctly highlighted and % correctly jumps from upper to lower delimiter; when I pass to the other file with :n, there the delimiter \begin{tikzpicture} ... \end{tikzpicture} is highlighted and % still works; when I come back to the original file with :N the delimiters are no more highlighted, while % still works well.

The .latexmkrc file contains

$pdflatex = 'pdflatex --interaction=nonstopmode --shell-escape --synctex=1';
add_cus_dep('tikz', 'pdf', 0, 'maketikz');
Aster89 commented 7 years ago

It seems that <localheader>lx restores the correct behavior at least for .tex files.

lervag commented 7 years ago

Can you please provide a full minimal example, and at least a minimal vimrc file?

Aster89 commented 7 years ago

Well, the problem is present whichever the files, so I tried with the following main.tex file

\documentclass{article}
\usepackage{amsmath} % just to put the equation environment in the other file
\begin{document}
Hello!
\input{other.tex}
\end{document}

and the other.tex file

\begin{equation*}
x = y
\end{equation*}

I can open the two files with vi main.tex other.tex or vi other.tex main.tex. In each case, when I move from the first one to the second one (with :n) and then back to the first one (with :N or :first), then the coloring of the environments in the first file is lost. The same happens if I split the window to see the two buffers at the same time, with the only addition that before the first move from the first file to the second, I can move the cursor on the environment to highlight it. Then, when I move to the second file, the coloring of the environment in the first files remains blocked (also when I move the cursor).

The complete .vimrc file is the following (I have no idea of which part could be important and which not).

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()
Plugin 'beloglazov/vim-online-thesaurus'
let g:online_thesaurus_map_keys = 0
Plugin 'ron89/thesaurus_query.vim'
Plugin 'SirVer/ultisnips'
let g:UltiSnipsExpandTrigger="<F8>"
let g:UltiSnipsJumpForwardTrigger="<F8>"
let g:UltiSnipsJumpBackwardTrigger="<F7>"

Plugin 'MarcWeber/vim-addon-mw-utils'
Plugin 'tomtom/tlib_vim'
Plugin 'garbas/vim-snipmate'
Plugin 'honza/vim-snippets'
"Plugin 'vim-scripts/matchit.zip'
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'itchyny/lightline.vim'
Plugin 'sjl/gundo.vim'
nnoremap [6~ :GundoToggle<CR>
let g:gundo_preview_bottom=1
let g:gundo_return_on_revert=0
Plugin 'tpope/vim-fugitive'
Plugin 'Valloric/YouCompleteMe'
Plugin 'uguu-org/vim-matrix-screensaver'
Plugin 'vim-scripts/ScrollColors'
Plugin 'flazz/vim-colorschemes'
Plugin 'lervag/vimtex'
let g:ycm_complete_in_comments=1
let g:ycm_complete_in_strings=1
let g:ycm_collect_identifiers_from_comments_and_strings=1

" more Plugin commands
" ...
call vundle#end()            " required

" *******************
" An example for a vimdc file.
"
" Maintainer:   Bram Moolenaar <Bram@vim.org>
" Last change:  2008 Dec 17
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"         for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"       for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evil"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set no compatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vas")
  set nobackup      " do not keep a backup file, use versions instead
else
  set backup        " keep a backup file
endif
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time
set showcmd     " display incomplete commands
set incsearch       " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" *****************************************************************************
" QUA DI SEGUITO CI SONO AGGIUNTE MIE

set nota

" settings for lighline (begin)
set noshowmode
set laststatus=2
let g:lightline = {
      \ 'colorscheme': 'default',
      \ 'mode_map': { 'c': 'NORMAL' },
      \ 'active': {
      \   'left': [ [ 'mode', 'paste' ], [ 'fugitive', 'filename' ] ]
      \ },
      \ 'component': {
      \ 'lineinfo': '%3l%-2v',
      \ },
      \ 'component_function': {
      \   'modified': 'LightLineModified',
      \   'readonly': 'LightLineReadonly',
      \   'fugitive': 'LightLineFugitive',
      \   'filename': 'LightLineFilename',
      \   'fileformat': 'LightLineFileformat',
      \   'filetype': 'LightLineFiletype',
      \   'fileencoding': 'LightLineFileencoding',
      \   'mode': 'LightLineMode',
      \ },
      \ 'separator': { 'left': '', 'right': '' },
      \ 'subseparator': { 'left': '', 'right': '' }
      \ }

function! LightLineModified()
  return &ft =~ 'help\|vimfiler\|gundo' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction

function! LightLineReadonly()
  return &ft !~? 'vimfiler\|gundo' && &readonly ? '' : ''
endfunction

function! LightLineFilename()
  return ('' != LightLineReadonly() ? LightLineReadonly() . ' ' : '') .
        \ (&ft == 'vimfiler' ? vimfiler#get_status_string() :
        \  &ft == 'unite' ? unite#get_status_string() :
        \  &ft == 'vimshell' ? vimshell#get_status_string() :
        \ '' != expand('%:t') ? expand('%:t') : '[No Name]') .
        \ ('' != LightLineModified() ? ' ' . LightLineModified() : '')
endfunction

function! LightLineFugitive()
  if &ft !~? 'vimfiler\|gundo' && exists("*fugitive#head")
    let branch = fugitive#head()
    return branch !=# '' ? ' '.branch : ''
  endif
  return ''
endfunction

function! LightLineFileformat()
  return winwidth(0) > 70 ? &fileformat : ''
endfunction

function! LightLineFiletype()
  return winwidth(0) > 70 ? (&filetype !=# '' ? &filetype : 'no ft') : ''
endfunction

function! LightLineFileencoding()
  return winwidth(0) > 70 ? (&fenc !=# '' ? &fenc : &enc) : ''
endfunction

function! LightLineMode()
  return winwidth(0) > 30 ? lightline#mode() : ''
  "return winwidth(0) > 60 ? lightline#mode() : ''
endfunction
" settings for lighline (end)

" highlight OverLength ctermbg=red ctermfg=white guibg=#592929
" match OverLength /\%81v.\+/
runtime macros/matchit.vim
set cursor line
"set cursor column
set number
set nohls
hi search ctermbg=white ctermfg=black
hi comment ctermfg=darkgrey
set noi
set no backup
set nowritebackup
set hidden
set tabstop=8 softtabstop=0 expandtab shiftwidth=4 smarttab
map è :res +1
map à :res -1
map ù :vert res +1
map ò :vert res -1

"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.

"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
fun! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
end fun
inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
fun! Tab_Or_Complete_inv()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-P>"
  else
    return "\<S-Tab>"
  endif
end fun
inoremap <S-Tab> <C-R>=Tab_Or_Complete_inv()<CR>

set dictionary=/usr/share/dict/words

"map <C-I> gg=G

" Quanto segue serve per usare CTRL-^ (cioè CTRL-MAIUSC-ì) in sostituzione al
" tasto capslock. Il vantaggio sta nell'ultima linea di codice, che codifica
" la disattivazione di questo capslock all'uscita dall'insert mode (soluzione
" trovata su vim.wikia.com/wiki/insert-mode_only_Caps_Lock).
" Execyte 'lnoremap x X' and 'lnoremap X x' for each letter a-z.
for c in range(char2nr('A'), char2nr('Z'))
    execute 'lnoremap ' . nr2char(c+32) . ' ' . nr2char(c)
    execute 'lnoremap ' . nr2char(c) . ' ' . nr2char(c+32)
nedfor
" Kill the capslock when leaving insert mode.
autocmd InsertLeave * set iminsert=0

" quanto segue è per vim-latex
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
" filetype plugin on

" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
set grepprg=grep\ -nH\ $*

" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
let g:Tex_DefaultTargetFormat='pdf'
let g:Tex_CompileRule_dvi = 'latex -interaction=nonstopmode --shell-escape $*'
let g:Tex_CompileRule_ps = 'ps2pdf $*'
let g:Tex_CompileRule_pdf = 'pdflatex -interaction=nonstopmode --shell-escape $*'
let g:Tex_ViewRule_pdf = 'open -a Skim'
au BufNewFile,BufRead *.tikz set filetype=tex
" *****************************************************************************

" Only do this part when compiled with support for auto commands
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on grim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent " always set auto indenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

set ic
set sic
set wmnu
lervag commented 7 years ago

Please see the issue description, and in particular the minimal vimrc template:

set nocompatible

" Load Vimtex
let &rtp  = '~/.vim/bundle/vimtex,' . &rtp
let &rtp .= ',~/.vim/bundle/vimtex/after'

" Load other plugins, if necessary
" let &rtp = '~/path/to/other/plugin,' . &rtp

filetype plugin indent on
syntax enable

" Vimtex options go here

Adjust the template according to your own settings (necessary vim and vimtex options, correct paths, etc), then save the file as minivimrc or similar. Finally, open with vim -u minivimrc main.tex other.tex.

lervag commented 7 years ago

I notice two things from your vimrc file: You set no vimtex options. This might be OK. You set options for LaTeX-Suite. This plugin does NOT work together with vimtex, and if you by chance have this plugin installed, e.g. on a system level, then it will conflict.

Aster89 commented 7 years ago

Oh, I simply forget to remove those lines from the .vimrc file. Now it's ok. For what concerns the installation of the plugin, I installed it following instructions on the LaTeX-Suite website (I was very very new to the Vim world and in particular I was new to plugins; now I use Vundle to install plugins), so I tried to remove every file LaTeX-Suite-related manually. I think I successfully deleted them all.

lervag commented 7 years ago

Good. Still, if you want me to investigate this, you have to create a minimal vimrc file that reproduces the problem. I don't have the time to debug your vimrc file for you, so if the problem can not be isolated to vimtex, then you will have to debug this yourself.

Note: It is really quite simple. My template for the minimal vimrc file should mostly just work out of the box.

Aster89 commented 7 years ago

Ah, okok, then I'll try in a moment.

Aster89 commented 7 years ago

Tried. The problem persists.

lervag commented 7 years ago

Can you post the minimal vimrc file you tried?

Can you report the version of Vim you are using (after you've opened, do :version).

Aster89 commented 7 years ago

I just substituted my .vimrc with yours.

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 14 2016 09:19:30)
MacOS X (unix) version
Included patches: 1-32
Compiled by travis@Traviss-Mac-592.local
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl             +clipboard       +dialog_con_gui  +file_in_path    +insert_expand   +localmap        +mouse_netterm   +odbeditor       +quickfix        +syntax          +title           +wildignore      -xterm_save
+arabic          +cmdline_compl   +diff            +find_in_path    +job             +lua/dyn         +mouse_sgr       +packages        +reltime         +tag_binary      +toolbar         +wildmenu
+autocmd         +cmdline_hist    +digraphs        +float           +jumplist        +menu            -mouse_sysmouse  +path_extra      +rightleft       +tag_old_static  +transparency    +windows
+balloon_eval    +cmdline_info    +dnd             +folding         +keymap          +mksession       +mouse_urxvt     +perl/dyn        +ruby/dyn        -tag_any_white   +user_commands   +writebackup
+browse          +comments        -ebcdic          -footer          +lambda          +modify_fname    +mouse_xterm     +persistent_undo +scrollbind      -tcl             +vertsplit       -X11
++builtin_terms  +conceal         +emacs_tags      +fork()          +langmap         +mouse           +multi_byte      +postscript      +signs           +termguicolors   +virtualedit     -xfontset
+byte_offset     +cryptv          +eval            +fullscreen      +libcall         +mouseshape      +multi_lang      +printer         +smartindent     +terminfo        +visual          +xim
+channel         +cscope          +ex_extra        -gettext         +linebreak       +mouse_dec       -mzscheme        +profile         +startuptime     +termresponse    +visualextra     -xpm
+cindent         +cursorbind      +extra_search    -hangul_input    +lispindent      -mouse_gpm       +netbeans_intg   +python/dyn      +statusline      +textobjects     +viminfo         -xsmp
+clientserver    +cursorshape     +farsi           +iconv           +listcmds        -mouse_jsbterm   +num64           +python3/dyn     -sun_workshop    +timers          +vreplace        -xterm_clipboard
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib  -L. -fstack-protector -L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/li
b -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl/lib   -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon       -lm  -lncurses -liconv -framework Cocoa   -fstack-protector  -L/System/Library/Perl/5.16/darwin-thread-multi-
2level/CORE
lervag commented 7 years ago

Does the same happen if you use vim instead of vi?

lervag commented 7 years ago

Ah, ok, I finally reproduced it. I'll investigate.

lervag commented 7 years ago

Think that should do the trick. Let me know if it works!

Aster89 commented 7 years ago

Perfct! :+1: