Home Explore Blog CI



neovim

17th chunk of `runtime/doc/vimeval.txt`
148e6255f27c311fef431e01bc75ea502090d057237101360000000100000fab
 number of hex characters.  Example: >
	:let b = 0zFF00ED015DAF


------------------------------------------------------------------------------
literal-string						*literal-string* *E115*

'string'		string constant			*expr-'*

Note that single quotes are used.

This string is taken as it is.  No backslashes are removed or have a special
meaning.  The only exception is that two quotes stand for one quote.

Single quoted strings are useful for patterns, so that backslashes do not need
to be doubled.  These two commands are equivalent: >
	if a =~ "\\s*"
	if a =~ '\s*'


------------------------------------------------------------------------------
interpolated-string				*$quote* *interpolated-string*

$"string"		interpolated string constant		*expr-$quote*
$'string'		interpolated literal string constant	*expr-$'*

Interpolated strings are an extension of the |string| and |literal-string|,
allowing the inclusion of Vim script expressions (see |expr1|).  Any
expression returning a value can be enclosed between curly braces.  The value
is converted to a string.  All the text and results of the expressions
are concatenated to make a new string.
								*E1278*
To include an opening brace '{' or closing brace '}' in the string content
double it.  For double quoted strings using a backslash also works.  A single
closing brace '}' will result in an error.

Examples: >
	let your_name = input("What's your name? ")
<	What's your name?  Peter ~
>
	echo
	echo $"Hello, {your_name}!"
<	Hello, Peter! ~
>
	echo $"The square root of {{9}} is {sqrt(9)}"
<	The square root of {9} is 3.0 ~

						*string-offset-encoding*
A string consists of multiple characters.  UTF-8 uses one byte for ASCII
characters, two bytes for other latin characters and more bytes for other
characters.

A string offset can count characters or bytes.  Other programs may use
UTF-16 encoding (16-bit words) and an offset of UTF-16 words.  Some functions
use byte offsets, usually for UTF-8 encoding.  Other functions use character
offsets, in which case the encoding doesn't matter.

The different offsets for the string "a©😊" are below:

  UTF-8 offsets:
      [0]: 61, [1]: C2, [2]: A9, [3]: F0, [4]: 9F, [5]: 98, [6]: 8A
  UTF-16 offsets:
      [0]: 0061, [1]: 00A9, [2]: D83D, [3]: DE0A
  UTF-32 (character) offsets:
      [0]: 00000061, [1]: 000000A9, [2]: 0001F60A

You can use the "g8" and "ga" commands on a character to see the
decimal/hex/octal values.

The functions |byteidx()|, |utf16idx()| and |charidx()| can be used to convert
between these indices.  The functions |strlen()|, |strutf16len()| and
|strcharlen()| return the number of bytes, UTF-16 code units and characters in
a string respectively.

------------------------------------------------------------------------------
option						*expr-option* *E112* *E113*

&option			option value, local value if possible
&g:option		global option value
&l:option		local option value

Examples: >
	echo "tabstop is " .. &tabstop
	if &expandtab

Any option name can be used here.  See |options|.  When using the local value
and there is no buffer-local or window-local value, the global value is used
anyway.


------------------------------------------------------------------------------
register						*expr-register* *@r*

@r			contents of register 'r'

The result is the contents of the named register, as a single string.
Newlines are inserted where required.  To get the contents of the unnamed
register use @" or @@.  See |registers| for an explanation of the available
registers.

When using the '=' register you get the expression itself, not what it
evaluates to.  Use |eval()| to evaluate it.


nesting							*expr-nesting* *E110*
-------
(expr1)			nested expression


------------------------------------------------------------------------------
environment variable					*expr-env*

$VAR			environment variable

The String value of any environment variable.  When it is not defined, the
result is an empty string.

The functions `getenv()` and `setenv()`

Title: Vim Script: String Types, Encodings, Options, Registers, Nesting, and Environment Variables
Summary
This section delves into various string types in Vim script: literal strings (single quotes), interpolated strings (allowing expression evaluation), and discusses string offset and encoding. It also covers accessing options, registers, nesting expressions, environment variables.