4

What is the NOP code for vimscript?

0

3 Answers 3

4

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'

2

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
0
2

The command execute with no arguments is a no-op. Importantly, :echo 'bar' | execute | echo 'foo' does not transform to contain a print.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.