char2nr("ABC") " returns 65
echo char2nr("á") " returns 225
echo char2nr("á"[0]) " returns 195
echo char2nr("\<M-x>") " returns 128
< Non-ASCII characters are always treated as UTF-8 characters.
{utf8} is ignored, it exists only for backwards-compatibility.
A combining character is a separate character.
|nr2char()| does the opposite.
Returns 0 if {string} is not a |String|.
Parameters: ~
• {string} (`string`)
• {utf8} (`any?`)
Return: ~
(`0|1`)
charclass({string}) *charclass()*
Return the character class of the first character in {string}.
The character class is one of:
0 blank
1 punctuation
2 word character (depends on 'iskeyword')
3 emoji
other specific Unicode class
The class is used in patterns and word motions.
Returns 0 if {string} is not a |String|.
Parameters: ~
• {string} (`string`)
Return: ~
(`0|1|2|3|'other'`)
charcol({expr} [, {winid}]) *charcol()*
Same as |col()| but returns the character index of the column
position given with {expr} instead of the byte position.
Example:
With the cursor on '세' in line 5 with text "여보세요": >vim
echo charcol('.') " returns 3
echo col('.') " returns 7
<
Parameters: ~
• {expr} (`string|any[]`)
• {winid} (`integer?`)
Return: ~
(`integer`)
charidx({string}, {idx} [, {countcc} [, {utf16}]]) *charidx()*
Return the character index of the byte at {idx} in {string}.
The index of the first character is zero.
If there are no multibyte characters the returned value is
equal to {idx}.
When {countcc} is omitted or |FALSE|, then composing characters
are not counted separately, their byte length is added to the
preceding base character.
When {countcc} is |TRUE|, then composing characters are
counted as separate characters.
When {utf16} is present and TRUE, {idx} is used as the UTF-16
index in the String {expr} instead of as the byte index.
Returns -1 if the arguments are invalid or if there are less
than {idx} bytes. If there are exactly {idx} bytes the length
of the string in characters is returned.
An error is given and -1 is returned if the first argument is
not a string, the second argument is not a number or when the
third argument is present and is not zero or one.
See |byteidx()| and |byteidxcomp()| for getting the byte index
from the character index and |utf16idx()| for getting the
UTF-16 index from the character index.
Refer to |string-offset-encoding| for more information.
Examples: >vim
echo charidx('áb́ć', 3) " returns 1
echo charidx('áb́ć', 6, 1) " returns 4
echo charidx('áb́ć', 16) " returns -1
echo charidx('a😊😊', 4, 0, 1) " returns 2
<
Parameters: ~
• {string} (`string`)
• {idx} (`integer`)
• {countcc} (`boolean?`)
• {utf16} (`boolean?`)
Return: ~
(`integer`)
chdir({dir}) *chdir()*
Change the current working directory to {dir}. The scope of
the directory change depends on the directory of the current
window:
- If the current window has a window-local directory
(|:lcd|), then changes the window local directory.
- Otherwise, if the current tabpage has a local
directory (|:tcd|) then changes the tabpage local
directory.
- Otherwise, changes the global directory.
{dir} must be a String.
If successful, returns the previous working directory. Pass
this to another chdir() to restore the directory.
On failure, returns an empty string.
Example: >vim
let save_dir = chdir(newdir)
if save_dir !=