Issue
I would like to get an AND -operator to the following Vim command
:command! -nargs=1 GrepSource :! grep <args> `sed -n 's/^source \(.*\)/\1/p' %`
such that I can use the command to find sources at
# source <path>
# . <path>
source <path>
. <path>
I am not sure whether it is possible or not to get AND -operator to SED or Vim.
How can you add an AND -operator to the SED command?
Solution
You can just use Vim regular expressions to find the <path>
name, instead of using sed
:
:command! -nargs=1 GrepSource :exe printf("!grep '<args>' '%s'", matchstr(getline('.'), '^#\=\s*\%(source\|\.\)\s*\zs\f\+'))
I think that command should do what you want. You can use the next command to test what is happening ('exe' is changed to 'echo'):
:command! -nargs=1 GrepSourceTest :echo printf("!grep '<args>' '%s'", matchstr(getline('.'), '^#\=\s*\%(source\|\.\)\s*\zs\f\+'))
The command must be used on a line in one of the following forms:
# source <somefile>
# . <somefile>
source <somefile>
. <somefile>
Answered By - too much php