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? - vim

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.

Related

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

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.

Preventing vim script from being applied to itself

I have a vim script with substitutions:
:%s/|I\(cc\|ee\|CC\|EE\)|/|$I_{\1}$|/
:%s/|UOmax\([+-]\)|/|$U_{Omax\1}$|/
:%s/|KcmR|/|$K_{cmR}$|/
:%s/|KsvR|/|$K_{svR}$|/
:%s/Uoffset/$U_{offset}$/
..............
Sometimes I forget that this script is currently edited, so I execute so ~/.vim/macros/script.vim and it is modifying itself. How to make script know that it is currently edited?
You could check that expand('%:p') != expand('<sfile>:p') before continuing.
Honestly, I'm not sure I'd bother with that as undo will quickly fix the issue, and moreover as I often open many buffers, I'm likely make the mistake on any buffer.
BTW, another approach would be to define a tex ftplugin, where you'd define a fucntion that does the substitutions, and a buffer-local mapping that executes the function on the current buffer. This way, you won't have the possibility to run the substitution on buffers that are not LaTeX ones.
Try to install vim-quickrun and type <leader>r. vim-quickrun run the script from buffer instead of file if it's modified.

gist-vim: change token location

I use gist-vim from mattn together with gVim. Works great and everything but I don't appreciate the auth token laying around in my home directory.
So I started looking around in the plugin files and found the variable called s:configfile which the dev sets to expand('~/.gist-vim').
Which makes me believe I can include let s:configfile = expand('~/some/other/path/gist-vim') in my vimrc to change the location of my token.
But it doesn't work. Is the devs command called again when I run :Gist, so my setting gets overwritten? Just thought I need to ask before I start forking and tinkering with the code.
The .gist-vim config file name is not open for customization.
You could ask the plugin author to make it customizable.
Why can't you set the variable in your vimrc though, you may want to know. First, you need to learn about Vim's variable name namespaces, documented at :h internal-variables.
Variables prefixed with s: are variables local to a script. See :h script-variable. Thus you cannot access those from your vimrc.

Making AutoComplPop search entire project (or open buffers)?

I started using AutoComplPop for automatic code completions. It works great on the single file I am editing, but if file1 is making a reference to a method defined in file2, it doesn't find it.
The docs don't specify if there is a way to make it search a whole project directory, or even just all open buffers, so I can't tell if this is simply not something the plugin does, or if I need to enable something.
I was testing it out on two Ruby files, if that's relevant. Thanks!
Looks like that the cause of the problem is that ACP set the complete option for its purposes to .,w,b,k (see line #125 in autocomplpop/plugin/acp.vim),
call l9#defineVariableDefault('g:acp_completeOption', '.,w,b,k')
while the default value that is used when pressing \<C-n> is .,w,b,u,t,i. And it appears that the very last letter i actually makes the difference: for some reason vim would not use word from an include file opened in a buffer to complete words in another buffer. So, b option is not enough, i must also be included. Adding the following line into my .vimrc helped
let g:acp_completeOption = '.,w,b,u,t,i'
At least it worked for C++ files, but I'm not sure it fixes the problem for the case of Ruby scripts.
Depending on what is on the left of the cursor, ACP (like all the alternatives) decides what completion mechanism to use.
But ACP only uses Vim's default completion mechanisms: if <C-x><C-o> and <C-n>/<C-p> don't provide what you are looking for, ACP won't help. Try them out first.
Oh cool, this plugin looks a lot like neocomplcache but maybe cleaner...looks a little old. Little concerning that there are so many open tickets on that project and no updates in two years.
Anyway, according to the documentation it doesn't...really...say. Very likely its one of the following things:
Your pwd. If the root directory for your source is some/path then that should also be your current working directory. Try typing :cd some/path to see if that makes a difference.
The runtime path rtp. See if adding the directory with your source files to &rtp does the trick.
The path. Same deal as the &rtp setting.
Very likely this plugin is just falling back on the built in ruby omni completion functions bundled with vim. Try help ft-ruby-omni.
I just had the same problem, and I actually found a solution for this.
Apparently you have to set in your .vimrc file the following:
let g:acp_behaviorKeywordCommand = "\<C-x>\<C-i>"
This will make acp look in every file included by your source for completions, as if you were actually typing <C-p>. However, it is slow, after trying it I decided to revert using <C-p> when there are no matches and default behaviour in the other cases.

vimscript using another file instead of .viminfo

I installed a vimscript written by expert in this question.
But there is one problem in the script. When I restart the computer, the bookmarks saved by the script will disappear.
Is it possible to store the bookmarks to another file (e.g. mybookmarks.txt) instead of .viminfo file? Bookmarks stored in .viminfo disappear unpredictably.
Yes. Use the 'viminfo n' option.
From :he 'viminfo':
Name of the viminfo file. The name must immediately follow
the 'n'. Must be the last one! If the "-i" argument was
given when starting Vim, that file name overrides the one
given here with 'viminfo'. Environment variables are expanded
when opening the file, not when setting the option.
Since it seems like a good tool in general, I extracted it to a plugin: http://www.vim.org/scripts/script.php?script_id=3826. This would store bookmarks only, regardless of viminfo settings, in ~/.vim_bookmarks. The filename is configurable by changing g:simple_bookmarks_filename.
Since it's a full blown plugin now, you can send bug reports on the issue tracker, so if it's not working quite right, let me know.
Cheers.

Resources