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

Idiomatic way to set viewer on neovim given script load order? #2740

Closed
muziejus opened this issue Jun 21, 2023 · 4 comments
Closed

Idiomatic way to set viewer on neovim given script load order? #2740

muziejus opened this issue Jun 21, 2023 · 4 comments
Labels

Comments

@muziejus
Copy link

muziejus commented Jun 21, 2023

Description

This is a bit of a followup to #2476. I was trying to get my install of neovim to recognize Skim as the viewer, but :VimtexInfo kept giving "General." Upon seeing the suggestion in the issue above, I now have vimtex_view_method set in my init.lua file. Here's the truncated version of :scriptnames:

   1: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/ftplugin.vim                                                                                                                                                     
  2: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/indent.vim                                                                                                                                                       
  3: ~/.config/nvim/init.lua                                                                                                                                                                                            
  4: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/filetype.lua                                                                                                                                                     
  9: ~/.local/share/nvim/lazy/vimtex/plugin/vimtex.vim                                                                                                                                                                  
 10: ~/.local/share/nvim/lazy/vimtex/ftdetect/cls.vim                                                                                                                                                                   
 11: ~/.local/share/nvim/lazy/vimtex/ftdetect/tex.vim                                                                                                                                                                   
 12: ~/.local/share/nvim/lazy/vimtex/ftdetect/tikz.vim                                                                                                                                                                                                                                                                                                                                          
 71: ~/.local/share/nvim/lazy/vimtex/ftplugin/tex.vim                                                                                                                                                                   
 72: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex.vim                                                                                                                                                                
 73: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/options.vim                                                                                                                                                        
 74: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/util.vim                                                                                                                                                           
 75: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/state.vim                                                                                                                                                          
 76: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/re.vim                                                                                                                                                             
 77: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/compiler/latexmk.vim                                                                                                                                               
 78: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/compiler/_template.vim                                                                                                                                             
 79: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/state/class.vim                                                                                                                                                    
 80: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/parser.vim                                                                                                                                                         
 81: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/parser/tex.vim                                                                                                                                                     
 82: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/cache.vim                                                                                                                                                          
 83: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/paths.vim                                                                                                                                                          
 84: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/view.vim                                                                                                                                                           
 85: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/view/skim.vim                                                                                                                                                      
 86: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/view/_template.vim                                                                                                                                                 
 87: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/compiler.vim                                                                                                                                                       
 88: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/qf.vim                                                                                                                                                             
 89: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/qf/latexlog.vim                                                                                                                                                    
 90: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/toc.vim                                                                                                                                                            
 91: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold.vim                                                                                                                                                           
 92: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/envs.vim                                                                                                                                                      
 93: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/cmd_single_opt.vim                                                                                                                                            
 94: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/markers.vim                                                                                                                                                   
 95: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/preamble.vim                                                                                                                                                  
 96: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/sections.vim                                                                                                                                                  
 97: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/cmd_addplot.vim                                                                                                                                               
 98: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/env_options.vim                                                                                                                                               
 99: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/cmd_multi.vim                                                                                                                                                 
100: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/items.vim                                                                                                                                                     
101: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fold/cmd_single.vim                                                                                                                                                
102: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/context.vim                                                                                                                                                        
103: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/context/cite.vim                                                                                                                                                   
104: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/parser/fls.vim                                                                                                                                                     
105: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/bib.vim                                                                                                                                                            
106: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/cmd.vim                                                                                                                                                            
107: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/complete.vim                                                                                                                                                       
108: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/debug.vim                                                                                                                                                          
109: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/delim.vim                                                                                                                                                          
110: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/doc.vim                                                                                                                                                            
111: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/env.vim                                                                                                                                                            
112: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/format.vim                                                                                                                                                         
113: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/fzf.vim                                                                                                                                                            
114: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/imaps.vim                                                                                                                                                          
115: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/include.vim                                                                                                                                                        
116: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/info.vim                                                                                                                                                           
117: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/jobs.vim                                                                                                                                                           
118: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/kpsewhich.vim                                                                                                                                                      
119: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/log.vim                                                                                                                                                            
120: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/matchparen.vim                                                                                                                                                     
121: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax.vim                                                                                                                                                         
122: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/pos.vim                                                                                                                                                            
123: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/misc.vim                                                                                                                                                           
124: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/motion.vim                                                                                                                                                         
125: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/nvim.vim                                                                                                                                                           
126: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/profile.vim                                                                                                                                                        
127: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/scratch.vim                                                                                                                                                        
128: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/text_obj.vim                                                                                                                                                       
129: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/ui.vim                                                                                                                                                             
130: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/text_obj/targets.vim                                                                                                                                               
131: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/ftplugin/tex.vim                                                                                                                                                 
132: ~/.local/share/nvim/lazy/vimtex/after/ftplugin/tex.vim                                                                                                                                                             
133: ~/.config/nvim/ftplugin/tex.lua                                                                                                                                                                                    
134: ~/.local/share/nvim/lazy/vimtex/indent/tex.vim                                                                                                                                                                     
135: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/indent/tex.vim                                                                                                                    
137: ~/.local/share/nvim/lazy/vimtex/syntax/tex.vim                                                                                                                                                                     
138: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/core.vim                                                                                                                                                    
139: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/nested.vim                                                                                                                                                  
140: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/packages.vim                                                                                                                                                
141: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/amsmath.vim                                                                                                                                               
142: /usr/local/Cellar/neovim/0.9.0/share/nvim/runtime/syntax/tex.vim                                                                                                                                                   
144: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/tabularx.vim                                                                                                                                              
145: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/array.vim                                                                                                                                                 
146: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/amssymb.vim                                                                                                                                               
147: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/url.vim                                                                                                                                                   
148: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/hyperref.vim                                                                                                                                              
149: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/nameref.vim                                                                                                                                               
150: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/pgfplots.vim                                                                                                                                              
151: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/tikz.vim                                                                                                                                                  
153: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/mathtools.vim                                                                                                                                             
154: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/listings.vim                                                                                                                                              
155: ~/.local/share/nvim/lazy/vimtex/autoload/vimtex/syntax/p/amsthm.vim                                                                                                                                                

In this list, ~/.config/nvim/ftplugin/tex.lua is where I was setting vim.g.vimtex_view_method = "skim", but it wasn't taking. So, like I said, I now have it as a line in my init.lua. This works, but it strikes me as unideal, as the rest of the settings (including other Skim settings) are in the ftplugin file.

So what would be the most idiomatic way, given the above, of ensuring that the viewer is set at the right time? Would it make sense to provide a warning about this in the documentation, like with g:vimtex_include_indicators?

Do you use a latexmkrc file?

No

VimtexInfo

System info:
  OS: macOS 13.4 (22F66)
  Vim version: NVIM v0.9.0
  Has clientserver: true
  Servername: /var/folders/j9/r4mh7gcn7qd8y62m63dzv00r0000gn/T/nvim.moacir/yVq8vP/nvim.5805.0

VimTeX project: 04
  base: 04.tex
  root: /Users/moacir/Documents/msds/coursework/linear-algebra/homework
  tex: /Users/moacir/Documents/msds/coursework/linear-algebra/homework/04.tex
  main parser: fallback current file
  document class: 
  source files:
    04.tex
    ../../../../../Library/texmf/tex/latex/math-homework.tex
    ../../../../../Library/texmf/tex/latex/package-sets/default.tex
    ../../../../../Library/texmf/tex/latex/package-sets/math.tex
    ../../../../../Library/texmf/tex/latex/fonts/math.tex
    ../../../../../Library/texmf/tex/latex/layouts/default.tex
    ../../../../../Library/texmf/tex/latex/outputs/pdf.tex
    ../../../../../Library/texmf/tex/latex/macros/linear-algebra.tex
  compiler: latexmk
    engine: -xelatex
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: Skim
  qf method: LaTeX logfile
@muziejus muziejus added the bug label Jun 21, 2023
@lervag
Copy link
Owner

lervag commented Jun 21, 2023

This is a bit of a followup to #2476. I was trying to get my install of neovim to recognize Skim as the viewer, but :VimtexInfo kept giving "General." Upon seeing the suggestion in the issue above, I now have vimtex_view_method set in my init.lua file. …

In this list, ~/.config/nvim/ftplugin/tex.lua is where I was setting vim.g.vimtex_view_method = "skim", …

I would propose using ~/.config/nvim/plugin/vimtex.lua for setting your VimTeX related settings and ~/.config/nvim/ftplugin/tex.lua for your additional customizations that you want to apply for .tex files.

Would it make sense to provide a warning about this in the documentation, like with g:vimtex_include_indicators?

Sort of, but it's slightly hard as I would need to check if the settings used at init time have been changed at some later time and then warn. And I would need to specifically mark the settings that should be configured early. Instead, I generally always ask people to avoid putting their VimTeX settings in ftplugin/. I don't quite understand why so many people still do it, though. Perhaps it is because of the popular guide by ejmastnak, cf. this comment?

In any case, I believe my above advice should work well.

@lervag lervag closed this as completed Jun 21, 2023
@muziejus
Copy link
Author

Thanks for the quick response. I can make a few notes:

  1. I was definitely inspired by the guide, as it's linked to from here. Additionally, I think in the VimTeX documentation, the only file suggested for making configuration settings is precisely the ftplugin/ file. I'd have never thought to do otherwise if not for the guide, etc.
  2. To that end, I use ~/.config/nvim/lua/plugins/ only for telling Lazy what plugins to load, offloading the configuration for ~/.config/nvim/after/plugin/. Either way, I've made the change, and things are working, and loading in lua/plugins surely feels better than in init.lua.

Thanks again!

@lervag
Copy link
Owner

lervag commented Jun 22, 2023

…, I think in the VimTeX documentation, the only file suggested for making configuration settings is precisely the ftplugin/ file.

ftplugin/ is never suggested as a file for making configuration settings in any general sense. It is mentioned for some specific cases, though.

To that end, I use ~/.config/nvim/lua/plugins/ only for telling Lazy what plugins to load, offloading the configuration for ~/.config/nvim/after/plugin/. Either way, I've made the change, and things are working, and loading in lua/plugins surely feels better than in init.lua.

What I mean was not lua/plugins, it was to use ~/.config/nvim/plugin/vimtex.lua.

Alternatively, I would add an init function to the vimtex load in your Lazy spec. This is what I do. I.e.: config/nvim/lua/plugins/text.lua:

return {
  {
    "lervag/vimtex",
    init = function()
      vim.g.vimtex_view_method = "skim"
    end,
  },
  --

I think this is a clear way than to add the option above the way you did.

@muziejus
Copy link
Author

Thanks!

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

2 participants