Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a$ and i$ not working when syntax highlighting is off #2248

Closed
igorf-27 opened this issue Nov 14, 2021 · 15 comments
Closed

a$ and i$ not working when syntax highlighting is off #2248

igorf-27 opened this issue Nov 14, 2021 · 15 comments
Labels

Comments

@igorf-27
Copy link

igorf-27 commented Nov 14, 2021

Description

When syntax highlighting is off, in normal mode, da$ and di$ produce either no effect or long error messages (a detailed example below); in visual mode, a$ and i$ behave the same way.

Setting :syntax on makes everything work fine though!

Maybe the problem is on my side, because I currently use a weird linux distro; on the other hand, everything else seems to work as it should do. I can't test it on another computer now.

The version info for the vim I actually use follows. (I tried building the most recent version of vim and observed the same problem.)

$ vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 15 2019 16:41:15)
Included patches: 1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    +tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
+balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
+browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +textprop
+byte_offset       -hangul_input      +num64             +timers
+channel           +iconv             +packages          +title
+cindent           +insert_expand     +path_extra        +toolbar
+clientserver      +job               +perl              +user_commands
+clipboard         +jumplist          +persistent_undo   +vartabs
+cmdline_compl     +keymap            +postscript        +vertsplit
+cmdline_hist      +lambda            +printer           +virtualedit
+cmdline_info      +langmap           +profile           +visual
+comments          +libcall           -python            +visualextra
+conceal           +linebreak         +python3           +viminfo
+cryptv            +lispindent        +quickfix          +vreplace
+cscope            +listcmds          +reltime           +wildignore
+cursorbind        +localmap          +rightleft         +wildmenu
+cursorshape       +lua               +ruby              +windows
+dialog_con_gui    +menu              +scrollbind        +writebackup
+diff              +mksession         +signs             +X11
+digraphs          +modify_fname      +smartindent       -xfontset
+dnd               +mouse             +startuptime       +xim
-ebcdic            +mouseshape        +statusline        +xpm
+emacs_tags        +mouse_dec         -sun_workshop      +xsmp_interact
+eval              +mouse_gpm         +syntax            +xterm_clipboard
+ex_extra          -mouse_jsbterm     +tag_binary        -xterm_save
   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: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/uuid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-4Pursk/vim-8.1.0875=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.28/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu -lpython3.7m -lcrypt -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.5 -lpthread -lgmp -ldl -lcrypt -lm

Steps to reproduce

  1. vim -u minimal.vim minimal.tex
  2. 3Glda$
  3. $hda$
% minimal.tex:
\documentclass{article}
\begin{document}
$a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$ $a$
\end{document}
" minimal.vim:
set nocompatible
filetype plugin on
let g:vimtex_compiler_method = 'generic'
let g:vimtex_compiler_generic = { 'command': 'pdflatex '.expand('%:p') }
let g:vimtex_view_general_viewer = 'okular'
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'

Expected behavior

The first and the last copy of $a$ deleted.

Actual behavior

After step 2, nothing happens.
After step 3, a long error message (I attach it as a text file). It seems to happen when da$ is typed inside of a formula which is at least 25th from the beginning (I am not really sure though).

vimtex-error-message.txt

Do you use a latexmkrc file?

no

VimtexInfo

System info
  OS: Endless GNU/Linux testing/unstable
  Vim version: VIM 8.1 (1-875, 878, 884, 948, 1046, 1365-1368, 1382, 1401)
  Has clientserver: true
  Servername: undefined (vim started without --servername)

VimTeX project: minimal
  base: minimal.tex
  root: /sysroot/home/igor
  tex: /sysroot/home/igor/minimal.tex
  main parser: current file verified
  document class: article
  compiler: generic
  viewer: General
  qf method: LaTeX logfile
@igorf-27 igorf-27 added the bug label Nov 14, 2021
@clason
Copy link
Contributor

clason commented Nov 14, 2021

That is to be expected -- if you disable syntax, you will not get any syntax-related features!

(It's a common misconception that syntax controls "syntax highlighting", but that is actually not true. There's no way in Vim to disable only highlighting and still have other syntax features. If you just want to get rid of "all the colors", you need to set a monochrome color scheme.)

@igorf-27
Copy link
Author

Ok, thanks.

@igorf-27
Copy link
Author

igorf-27 commented Nov 14, 2021

I'm not yet convinced though. The vim documentation says it's just highlighting. http://vimdoc.sourceforge.net/htmldoc/syntax.html

aP and daP work fine without this stuff on.

If it is really necessary to turn this on for a$ to work, then you should probably mention it in VimTeX documentation. I spent quite a while trying to understand why it won't work (actually, I only realized that switching the "syntax" on fixes the problem when typing this bug report, because it was in the "minimal.vim" example).

@clason
Copy link
Contributor

clason commented Nov 14, 2021

I'm not yet convinced though. The vim documentation says it's just highlighting. http://vimdoc.sourceforge.net/htmldoc/syntax.html

Yes, but if you keep on reading, it'll tell you what that actually means.

"daP" works fine without highlighting.

P does not rely on syntax files.

If it is really necessary to turn this on for a$ to work, then you should probably mention it in vimtex documentation. I spent quite a while trying to understand why it won't work (actually, I only realized that switching the "syntax" on fixes the problem when typing this bug report, because it was in the "minimal.vim" example).

I think that is just basic Vim knowledge (which, admittedly, is not a low bar)...

@lervag
Copy link
Owner

lervag commented Nov 14, 2021

@clason is right, but I can see how this is still unexpected for most users. Perhaps I should try and recognize if a user has syntax enabled during VimTeX initialization and add a warning unless the user also explicitly disables vimtex syntax?

@igorf-27
Copy link
Author

igorf-27 commented Nov 14, 2021

Personally, I think I would not need run-time warnings. I would rather have the warning in the documentation.

You may consider adding the following to the end of the "Installation" section of your README file. (This is a rough draft, probably containing mistakes. Feel free to modify it as you will. I just thought I'd let you know the noob's point of view.)

After the installation, you should edit your .vimrc file. It must contain something similar to the following:

" This is necessary for VimTeX to load properly when you start editing a .tex file.
filetype plugin on
" This turns syntax highlighting on, and enables Vim's syntax-related features.
" If you don't turn this on, some features of VimTeX won't work properly.
" If you don't like the highlighting, you may change your color scheme (type ':help syntax' for details).
syntax enable

" Compiler options
" This is a generic example. For specific recommendations please refer to VimTeX's documentation.
let g:vimtex_compiler_method = 'generic'
" Here you specify the command your TeX compiler will be executed with.
" expand('%:p') turns into the full path to the file you are editing.
let g:vimtex_compiler_generic = { 'command': '/usr/bin/pdflatex -synctex=1 '.expand('%:p') }

" Viewer options
" This is the executable:
let g:vimtex_view_general_viewer = '/usr/bin/okular'
" This will be sent to the viewer as command-line parameters;
" @pdf gets substituted with the full path to the tex file you are editing, the final '.tex' being replaced with '.pdf',
" @line with the line number you are staying at in Vim,
" and @tex with the full path to the tex file you are editing.
let g:vimtex_view_general_options = '--unique file:@pdf\#src:@line@tex'

" In normal mode, type <localleader>li to view the command which has been executed
" and <localleader>lo to view the compiler output.
" By default, the local leader is the symbol \.

@lervag
Copy link
Owner

lervag commented Nov 14, 2021

Thanks! I've done this now with some changes. Note that I believe the default compiler is good for most people. I do NOT want most people to use the generic compiler.

@lervag lervag closed this as completed Nov 14, 2021
@igorf-27
Copy link
Author

Well, I never used latexmk and I don't think I really need it. So the first thing I got when I installed the plugin was an error (and no output pdf). Naturally, I wanted to know what had been executed and what it had responded...
Thank you, in any case!

@lervag
Copy link
Owner

lervag commented Nov 15, 2021

Well, I never used latexmk and I don't think I really need it.

latexmk is very convenient, and I strongly suggest you install it. It should be easy to install on any system.

@igorf-27
Copy link
Author

igorf-27 commented Nov 16, 2021

Thanks for your suggestion! I will certainly set latexmk up when I have any trouble with invoking the compiler directly (when I start writing a book maybe).

In my turn, I suggest you enhance your README just a little further. This would have saved me time if I had it.

" The supported compilation methods should suit most people.
" latexmk is the default one, if you use it, you probably don't have to configure anything.
" If you want another supported compiler method (see the docs for a list), change it like this:
let g:vimtex_compiler_method = 'latexrun'
" If you want to use your own method (which is strongly not recommended), add the following lines.
let g:vimtex_compiler_method = 'generic'
" Here you specify the command your TeX compiler will be executed with.
" expand('%:p') turns into the full path to the file you are editing.
let g:vimtex_compiler_generic = { 'command': '/usr/bin/pdflatex -synctex=1 '.expand('%:p') }
" If the compiler or the viewer doesn't start properly, 
" type <localleader>li to view the exact commands which have been executed and <localleader>lo to view the compiler output.

@lervag
Copy link
Owner

lervag commented Nov 16, 2021

No, sorry. The generic compiler is not good enough, and I don't want to address that too much. Your suggested setting will fail in many cases. E.g. expand('%:p') will be expanded when you start Vim and will not work if you change to another project.

The main idea is to rely on latexmk, because this will just work. Really. The generic compiler backend is useful in certain cases, but I don't want people to use it unless they know what they are doing.

@igorf-27
Copy link
Author

Maybe like this?

" The default compilation method is latexmk. If you use it, which is strongly suggested, you probably don't have to configure anything.
" If you want another compiler method (see the docs for a list), change it like this:
let g:vimtex_compiler_method = 'latexrun'
" If the compiler or the viewer doesn't start properly, 
" type <localleader>li to view the exact commands which have been executed and <localleader>lo to view the compiler output.

Sorry if I'm bothering you.

@lervag
Copy link
Owner

lervag commented Nov 16, 2021

Sorry if I'm bothering you.

No need to be sorry; I'm glad you're being insistant, as it forces me to think twice. My previous reply was short and may have come off more "aggressive" then I meant it - I was at work and did not have time to think too much.

" The default compilation method is latexmk. If you use it, which is strongly suggested, you probably don't have to configure anything.
" If you want another compiler method (see the docs for a list), change it like this:
let g:vimtex_compiler_method = 'latexrun'
" If the compiler or the viewer doesn't start properly, 
" type <localleader>li to view the exact commands which have been executed and <localleader>lo to view the compiler output.

This is better, thanks. I'll push a variant of this now. Let me know what you think!

@lervag
Copy link
Owner

lervag commented Nov 16, 2021

See: c3991f8

@igorf-27
Copy link
Author

igorf-27 commented Nov 18, 2021

Thank you, surely, these explanations would have been useful for me, I only hope they will help other users too.

It is not clear from the current version of README that the viewer will also work without configuration in most cases, unless the user wants forward search. But then, I think, users usually do want forward search, so they will have to configure the viewer anyway. So it's OK, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants