Vim Tips Wiki
Register
(Change <tt> to <code>, perhaps also minor tweak.)
(Changing command to lowercase.)
Line 30: Line 30:
   
 
==Listing to a scratch buffer==
 
==Listing to a scratch buffer==
The following code (for your [[vimrc]]) defines the <code>:Scriptnames</code> user command to list loaded scripts in a scratch buffer which you can search and edit. It is also useful to put the cursor on the name of a script, and type <code>gf</code> ("goto file") to show that script.
+
The following code (for your [[vimrc]]) defines the <code>:scriptnames</code> user command to list loaded scripts in a scratch buffer which you can search and edit. It is also useful to put the cursor on the name of a script, and type <code>gf</code> ("goto file") to show that script.
   
 
The <code>:Scriptnames</code> command takes an argument which is a pattern to match the names of scripts of interest. Lines which do not contain the given argument are removed from the list. For example, entering <code>:Scriptnames surround</code> will list all scripts which contain "surround" in the path name of the script.
 
The <code>:Scriptnames</code> command takes an argument which is a pattern to match the names of scripts of interest. Lines which do not contain the given argument are removed from the list. For example, entering <code>:Scriptnames surround</code> will list all scripts which contain "surround" in the path name of the script.

Revision as of 17:35, 1 August 2013

Tip 515 Printable Monobook Previous Next

created 2003 · complexity intermediate · author Yakov Lerner · version 6.0


The :scriptnames command can be used to list the scripts that Vim has loaded. This tip provides information on how to list scripts that Vim failed to load. In addition, a user command is provided to list loaded scripts in a scratch buffer which you can search and edit (convenient for use of gf to edit scripts).

Listing loaded scripts

To see the file names of all scripts loaded (sourced) by Vim, including those loaded implicitly at startup, enter:

:scriptnames

The list does not include "would-be scripts" (scripts that Vim tried to open but which failed without warning, perhaps because the script could not be found). To see the "would-be" scripts use the -V option when starting Vim:

vim -V

Use the following to show the system-dependent locations of configuration files (but not the location of system/personal plugins):

vim --version

Listing to a scratch buffer

The following code (for your vimrc) defines the :scriptnames user command to list loaded scripts in a scratch buffer which you can search and edit. It is also useful to put the cursor on the name of a script, and type gf ("goto file") to show that script.

The :Scriptnames command takes an argument which is a pattern to match the names of scripts of interest. Lines which do not contain the given argument are removed from the list. For example, entering :Scriptnames surround will list all scripts which contain "surround" in the path name of the script.

Create file ~/.vim/plugin/scriptnames.vim (Unix) or $HOME/vimfiles/plugin/scriptnames.vim (Windows) containing the script below, then restart Vim.

" Execute 'cmd' while redirecting output.
" Delete all lines that do not match regex 'filter' (if not empty).
" Delete any blank lines.
" Delete '<whitespace><number>:<whitespace>' from start of each line.
" Display result in a scratch buffer.
function! s:Filter_lines(cmd, filter)
  let save_more = &more
  set nomore
  redir => lines
  silent execute a:cmd
  redir END
  let &more = save_more
  new
  setlocal buftype=nofile bufhidden=hide noswapfile
  put =lines
  g/^\s*$/d
  %s/^\s*\d\+:\s*//e
  if !empty(a:filter)
    execute 'v/' . a:filter . '/d'
  endif
  0
endfunction
command! -nargs=? Scriptnames call s:Filter_lines('scriptnames', <q-args>)

References

Comments

The Headlights plugin (for gvim or MacVim) creates menus for installed plugins along with their files (and commands, mappings, abbreviations, etc).