Search code examples
vimvim-pluginpython-mode

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?


Solution

  • 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.