In command mode enter
:vimgrep "^\s*set\s" % || :copen
This produces an output like
desktop/a.tcl|11 col 1| set set
desktop/a.tcl|14 col 1| set example {1 2 3}
desktop/a.tcl|21 col 1| set pos [lsearch -exact $set $el]
desktop/a.tcl|22 col 1| set set [lreplace $set $pos $pos]
desktop/a.tcl|25 col 1| set set
desktop/a.tcl|32 col 1| set res {}
desktop/a.tcl|34 col 1| set res
in the quickfix window.
It extracts all lines starting with optional whitespace (^\s
), the word set
, and at least one whitespace (\s
) into the quickfix list, then opens the quickfix window (|| :copen
) to show the list.
(Source code is the "Sets as lists" example from https://en.wikibooks.org/wiki/Tcl_Programming/Examples)
Update:
To make things more generic, you can put this line in your Vim configuration file (~/.vimrc
if you are on Linux):
command! -nargs=1 FindFirstWord :vimgrep "^\s*<args>\s" % || :copen
Then you can search any "first word" like this:
:FindFirstWord proc
with result:
1 desktop/a.tcl|1 col 1| proc set'contains {set el} {expr {[lsearch -exact $set $el]>=0}}
2 desktop/a.tcl|6 col 1| proc set'add {_set args} {
3 desktop/a.tcl|18 col 1| proc set'remove {_set args} {
4 desktop/a.tcl|30 col 1| proc set'intersection {a b} {
5 desktop/a.tcl|38 col 1| proc set'union {a b} {
6 desktop/a.tcl|46 col 1| proc set'difference {a b} {
for the same sample code from above.