Skip to content

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

@sedimentation-fault

Description

@sedimentation-fault

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:

  • OS: Gentoo Linux
  • Terminal: x11-misc/tabbed-0.6-r1 with x11-terms/xterm-367, or app-editors/gvim-8.2.3741
  • Shell: app-shells/bash-5.1_p16
  • Vim version: app-editors/vim-8.2.3741
  • Plugin manager: None
  • Plugin version: git clone of yesterday
  • Nnn version: app-misc/nnn-4.8

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions