1

I am trying to check if a line of code is in a file in vimscript. I need to use the return value of grep inside my if but I don't know hot get it.

This does not work of course:

if $(execute '!grep -q ' . shellescape(lineToAdd) . ' ' . shellescape(g:projectPath))
    echom "Already added."
    return
endif

1 Answer 1

1

See v:shell_error as seen in this Vim documentation,

Result of the last shell command. When non-zero, the last shell command had an error. When zero, there was no problem. This only works when the shell returns the error code to Vim. The value -1 is often used when the command could not be executed. Read-only.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.