1

After yanking into register + from Visual Block mode, the lines break are marked with ^@.

I would like to detect this character, but I can't.. For example, if register + contains ^@ as shown below

stridx(getreg('+'), '^@')

returns -1. Same for

stridx(getreg('+'), '\^\@')

So what is the proper way of detecting it, more generally, inside a string?

1 Answer 1

4

The ^@ is the code for the NUL character. It is used by Vim to separate the lines internally.

The clipboard contains actually new lines that are output in your context using the NUL character.

You can input the new line character using the following key sequence Ctrl vCtrl j

In VimScript the new line character is "\n".

The following code should not return -1

stridx(getreg('+'), "\n")
4
  • 1
    you mean Ctrl-V Ctrl-J? Jun 16, 2023 at 6:14
  • @Christian, thanks for the hint :-) Jun 16, 2023 at 6:16
  • 2
    Character ^@ is actually called NUL, not really "null" (see man ascii) and is actually represented by \0. The \n escape is actually "new line" (ascii LF or nr2char(10)). The reason why ^@ is showing for new lines here is explained in :help NL-used-for-Nul, Vim uses "\n" to represent NUL bytes internally and this representation leaks sometimes, resulting in the display including ^@ for new lines.
    – filbranden
    Jun 16, 2023 at 12:46
  • 1
    @filbranden, thanks for the precision. I adapted the answer accordingly. Let me know if it needs further improvement. Jun 16, 2023 at 13:12

Your Answer

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

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