0

What is the NOP code for vimscript?

0
1

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'

1

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
1
  • 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 Layer Feb 11 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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