user985675
user985675

Reputation: 291

vim how enter multiple commands at command prompt

How should I enter the following as a single string at the command prompt in vim

:let v:errmsg = ""  
:silent! /\cend of .*project gutenberg  
:if v:errmsg != ""  
:echo "Not found"  
:endif  

This does not work, the message is not printed.

:let v:errmsg = ""|:silent! /\cend of .*project gutenberg|:if v:errmsg != ""|:echo "Not found"|:endif  

Upvotes: 2

Views: 683

Answers (2)

Christian Brabandt
Christian Brabandt

Reputation: 8248

Well, the problem is the normal search you are doing. The range search sees the | as part of its arguments and therefore it cannot be used to enter another command. Therefore, wrap it into an :exe call like this:

let v:errmsg = ""|exe 'sil! /\cend of .*project gutenberg'|if v:errmsg != ""|echo "Not found"|endif 

Upvotes: 2

ZyX
ZyX

Reputation: 53604

Range-search may be not the best option in your case. You can use

if !search('\cend of .*project gutenberg') | echo 'Not found' | endif

if you are fine with not updating last search pattern.

Upvotes: 0

Related Questions