What is logical AND in Sed/Vim?


What is logical AND in Sed/Vim?



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?




Can vim be made to only expand tabs to the left of text?

1:



How to automatically update tag file in vim?
You can just use Vim regular expressions to find the <path> name, instead of using sed:.
vim getting the current value of vim foldmarker
: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.


How do I operate on highlighted text in VI/VIM?
You can use the next command to test what is happening ('exe' is changed to 'echo'):.
Vim comma key not working
: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:.
How can I open another vertical window (:vsp) on the left in vim?
# source <somefile> # . 


how to load another file's content to current file in vim
<somefile> source <somefile> .


VI/VIM file handling
<somefile>


2:


I'm not clear what you are trying to achieve/searching for.

Maybe if you elaborate what exactly are you trying to do and what the AND is supposed to do we could help more.. This solution executes from vim command:.
grep PATTERN /some/path/* 
If you are looking for files in a directory you would use:.
ls /some/path | grep PATTERN 
You can update relevant pieces of the command.. Anyway.... From your script I assume you have a line specifying path to a directory which you want to grep for something, e.g.

you want to search path for PATTERN, you position cursor on the line with path, then you want to extract the path and grep it for the pattern with your command, example line in file:.
source /some/path 
This command should do what you expect:.
:command! -nargs=1 GrepSource :exe printf("!grep '<args>' '%s'/*", substitute( getline('.'), "\\%(source\\s*\\)\\(.*\\)$", "\\1","")) 
With cursor on the line with path starting with word source you can execute the above command:.
:GrepSource PATTERN 
This will search files in '/some/path/' for word PATTERN.. I assume paths in your file don't end with slash '/' and I assume you want to search in files so I append '/*' at the end of path to search, ending with command:.
grep PATTER /some/path/* 
I have used substitute command that replaces.
source /some/path 
with .
/some/path 
Which is then used in printf to create the actual command..



94 out of 100 based on 64 user ratings 214 reviews