1

I am wondering how to open a file or load it into a buffer using the index shown by :scriptnames?

 23: /usr/share/vim/vim80/plugin/tarPlugin.vim
 24: /usr/share/vim/vim80/plugin/tohtml.vim
 25: /usr/share/vim/vim80/plugin/vimballPlugin.vim
 26: /usr/share/vim/vim80/plugin/zipPlugin.vim

e.g., the 25th?

0
6

Since Vim 8.1.553, you can simply supply a count to the scriptnames command to have it edited. So in your case, you can simply use:

 :25scriptnames

or

 :scriptnames 25

to edit the zipPlugin.vim

3

Another option is the Scriptnames command in Tim Pope's vim-scriptease plugin.

https://github.com/tpope/vim-scriptease

The script names are loaded into a quickfix list. Hitting return opens the script name under the cursor.

1

Another alternative is to load the output of :scriptnames in a buffer like so:

:call setline('.', split(execute('scriptnames'), '\n'))

This will give you this in the current buffer:

  1: ~/.vim/vimrc
  2: /usr/share/vim/vim82/syntax/syntax.vim
  3: /usr/share/vim/vim82/syntax/synload.vim
  4: /usr/share/vim/vim82/syntax/syncolor.vim
  5: /usr/share/vim/vim82/filetype.vim
  [..]

And you can then use gf to go to the files.


I find this pattern in general useful enough that I have a little command for it:

comm! -complete=command -nargs=+ Load call call(
            \ (len(filter(getline(1, '$'), {_, v -> len(v) > 0})) == 0 ? 'setline' : 'append'),
            \ ['.', split(execute(join([<f-args>], ' ')), '\n')])

You can then just type :Load scriptnames.

You can modify it to automatically create a new (scratch) buffer or split or whatnot (although you can use :new | Load scriptnames).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.