Vimtex variables are said to be undefined (so I can't change them) - vim

I'm using the vimtex plugin with vim-plug plugin manager to edit LaTex files. I'm trying to disable the Callback feature in my vimrc (so I stop getting warnings about it whenever I open a .tex file), so I let g:vimtex_compiler_latexmk.callback = 0, but I get an error saying g:vimtex_compiler_latexmk is an undefined variable.
Attempting :echo g:vimtex_compiler_latexmk gives the same error message.
The only variable I can seem to change or even view is g:vimtex_enabled, so if I want to let g:vimtex_enabled = 0, I can do that and disable vimtex altogether.
Any ideas why and what I can do to fix this? Vimtex otherwise works flawlessly despite this.
I'm running VIM 7.4 on Linux Mint 18.

Vim doesn't let you initialize a dictionary variable like that. There's no default value for g:vimtex_compiler_latexmk, so you first have to initialize it as a dictionary:
let g:vimtex_compiler_latexmk = {}
let g:vimtex_compiler_latexmk.callback = 0
Or just initialize and assign at once:
let g:vimtex_compiler_latexmk = {'callback': 0}
Either way, once it's initialized, you can use the . accessor shortcut.
The reason you're only seeing g:vimtex_enabled is because vimtex autoloads when you access a .tex file. Load one up, and you'll see a lot more variables. You still won't see g:vimtex_compiler_latexmk, though, because it has no value unless you set one.
I suspect you are assigning g:vimtex_enabled in your vimrc, and that's why you see that one even without loading a LaTeX file.

Related

If you change a global variable in a vim plugin (python-mode) and reload it, isn’t it equivalent to just loading the .vimrc at startup?

Using Vim version: 7.4
In this line of the Python-mode documentation: https://github.com/python-mode/python-mode/blob/01c3131343aaa3c76f8cb656b5e9f54ac90ca04b/doc/pymode.txt#L234
it says that I can turn-on the variable (g:pymode_run) using
let g:pymode_run=1,
to run my python file using “:PymodeRun” or use it via ‘<leader>r’
If there is no modification to my Vimrc file, the default setting is:
let g:pymode_run=1
However, if the default setting in your vimrc file is
let g:pymode_run=0,
you load your .vimrc, and attempt to then change the variable using
let pymode_run=1 or let g:pymode_run=1 (both of this is equivalent, as we are dealing with the global variable here),
:PymodeRun doesn’t work.
If you do “:so ~/.vimrc” after changing let g:pymode_run=1, it doesn’t work either.
The only solution to this, that I found, is to change to “let g:pymode_run=1” in your ~/.vimrc, shutdown VIM and restart vim.
Then it works as expected.
Since pymode_run is a variable which determines whether :PymodeRun should run or not, shouldn’t changing the variable pymode_run from 0 to 1 in the current VIM session, also enable running :PymodeRun, withough having to reload VIM?
g:pymode_run seems to be used here, which means that the variable is used to decide if the command :PymodeRun (and related bindings) should be defined or not in the first place. In other words, it isn't checked when calling :PymodeRun, but is checked on editing python files. This is why setting the value afterwards doesn't work. This is probably because changing the option while editing is not expected (I don't see much rationale either).
As this variable is checked in ftplugin, I believe reloading the file (:ed %) suffices for let g:pymode_run=1 to take effect.

Why I cannot save my `_vimrc` after defining a register item?

After adding the following definition of registrar, I can no longer save my _vimrc.
let #m = "V}k:s/ /\&/gV{j,tt$b${j$yV}k:s/\&kbkb&/ /kbkb/g"
Here goes the complete error picture. As it turned out, my definition in _vimrc had not been precisely displayed on stackoverflow. What I saw in the edit box goes to the very end of this post.
The editing box:
Weirdly though, commenting it out also did no help! I still cannot save my _vimrc. Error message shall be the same.
The following setting in my _vimrc had caused the problem:
set set encoding=utf-8
This setting is not evil by itself, but (I guess) it will lead to all the keystrokes typed through the keyboard encoded differently. Vim don't like it.
So, when I recorded the macro, while keeping such setting active, Vim was recording something that is only compatible with utf-8. Then, when I tried to assign what has been captured by the macro to a certain register item, Vim was confused about those weird keystrokes encoded "wrongly".
Solution in short:
Record the macro with encoding set as default (commenting out the existing encoding specification);
Paste from register to _vimrc and the definition shall be
let #g = "{}{jV}k:s/ /\&/gV{j,tt$^M{j$yV}k:s/&//g^M"
Or, visually in _vimrc as follows:

Setting fountainwiki variables in vim

I've installed the fountainwiki, a plugin that offers wiki like features for fountain - the markdown language for screenwriting. In the help file for fountainwiki a lot of options are listed for example:
Auto-indent scheme: 0 = off, 1 = on (default).
let g:Fountainwiki_Auto_Indent = 0
I can't get those options to work. I've tried this (in normal mode):
:let g:Fountainwiki_Auto_Indent = 0
And I've tried adding this to .vimrc:
let g:Fountainwiki_Auto_Indent = 0
Neither works to switch off auto-indentation (tried other options as well).
What would be the correct way to execute the command?
Configuration variables must usually be put into your ~/.vimrc, because that is the first config file read when Vim starts up, and the plugins read the configuration override once on startup.
You can verify the value via
:echo g:Fountainwiki_Auto_Indent
If you have problems with a particular plugin, its author is the best resource; email him or open an issue in the accompanying issue tracker, if there is any.

NERDTree can't write a bookmark to a file

When I try to create a bookmark in NERDTree (win7 with emacs installed)
:Bookmark mybookmark
I get this:
E482: Can't create file C:\emacs\home/.NERDTreeBookmarks
NERDTree is trying to write the bookmark to "$HOME/.NERDTreeBookmarks" by default. This is how it looks like in the code:
call s:initVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
While it's possible that you've set the "g:NERDTreeBookmarksFile" variable somewhere in the configuration, it's a lot more likely that emacs has, for some reason, set your "HOME" environment variable to "C:\emacs\home". This explains the slash/backslash mixup as well. You can try two things:
Change the $HOME variable to your home dir, "C:\Users\your-username". A quick google turns up this guide for windows 7: http://www.itechtalk.com/thread3595.html
Just set the "g:NERDTreeBookmarksFile" variable to your home dir ("C:\Users\your-username").
I'd recommend the second option, since it's definitely going to work. You may need to escape the backslashes and spaces, but I can't be sure how at the moment. Try it out in all of these ways and see which one works for you:
let g:NERDTreeBookmarksFile = "C:\Users\Your\ Username"
let g:NERDTreeBookmarksFile = "C:\\Users\\Your\ Username"
let g:NERDTreeBookmarksFile = 'C:\Users\Your Username'

How can I get vim's closetag plugin to work for all html tags?

I am using the closetag.vim plugin, but it doesn't seem to work for all tags. In the plugin code there is the ignored tags var that contains some one that I noticed were not closing ex dd dl, but there are many others that aren't in the list that are not working (p, ul, li).
Nothing seemed to happen after updating the list of ignored tags.
To get this plugin to work you just enter the tag text and click tab, right? ie div
Am I missing something?
How did you install the plugin?
I had troubles with closetag.vim when I installed it in ~/.vim/plugins. Then I moved it into ~/.vim/scripts instead, and added the following to my .vimrc:
:let g:closetag_html_style=1
:source ~/.vim/scripts/closetag.vim
and now it works fine for me. I find that it closes all tags (including those included in the 'ignore' list), but not those that are self-closing (e.g. <img/>).
In the version of the script that I am using (0.9.1), it defines <C-_> as the trigger for completing tags. If you have mapped the command to <tab>, then that should work too.
I also cannot get this plugin to work, however in my case what it does it throw out a number of error messages before finally working. For instance if I try to close an H1 tag I will get the error Error Detected while processing function GetCloseTag and the error is an undefined variable b:UnaryTagsStack.
Seems like it would be a useful plugin but it just won't cooperate.
I had the same issue and nelstrom's answer above didn't solve it for me. What worked for me was adding the following lines to my .vimrc:
if !exists("b:unaryTagsStack") || exists("b:closetag_html_style")
if &filetype == "html" || exists("b:closetag_html_style")
let b:unaryTagsStacktack="area base br dd dt hr img input link meta param"
else " for xml and xsl
let b:unaryTagsStack=""
endif
endif
if !exists("b:unaryTagsStack")
let b:unaryTagsStack=""
endif
I don't know why adding just let b:unaryTagsStack="" didn't do the trick, but the combination above seems to fix it in all file types for me.

Resources