What is the NOP code for vimscript?
2 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
-
Typo? You mean
:
, right? I know that:
works for Bash...yet it didn't occur to me for Vim. It should have because it seems ideal. Why wrap it, though? Is there any advantage? Just for clarity/readability?– B LayerFeb 11, 2021 at 8:17