mcchrish / nnn.vim

File manager for vim/neovim powered by n³
BSD 2-Clause "Simplified" License
646 stars 25 forks source link

Undefined variable: g:nnn#action in ftplugin/nnn.vim #168

Open sedimentation-fault opened 1 year ago

sedimentation-fault commented 1 year ago

Problem

Cloned nnn.vim (the directory) into /usr/local/share/vim/plugin/ In my vimrc I have added /usr/local/share/vim to my runtimepath. Upon start of vim/gvim, I get:

Error detected while processing /usr/local/share/vim/plugin/nnn.vim/ftplugin/nnn.vim:
line    6:
E121: Undefined variable: g:nnn#action
E116: Invalid arguments for function empty(g:nnn#action)
line   12:
E121: Undefined variable: g:nnn#set_default_mappings

How to reproduce

See above.

Expected behavior

No error, of course

Environment:

Solution Change

if !empty(g:nnn#action)

to

if exists('g:nnn#action') && !empty(g:nnn#action)

and

if g:nnn#set_default_mappings

to

if exists('g:nnn#set_default_mappings') && g:nnn#set_default_mappings

Now, the errors went away, but I am not sure if this is OK, or if I just covered up a more serious problem. Are nnn#action and g:nnn#set_default_mappings supposed to be defined at the time ftplugin/nnn.vim uses them - and what happens if they are not? ftplugin/nnn.vim will not retouch them, since b:nnn_ftplugin will be 1 subsequently, which will cause it to return immediately at the start...