Comments (5)
I think this is due to the way the native packages support works, which is what I'm using, with vim-picker cloned to /home/srstevenson/.config/nvim/pack/plugins/start/vim-picker
. After adding the echom
calls to autoload/picker.vim
and plugin/picker.vim
, and a similar one to init.vim
, I can see that vim-picker isn't loaded until after init.vim
:
$ nvim
Loading init.vim
Loading plugin/picker.vim
Press ENTER or type command to continue
Which is actually what the documentation says, now I've read it again (emphasis mine):
When Vim starts up, after processing your .vimrc, it scans all directories in 'packpath' for plugins under the "pack/*/start" directory. First all those directories are added to 'runtimepath'. Then all the plugins are loaded.
Printing &runtimepath
from init.vim
confirms vim-picker isn't there when init.vim
is loaded:
/home/srstevenson/.config/nvim,/etc/xdg/nvim,/home/srstevenson/.local/share/nvim/site,/usr/local/share/nvim/site,/usr/share/nvim/site,/usr/share/nvim/runtime,/usr/share/nvim/site/after,/usr/local/share/nvim/site/after,/home/srstevenson/.local/share/nvim/site/after,/etc/xdg/nvim/after,/home/srstevenson/.config/nvim/after,/usr/share/vim/vimfiles
However, after Vim has started:
/home/srstevenson/.config/nvim,/home/srstevenson/.config/nvim/pack/plugins/start/vim-picker,/etc/xdg/nvim,/home/srstevenson/.local/share/nvim/site,/usr/local/share/nvim/site,/usr/share/nvim/site,/usr/share/nvim/runtime,/usr/share/nvim/site/after,/usr/local/share/nvim/site/after,/home/srstevenson/.local/share/nvim/site/after,/etc/xdg/nvim/after,/home/srstevenson/.config/nvim/after,/usr/share/vim/vimfiles
The documentation also says:
To load packages earlier, so that 'runtimepath' gets updated:
:packloadall
After adding :packloadall
in init.vim
before calling picker#Register
, things work as expected:
$ nvim
Loading plugin/picker.vim
Loading init.vim
Loading autoload/picker.vim
Loading plugin/picker.vim
Press ENTER or type command to continue
Therefore I don't think this is a bug in vim-picker (or Vim), but is just me not initially being aware of the difference in how this is handled with the native packages support versus the established third party tools like vim-plug and Vundle.
from vim-picker.
This was another weird bug for me. One minute it was there, and the next it was gone.
The following two init.vim
examples don't reproduce this error in either Neovim 0.3 or Vim 8.1. E.g. vim --noplugin -u [./init1.vim | ./init2.vim]
.
If I remove the runtime! plugin/**/*.vim
, then the error appears, so maybe that's where I went wrong. I wonder if that runtime!
call is triggering a premature autoload.
" Save as init1.vim
" Run as `nvim --noplugin -u ./init1.vim`
" No plugin manager.
set nocompatible " otherwise Vim 8 complains about script syntax.
set runtimepath=./repo
runtime! plugin/**/*.vim
nmap <leader>pb <Plug>PickerBuffer
call picker#Register(
\ 'recent-notes',
\ 'file',
\ 'edit',
\ 'find . -path ./git -prune -o -iname "*.md" -printf "%T@ %p\n" | sort -n | cut -d" " -f2-',
\ )
nmap <leader>pr :call picker#Execute('recent-notes')<cr>
" Save as init2.vim
" Run as `nvim --noplugin -u ./init2.vim`
" Load plugins with vim-plug.
set nocompatible " otherwise Vim 8 complains about script syntax.
set runtimepath=~/.config/nvim
source ~/.config/nvim/autoload/plug.vim
au!
call plug#begin('~/.config/nvim/plugged')
Plug 'srstevenson/vim-picker'
call plug#end()
runtime! plugin/**/*.vim
nmap <leader>pb <Plug>PickerBuffer
call picker#Register(
\ 'recent-notes',
\ 'file',
\ 'edit',
\ 'find . -path ./git -prune -o -iname "*.md" -printf "%T@ %p\n" | sort -n | cut -d" " -f2-',
\ )
nmap <leader>pr :call picker#Execute('recent-notes')<cr>
from vim-picker.
Yep, , and yet, it doesn't seem that it should since autoload/ isn't a subfolder of plugin/.runtime! plugin/**/*.vim
triggers an autoload of autoload/picker.vim
The documentation regarding "autoloading" scripts suggests that vim/neovim should Just Workβ’. I'll continue trying to identify what we're missing that causing this bug.
Using an autoload script ~
*autoload* *E746*
This is introduced in the user manual, section |41.15|.
Using a script in the "autoload" directory is simpler, but requires using
exactly the right file name. A function that can be autoloaded has a name
like this: >
:call filename#funcname()
When such a function is called, and it is not defined yet, Vim will search the
"autoload" directories in 'runtimepath' for a script file called
"filename.vim". For example "~/.config/nvim/autoload/filename.vim". That
file should then define the function like this: >
function filename#funcname()
echo "Done!"
endfunction
The file name and the name used before the # in the function must match
exactly, and the defined function must have the name exactly as it will be
called.
It is possible to use subdirectories. Every # in the function name works like
a path separator. Thus when calling a function: >
:call foo#bar#func()
Vim will look for the file "autoload/foo/bar.vim" in 'runtimepath'.
from vim-picker.
I'm chasing my tail a bit, because now I can't reproduce the error. I'm not sure why, but autoloading appears to be working. Apparently, not reading the docs beforehand was my issue, cause autoloading appears to work as expected now that I reread the docs. sigh
To debug, I added the following echom
's in the patch below. The init3.vim below documents the behavior I now see.
Without runtime! plugin/**/*.vim
, plugin/picker.vim never loads, but triggering a picker#
function will autoload autoload/picker.vim. I thought the vim docs mentioned the runtime! plugin/**/*.vim
, but I can't find where I learned of it. I believe I'm using runtime!
to compensate for the --noplugin
CLI flag that disables loading plugins.
So far, the echom
's show plugin/picker.vim loading, then autoload/picker.vim when I start Vim or Neovim as described in the comments of init3.vim.
diff --git a/autoload/picker.vim b/autoload/picker.vim
index 2d83e8d..0a06758 100644
--- a/autoload/picker.vim
+++ b/autoload/picker.vim
@@ -2,6 +2,8 @@
" Maintainer: Scott Stevenson <[email protected]>
" Source: https://github.com/srstevenson/vim-picker
+echom 'Loading autoload/picker.vim'
+
if !exists('s:command_registry')
let s:picker_command_registry = {}
endif
diff --git a/plugin/picker.vim b/plugin/picker.vim
index 4ddc19e..0cffbaa 100644
--- a/plugin/picker.vim
+++ b/plugin/picker.vim
@@ -2,49 +2,21 @@
" Maintainer: Scott Stevenson <[email protected]>
" Source: https://github.com/srstevenson/vim-picker
+echom 'Loading plugin/picker.vim'
+
if exists('g:loaded_picker')
finish
endif
" Save as ./init3.vim
" Run as `nvim --noplugin -u ./init3.vim
set nocompatible " otherwise Vim 8 complains about script syntax.
set runtimepath^=./repo
" Without runtime!, plugin/picker.vim does not load. Autoloading won't load plugin/picker.vim later.
runtime! plugin/**/*.vim
" nmap definitions don't trigger autoloading.
"nmap <leader>pb <Plug>PickerBuffer
let g:picker_find_executable = 'fd'
let g:picker_find_flags = '--color=never'
" Uncomment and picker#Register will trigger loading of autoload/picker.vim as expected.
"call picker#Register(
" \ 'recent-notes',
" \ 'file',
" \ 'edit',
" \ 'find . -path ./git -prune -o -iname "*.md" -printf "%T@ %p\n" | sort -n | cut -d" " -f2-',
" \ )
"
" nmap does not trigger autoload, but executing the keybinding <leader>pr does
" trigger loading of autoload/picker.vim.
"nmap <leader>pr :call picker#Execute('recent-notes')<cr>
from vim-picker.
@srstevenson before the error occurs at line 76, could you echom &runtimepath
and verify the path to vim-picker is in the list?
So long as I have vim-picker in runtimepath
before I use picker#blah
, I don't run into this error in my vimrc/init.vim. Vim-plug usually handles that for me, day to day. init3.vim explicitly updates the runtimepath during my minimal environment tests.
Apologies for all the noise. My inadequate understanding and interpretation of observations has led me on a merry chase.
from vim-picker.
Related Issues (20)
- Order of files in list HOT 2
- Support user customization: add framework to register new commands HOT 1
- Picker window remains open after selection HOT 7
- Ability to search most recent files HOT 2
- Bufferlist fills with vim-picker buffers HOT 4
- Can't use `picker#Register()` in init.vim if vim-picker is loaded via vim-plug HOT 2
- Lag when using mapping for PickerBuffer HOT 8
- More split window commands HOT 6
- How to get current file name in picker#Register shell_command? HOT 2
- git handling skips submodules HOT 6
- Minimize file name length in buffer HOT 6
- fzf support HOT 1
- Populate query from last time picker was opened HOT 2
- Cannot use arrow keys to select matches HOT 2
- Open vim-picker in the current window, instead of a new split window? HOT 5
- How to search for file that contains some string HOT 1
- working_directory option HOT 1
- Hide or customize "Picker [command, directory]" line HOT 1
- Unclear warning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-picker.