Download vim_doc.txt Page 1 *usr_toc.txt* For Vim version 6.3. Last change

Transcript
vim_doc.txt
Page 194
Vim will run into the end of the argument and abort the command. For example,
if you start Insert mode, you must leave Insert mode as well. This works:
:execute "normal Inew text \<Esc>"
This inserts "new text " in the current line. Notice the use of the special
key "\<Esc>". This avoids having to enter a real <Esc> character in your
script.
==============================================================================
*41.6* Using functions
Vim defines many functions and provides a large amount of functionality that
way. A few examples will be given in this section. You can find the whole
list here: |functions|.
A function is called with the ":call" command.
between braces, separated by commas. Example:
The parameters are passed in
:call search("Date: ", "W")
This calls the search() function, with arguments "Date: " and "W". The
search() function uses its first argument as a search pattern and the second
one as flags. The "W" flag means the search doesn't wrap around the end of
the file.
A function can be called in an expression.
Example:
:let line = getline(".")
:let repl = substitute(line, '\a', "*", "g")
:call setline(".", repl)
The getline() function obtains a line from the current file. Its argument is
a specification of the line number. In this case "." is used, which means the
line where the cursor is.
The substitute() function does something similar to the ":substitute"
command. The first argument is the string on which to perform the
substitution. The second argument is the pattern, the third the replacement
string. Finally, the last arguments are the flags.
The setline() function sets the line, specified by the first argument, to a
new string, the second argument. In this example the line under the cursor is
replaced with the result of the substitute(). Thus the effect of the three
statements is equal to:
:substitute/\a/*/g
Using the functions becomes more interesting when you do more work before and
after the substitute() call.
FUNCTIONS
*function−list*
There are many functions. We will mention them here, grouped by what they are
used for. You can find an alphabetical list here: |functions|. Use CTRL−] on
the function name to jump to detailed help on it.
String manipulation:
char2nr()
nr2char()
escape()
strtrans()
tolower()
toupper()
match()
matchend()
matchstr()
stridx()
strridx()
strlen()
get ASCII value of a character
get a character by its ASCII value
escape characters in a string with a '\'
translate a string to make it printable
turn a string to lowercase
turn a string to uppercase
position where a pattern matches in a string
position where a pattern match ends in a string
match of a pattern in a string
first index of a short string in a long string
last index of a short string in a long string
length of a string