What is the NOP code for vimscript?
3 Answers
VimScript interpreter ignores colons and spaces, so :
could be qualified as "nop" command. For example, echo 'foo' | :
is the same as just echo 'foo'
.
However, there's a problem: due to Vi compatibility :|
is forcefully parsed as :print
, so echo 'foo' | : | echo 'bar'
surprisingly transforms into echo 'foo' | print | echo 'bar'
.
To deal with this one can create a user-defined command, e.g.
command! -bar Nop :
Now this works: echo 'foo' | Nop | echo 'bar'
According to the url provided:
The simplest possible statement in C that behaves like a NOP is the so-called null statement, which is just a semi-colon in a context requiring a statement. (A compiler is not required to generate a NOP instruction in this case; typically, no instructions whatsoever would be generated.)
;
Alternatively, an empty block (compound statement) may be used, and may be more legible:
{}
What about "empty command" :
func! Test()
:
endfunc
The command execute
with no arguments is a no-op. Importantly, :echo 'bar' | execute | echo 'foo'
does not transform to contain a print
.