Skip to main content
Bounty Awarded with 100 reputation awarded by Léo Léopold Hertz 준영
Added lines with source
Source Link
chmeee
  • 7.6k
  • 4
  • 33
  • 43

This worked for me:

:! grep manual `sed -n 's/^\. \(.*\)/\1/p' %` 

The sed part looks for source files and gives them as arguments to grep.

To avoid having to type this everytime you can create a command like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -n 's/^\. \(.*\)/\1/p' %` 

Be careful when searching for more than one word, you'll have to use quotes. For example:

:SourceGrep "sudo ssh" 

EDIT:

To search for lines with 'source' as well as '.':

:! grep manual `sed -rn 's/^(\.|source) (.*)/\2/p' %` 

The command will look like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -rn 's/^(source|\.) (.*)/\2/p' %` 

This worked for me:

:! grep manual `sed -n 's/^\. \(.*\)/\1/p' %` 

The sed part looks for source files and gives them as arguments to grep.

To avoid having to type this everytime you can create a command like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -n 's/^\. \(.*\)/\1/p' %` 

Be careful when searching for more than one word, you'll have to use quotes. For example:

:SourceGrep "sudo ssh" 

This worked for me:

:! grep manual `sed -n 's/^\. \(.*\)/\1/p' %` 

The sed part looks for source files and gives them as arguments to grep.

To avoid having to type this everytime you can create a command like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -n 's/^\. \(.*\)/\1/p' %` 

Be careful when searching for more than one word, you'll have to use quotes. For example:

:SourceGrep "sudo ssh" 

EDIT:

To search for lines with 'source' as well as '.':

:! grep manual `sed -rn 's/^(\.|source) (.*)/\2/p' %` 

The command will look like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -rn 's/^(source|\.) (.*)/\2/p' %` 
Source Link
chmeee
  • 7.6k
  • 4
  • 33
  • 43

This worked for me:

:! grep manual `sed -n 's/^\. \(.*\)/\1/p' %` 

The sed part looks for source files and gives them as arguments to grep.

To avoid having to type this everytime you can create a command like this:

:command! -nargs=1 SourceGrep :! grep <args> `sed -n 's/^\. \(.*\)/\1/p' %` 

Be careful when searching for more than one word, you'll have to use quotes. For example:

:SourceGrep "sudo ssh"