I just recently found a very nice command to search for a pattern in a document, and display all hits:
:g/pattern/z#.1
Since the command is a bit cumbersome to type, I would like to make a shortcut, so instead of typing the command above, I could simply type
:sl pattern
(sl
stands for search & list, for lack of a better name.)
I wonder what is the best way to do this. I think one first needs to define a function
function! SearchList(pattern)
f/a:pattern/z#.1
endfunction
But the only thing the function does, is to show its own content (since this is the only occurrence of a:pattern
in my .vimrc
.
So here I'm stuck. To create a mapping, is the function actually needed? Or what is the best way to define the mapping? And if indeed a function is the way to go, how would I write this function?
:exe ":g/".a:pattern."/z#.1