home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / mac / vim55rt.sit / runtime / doc / eval.txt < prev    next >
Encoding:
Text File  |  1999-09-25  |  66.0 KB  |  1,820 lines  |  [TEXT/MPS ]

  1. *eval.txt*      For Vim version 5.5.  Last change: 1999 Sep 16
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Expression evaluation                    *expression* *expr*
  8.  
  9. Note: Expression evaluation can be disabled at compile time.  If this has been
  10. done, the features in this document are not available.  See |+eval| and the
  11. last chapter below.
  12.  
  13. 1. Variables        |variables|
  14. 2. Expression syntax    |expression-syntax|
  15. 3. Internal variable    |internal-variables|
  16. 4. Builtin Functions    |functions|
  17. 5. Defining functions    |user-functions|
  18. 6. Commands        |expression-commands|
  19. 7. Examples        |eval-examples|
  20. 8. No +eval feature    |no-eval-feature|
  21.  
  22. {Vi does not have any of these commands}
  23.  
  24. ==============================================================================
  25. 1. Variables                        *variables*
  26.  
  27. There are two types of variables:
  28.  
  29. Number        a 32 bit signed number.
  30. String        a NUL terminated string of 8-bit unsigned characters.
  31.  
  32. These are converted automatically, depending on how they are used.
  33.  
  34. Conversion from a Number to a String is by making the ASCII representation of
  35. the Number.  Examples:
  36. >    Number 123    -->    String "123"
  37. >    Number 0    -->    String "0"
  38. >    Number -1    -->    String "-1"
  39.  
  40. Conversion from a String to a Number is done by converting the first digits
  41. to a number.  Hexadecimal "0xf9" and Octal "017" numbers are recognized.  If
  42. the String doesn't start with digits, the result is zero.  Examples:
  43. >    String "456"    -->    Number 456
  44. >    String "6bar"    -->    Number 6
  45. >    String "foo"    -->    Number 0
  46. >    String "0xf1"    -->    Number 241
  47. >    String "0100"    -->    Number 64
  48.  
  49. To force conversion from String to Number, add zero to it:
  50. >    :echo "0100" + 0
  51.  
  52. For boolean operators Numbers are used.  Zero is FALSE, non-zero is TRUE.
  53.  
  54. Note that in the command
  55.     :if "foo"
  56. "foo" is converted to 0, which means FALSE.  To test for a non-empty string,
  57. use strlen():
  58.     :if strlen("foo")
  59.  
  60. When the '!' flag is included in the 'viminfo' option, global variables that
  61. start with an uppercase letter, and don't contain a lowercase letter, are
  62. stored in the viminfo file |viminfo-file|.
  63.  
  64. When the 'sessionoptions' option contains "global", global variables that
  65. start with an uppercase letter and contain at least one lowercase letter are
  66. stored in the session file |session-file|.
  67.  
  68. variable name        can be stored where ~
  69. my_var_6        not
  70. My_Var_6        session file
  71. MY_VAR_6        viminfo file
  72.  
  73. ==============================================================================
  74. 2. Expression syntax                    *expression-syntax*
  75.  
  76. Expression syntax summary, from least to most significant:
  77.  
  78. |expr1|    expr2 || expr2 ..    logical OR
  79.  
  80. |expr2|    expr3 && expr3 ..    logical AND
  81.  
  82. |expr3|    expr4 == expr4        equal
  83.     expr4 != expr4        not equal
  84.     expr4 >     expr4        greater than
  85.     expr4 >= expr4        greater than or equal
  86.     expr4 <     expr4        smaller than
  87.     expr4 <= expr4        smaller than or equal
  88.     expr4 =~ expr4        regexp matches
  89.     expr4 !~ expr4        regexp doesn't match
  90.     expr4 ==? expr4        equal, ignoring case
  91.     expr4 ==# expr4        equal, match case
  92.     etc.  As above, append ? for ignoring case, # for matching case
  93.  
  94. |expr4|    expr5 +     expr5 ..    number addition
  95.     expr5 -     expr5 ..    number subtraction
  96.     expr5 .     expr5 ..    string concatenation
  97.  
  98. |expr5|    expr6 *     expr6 ..    number multiplication
  99.     expr6 /     expr6 ..    number division
  100.     expr6 %     expr6 ..    number modulo
  101.  
  102. |expr6|    ! expr6            logical NOT
  103.     - expr6            unary minus
  104.     expr7
  105.  
  106. |expr7|    expr8[expr1]        index in String
  107.  
  108. |expr8|    number            number constant
  109.     "string"        string constant
  110.     'string'        literal string constant
  111.     &option            option value
  112.     (expr1)            nested expression
  113.     variable        internal variable
  114.     $VAR            environment variable
  115.     @r            contents of register 'r'
  116.     function(expr1, ...)    function call
  117.  
  118. ".." indicates that the operations in this level can be concatenated.
  119. Example:
  120. >    &nu || &list && &shell == "csh"
  121.  
  122. All expressions within one level are parsed from left to right.
  123.  
  124.  
  125. expr1 and expr2                        *expr1* *expr2*
  126. ---------------
  127.  
  128.                         *expr-barbar* *expr-&&*
  129. The "||" and "&&" operators take one argument on each side.  The arguments
  130. are (converted to) Numbers.  The result is:
  131.  
  132.      input                 output            ~
  133.     n1        n2        n1 || n2    n1 && n2    ~
  134.     zero    zero        zero        zero
  135.     zero    non-zero    non-zero    zero
  136.     non-zero    zero        non-zero    zero
  137.     non-zero    non-zero    non-zero    non-zero
  138.  
  139. The operators can be concatenated, for example:
  140.  
  141. >    &nu || &list && &shell == "csh"
  142.  
  143. Note that "&&" takes precedence over "||", so this has the meaning of:
  144.  
  145. >    &nu || (&list && &shell == "csh")
  146.  
  147. Once the result is known, the expression "short-circuits", that is, further
  148. arguments are not evaluated.  This is like what happens in C.  For example:
  149.  
  150. >    let a = 1
  151. >    echo a || b
  152.  
  153. This is valid even if there is no variable called "b" because "a" is non-zero,
  154. so the result must be non-zero.  Similarly below:
  155.  
  156. >    echo exists("b") && b == "yes"
  157.  
  158. This is valid whether "b" has been defined or not.  The second clause will
  159. only be evaluated if "b" has been defined.
  160.  
  161.  
  162. expr3                            *expr3*
  163. -----
  164.  
  165.     expr4 {cmp} expr4
  166.  
  167. Compare two expr4 expressions, resulting in a 0 if it evaluates to false, or 1
  168. if it evaluates to true.
  169.  
  170.                 *expr-==*  *expr-!=*  *expr->*   *expr->=*
  171.                 *expr-<*   *expr-<=*  *expr-=~*  *expr-!~*
  172.                 *expr-==#* *expr-!=#* *expr->#*  *expr->=#*
  173.                 *expr-<#*  *expr-<=#* *expr-=~#* *expr-!~#*
  174.                 *expr-==?* *expr-!=?* *expr->?*  *expr->=?*
  175.                 *expr-<?*  *expr-<=?* *expr-=~?* *expr-!~?*
  176.         use 'ignorecase'    match case       ignore case ~
  177. equal            ==        ==#        ==?
  178. not equal        !=        !=#        !=?
  179. greater than        >        >#        >?
  180. greater than or equal    >=        >=#        >=?
  181. smaller than        <        <#        <?
  182. smaller than or equal    <=        <=#        <=?
  183. regexp matches        =~        =~#        =~?
  184. regexp doesn't match    !~        !~#        !~?
  185.  
  186. Examples:
  187.     "abc" ==# "Abc"      evaluates to 0
  188.     "abc" ==? "Abc"      evaluates to 1
  189.     "abc" == "Abc"      evaluates to 1 if 'ignorecase' is set, 0 otherwise
  190.  
  191. When comparing a String with a Number, the String is converted to a Number,
  192. and the comparison is done on Numbers.
  193.  
  194. When comparing two Strings, this is done with strcmp() or stricmp().  This
  195. results in the mathematical difference (comparing byte values), not
  196. necessarily the alphabetical difference in the local language.
  197.  
  198. When using the opreators with a trailing '#", or the short version and
  199. 'ignorecase' is off, the comparing is done with strcmp().
  200.  
  201. When using the operators with a trailing '?', or the short version and
  202. 'ignorecase' is set, the comparing is done with stricmp().
  203.  
  204. The "=~" and "!~" operators match the lefthand argument with the righthand
  205. argument, which is used as a pattern.  See |pattern| for what a pattern is.
  206. This matching is always done like 'magic' was set and 'cpoptions' is empty, no
  207. matter what the actual value of 'magic' or 'cpoptions' is.  This makes scripts
  208. portable.  To avoid backslashes in the regexp pattern to be doubled, use a
  209. single-quote string, see |literal-string|.
  210.  
  211.  
  212. expr4 and expr5                        *expr4* *expr5*
  213. ---------------
  214.     expr5 +     expr5 ..    number addition        *expr-+*
  215.     expr5 -     expr5 ..    number subtraction    *expr--*
  216.     expr5 .     expr5 ..    string concatenation    *expr-.*
  217.  
  218.     expr6 *     expr6 ..    number multiplication    *expr-star*
  219.     expr6 /     expr6 ..    number division        *expr-/*
  220.     expr6 %     expr6 ..    number modulo        *expr-%*
  221.  
  222. For all, except ".", Strings are converted to Numbers.
  223.  
  224. Note the difference between "+" and ".":
  225.     "123" + "456" = 579
  226.     "123" . "456" = "123456"
  227.  
  228. When the righthand side of '/' is zero, the result is 0xfffffff.
  229. When the righthand side of '%' is zero, the result is 0.
  230.  
  231.  
  232. expr6                            *expr6*
  233. -----
  234.     ! expr6            logical NOT        *expr-!*
  235.     - expr6            unary minus        *expr-unary--*
  236.  
  237. For '!' non-zero becomes zero, zero becomes one.
  238. For '-' the sign of the number is changed.
  239.  
  240. A String will be converted to a Number first.
  241.  
  242. These two can be repeated and mixed.  Examples:
  243.     !-1        == 0
  244.     !!8        == 1
  245.     --9        == 9
  246.  
  247.  
  248. expr7                            *expr7*
  249. -----
  250.     expr8[expr1]        index in String        *expr-[]*
  251.  
  252. This results in a String that contains the expr1'th single character from
  253. expr8.  expr8 is used as a String, expr1 as a Number.
  254.  
  255. Note that index zero gives the first character.  This is like it works in C.
  256. Careful: column numbers start with one!  Example, to get the character under
  257. the cursor:
  258. >   c = getline(line("."))[col(".") - 1]
  259.  
  260. If the length of the String is less than the index, the result is an empty
  261. String.
  262.  
  263.                             *expr8*
  264. number
  265. ------
  266.     number            number constant        *expr-number*
  267.  
  268. Decimal, Hexadecimal (starting with 0x or 0X), or Octal (starting with 0).
  269.  
  270.  
  271. string                            *expr-string*
  272. ------
  273.     "string"        string constant        *expr-quote*
  274.  
  275. Note that double quotes are used.
  276.  
  277. A string constant accepts these special characters:
  278.     \...    three-digit octal number (e.g., "\316")
  279.     \..    two-digit octal number (must be followed by non-digit)
  280.     \.    one-digit octal number (must be followed by non-digit)
  281.     \x..    two-character hex number (e.g., "\x1f")
  282.     \x.    one-character hex number (must be followed by non-hex)
  283.     \X..    same as \x..
  284.     \X.    same as \x.
  285.     \b    backspace <BS>
  286.     \e    escape <Esc>
  287.     \f    formfeed <FF>
  288.     \n    newline <NL>
  289.     \r    return <CR>
  290.     \t    tab <Tab>
  291.     \\    backslash
  292.     \"    double quote
  293.     \<xxx>    Special key named "xxx".  e.g. "\<C-W>" for CTRL-W.
  294.  
  295. Note that "\000" and "\x00" force the end of the string.
  296.  
  297.  
  298. literal-string                        *literal-string*
  299. ---------------
  300.     'string'        literal string constant        *expr-'*
  301.  
  302. Note that single quotes are used.
  303.  
  304. This string is taken literally.  No backslashes are removed or have a special
  305. meaning.  A literal-string cannot contain a single quote.  Use a normal string
  306. for that.
  307.  
  308.  
  309. option                            *expr-option*
  310. ------
  311.     &option            option value
  312.  
  313. Any option name can be used here.  See |options|.
  314.  
  315.  
  316. register                        *expr-register*
  317. --------
  318.     @r            contents of register 'r'
  319.  
  320. The result is the contents of the named register, as a single string.
  321. Newlines are inserted where required.  To get the contents of the unnamed
  322. register use @@.  The '=' register can not be used here.  See |registers| for
  323. an explanation of the available registers.
  324.  
  325.  
  326. nesting                            *expr-nesting*
  327. -------
  328.     (expr1)            nested expression
  329.  
  330.  
  331. environment variable                    *expr-env*
  332. --------------------
  333.     $VAR            environment variable
  334.  
  335. The String value of any environment variable.  When it is not defined, the
  336. result is an empty string.
  337.                             *expr-env-expand*
  338. Note that there is a difference between using $VAR directly and using
  339. expand("$VAR").  Using it directly will only expand environment variables that
  340. are known inside the current Vim session.  Using expand() will first try using
  341. the environment variables known inside the current Vim session.  If that
  342. fails, a shell will be used to expand the variable.  This can be slow, but it
  343. does expand all variables that the shell knows about.  Example:
  344. >   echo $version
  345. >   echo expand("$version")
  346. The first one probably doesn't echo anything, the second echoes the $version
  347. variable (if you shell supports it).
  348.  
  349.  
  350. internal variable                    *expr-variable*
  351. -----------------
  352.     variable        internal variable
  353. See below |internal-variables|.
  354.  
  355.  
  356. function call                        *expr-function*
  357. -------------
  358.     function(expr1, ...)    function call
  359. See below |functions|.
  360.  
  361.  
  362. ==============================================================================
  363. 3. Internal variable                    *internal-variables*
  364.  
  365. An internal variable name can be made up of letters, digits and '_'.  But it
  366. cannot start with a digit.
  367.  
  368. An internal variable is created with the ":let" command |:let|.
  369. An internal variable is destroyed with the ":unlet" command |:unlet|.
  370. Using a name that isn't an internal variable, or an internal variable that has
  371. been destroyed, results in an error.
  372.  
  373. A variable name that is preceded with "b:" is local to the current buffer.
  374. Thus you can have several "b:foo" variables, one for each buffer.
  375. This kind of variable is deleted when the buffer is unloaded.  If you want to
  376. keep it, avoid that the buffer is unloaded by setting the 'hidden' option.
  377.  
  378. A variable name that is preceded with "w:" is local to the current window.  It
  379. is deleted when the window is closed.
  380.  
  381. Inside functions global variables are accessed with "g:".
  382.  
  383. Predefined Vim variables:
  384.                     *v:count-variable* *count-variable*
  385. v:count        The count given for the last Normal mode command.  Can be used
  386.         to get the count before a mapping.  Read-only.  Example:
  387. >    :map _x :<C-U>echo "the count is " . count<CR>
  388.         Note: The <C-U> is required to remove the line range that you
  389.         get when typing ':' after a count.
  390.         "count" also works, for backwards compatibility.
  391.  
  392.                             *v:count1-variable*
  393. v:count1    Just like "v:count", but defaults to one when no count is
  394.         used.
  395.  
  396.                     *v:errmsg-variable* *errmsg-variable*
  397. v:errmsg    Last given error message.  It's allowed to set this variable.
  398.         Example:
  399. >    :let errmsg = ""
  400. >    :next
  401. >    :if (errmsg != "")
  402. >    :  ...
  403.         "errmsg" also works, for backwards compatibility.
  404.  
  405.                             *v:warningmsg-variable*
  406. v:warningmsg    Last given warning message.  It's allowed to set this variable.
  407.  
  408.                             *v:statusmsg-variable*
  409. v:statusmsg    Last given status message.  It's allowed to set this variable.
  410.  
  411.                 *v:shell_error-variable* *shell_error-variable*
  412. v:shell_error    Result of the last shell command.  When non-zero, the last
  413.         shell command had an error.  When zero, there was no problem.
  414.         This only works when the shell returns the error code to Vim.
  415.         The value -1 is often used when the command could not be
  416.         executed.  Read-only.
  417.         Example:
  418. >    :!mv foo bar
  419. >    :if v:shell_error
  420. >    :  echo 'could not rename "foo" to "bar"!'
  421. >    :endif
  422.         "shell_error" also works, for backwards compatibility.
  423.  
  424.                 *v:this_session-variable* *this_session-variable*
  425. v:this_session    Full filename of the last loaded or saved session file.  See
  426.         |:mksession|.  It is allowed to set this variable.
  427.         "this_session" also works, for backwards compatibility.
  428.  
  429.                     *v:version-variable* *version-variable*
  430. v:version    Version number of Vim: Major version number times 100 plus
  431.         minor version number.  Version 5.0 is 500.  Version 5.1 (5.01)
  432.         is 501.  Read-only.  "version" also works, for backwards
  433.         compatibility.
  434.  
  435. ==============================================================================
  436. 4. Builtin Functions                    *functions*
  437.  
  438. (Use CTRL-] on the function name to jump to the full explanation)
  439.  
  440. USAGE                RESULT    DESCRIPTION    ~
  441.  
  442. append( {lnum}, {string})    Number  append {string} below line {lnum}
  443. argc()                Number    number of files in the argument list
  444. argv( {nr})            String    {nr} entry of the argument list
  445. browse( {save}, {title}, {initdir}, {default})
  446.                 String    put up a file requester
  447. bufexists( {expr})        Number    TRUE if buffer {expr} exists
  448. bufloaded( {expr})        Number  TRUE if buffer {expr} is loaded
  449. bufname( {expr})        String    Name of the buffer {expr}
  450. bufnr( {expr})            Number    Number of the buffer {expr}
  451. bufwinnr( {nr})            Number    window number of buffer {nr}
  452. byte2line( {byte})        Number    line number at byte count {byte}
  453. char2nr( {expr})        Number    ASCII value of first char in {expr}
  454. col( {expr})            Number    column nr of cursor or mark
  455. confirm( {msg}, {choices} [, {default} [, {type}]])
  456.                 Number    number of choice picked by user
  457. delete( {fname})        Number    delete file {fname}
  458. did_filetype()            Number    TRUE if FileType autocommand event used
  459. escape( {string}, {chars})    String    escape {chars} in {string} with '\'
  460. exists( {var})            Number    TRUE if {var} exists
  461. expand( {expr})            String    expand special keywords in {expr}
  462. filereadable( {file})        Number    TRUE if {file} is a readable file
  463. fnamemodify( {fname}, {mods})    String    modify file name
  464. getcwd()            String    the current working directory
  465. getftime( {fname})        Number    last modification time of file
  466. getline( {lnum})        String    line {lnum} from current buffer
  467. getwinposx()            Number    X coord in pixels of GUI vim window
  468. getwinposy()            Number    Y coord in pixels of GUI vim window
  469. glob( {expr} [, {flag}])    String    expand file wildcards in {expr}
  470. has( {feature})            Number    TRUE if feature {feature} supported
  471. histadd( {history},{item})    String    add an item to a history
  472. histdel( {history} [, {item}])    String    remove an item from a history
  473. histget( {history} [, {index}])    String    get the item {index} from a history
  474. histnr( {history})        Number    highest index of a history
  475. hlexists( {name})        Number    TRUE if highlight group {name} exists
  476. hlID( {name})            Number    syntax ID of highlight group {name}
  477. hostname()            String    name of the machine vim is running on
  478. input( {prompt})        String    get input from the user
  479. isdirectory( {directory})    Number    TRUE if {directory} is a directory
  480. libcall( {lib}, {func}, {arg}    String  call {func} in library {lib}
  481. line( {expr})            Number    line nr of cursor, last line or mark
  482. line2byte( {lnum})        Number    byte count of line {lnum}
  483. localtime()            Number    current time
  484. maparg( {name}[, {mode}])    String    rhs of mapping {name} in mode {mode}
  485. mapcheck( {name}[, {mode}])    String    check for mappings matching {name}
  486. match( {expr}, {pat})        Number    position where {pat} matches in {expr}
  487. matchend( {expr}, {pat})    Number    position where {pat} ends in {expr}
  488. matchstr( {expr}, {pat})    String    match of {pat} in {expr}
  489. nr2char( {expr})        String    single char with ASCII value {expr}
  490. rename({from}, {to})        Number  rename (move) file from {from} to {to}
  491. setline( {lnum}, {line})    Number    set line {lnum} to {line}
  492. strftime( {format}[, {time}])    String    time in specified format
  493. strlen( {expr})            Number    length of the String {expr}
  494. strpart( {src}, {start}, {len})    String    {len} characters of {src} at {start}
  495. strtrans( {expr})        String    translate sting to make it printable
  496. substitute( {expr}, {pat}, {sub}, {flags})
  497.                 String    all {pat} in {expr} replaced with {sub}
  498. synID( {line}, {col}, {trans})    Number    syntax ID at {line} and {col}
  499. synIDattr( {synID}, {what} [, {mode}])
  500.                 String    attribute {what} of syntax ID {synID}
  501. synIDtrans( {synID})        Number    translated syntax ID of {synID}
  502. system( {expr})            String    output of shell command {expr}
  503. tempname()            String    name for a temporary file
  504. virtcol( {expr})        Number    screen column of cursor or mark
  505. visualmode()            String    last visual mode used
  506. winbufnr( {nr})            Number    buffer number of window {nr}
  507. winheight( {nr})        Number    height of window {nr}
  508. winnr()                Number    number of current window
  509.  
  510. append({lnum}, {string}                    *append()*
  511.         Append the text {string} after line {lnum} in the current
  512.         buffer.  {lnum} can be zero, to insert a line before the first
  513.         one.  Returns 1 for failure ({lnum} out of range) or 0 for
  514.         success.
  515.  
  516.                             *argc()*
  517. argc()        The result is the number of files in the argument list.  See
  518.         |arglist|.
  519.  
  520.                             *argv()*
  521. argv({nr})    The result is the {nr}th file in the argument list.  See
  522.         |arglist|.  "argv(0)" is the first one.  Example:
  523. >    let i = 0
  524. >    while i < argc()
  525. >      let f = substitute(argv(i), '\([. ]\)', '\\&', 'g')
  526. >      exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
  527. >      let i = i + 1
  528. >    endwhile
  529.  
  530.                             *browse()*
  531. browse({save}, {title}, {initdir}, {default})
  532.         Put up a file requester.  This only works when "has("browse")"
  533.         returns non-zero (only in some GUI versions).
  534.         The input fields are:
  535.             {save}    when non-zero, select file to write
  536.             {title}    title for the requester
  537.             {initdir}    directory to start browsing in
  538.             {default}    default file name
  539.         When the "Cancel" button is hit, something went wrong, or
  540.         browsing is not possible, an empty string is returned.
  541.  
  542.                             *bufexists()*
  543. bufexists({expr})
  544.         The result is a Number, which is non-zero if a buffer called
  545.         {expr} exists.  If the {expr} argument is a string it must
  546.         match a buffer name exactly.  If the {expr} argument is a
  547.         number buffer numbers are used.  Use "bufexists(0)" to test
  548.         for the existence of an alternate file name.
  549.                             *buffer_exists()*
  550.         Obsolete name: buffer_exists().
  551.  
  552.                             *bufloaded()*
  553. bufloaded({expr})
  554.         The result is a Number, which is non-zero if a buffer called
  555.         {expr} exists and is loaded (shown in a window or hidden).
  556.         The {expr} argument is used like with bufexists().
  557.  
  558.                             *bufname()*
  559. bufname({expr})
  560.         The result is the name of a buffer, as it is displayed by the
  561.         ":ls" command.
  562.         If {expr} is a Number, that buffer number's name is given.
  563.         Number zero is the alternate buffer for the current window.
  564.         If {expr} is a String, it is used as a regexp pattern to match
  565.         with the buffer names.  This is always done like 'magic' is
  566.         set and 'cpoptions' is empty.  When there is more than one
  567.         match an empty string is returned.  "" or "%" can be used for
  568.         the current buffer, "#" for the alternate buffer.
  569.         If the {expr} is a String, but you want to use it as a buffer
  570.         number, force it to be a Number by adding zero to it:
  571. >            echo bufname("3" + 0)
  572.         If the buffer doesn't exist, or doesn't have a name, an empty
  573.         string is returned.
  574. >  bufname("#")            alternate buffer name
  575. >  bufname(3)            name of buffer 3
  576. >  bufname("%")            name of current buffer
  577. >  bufname("file2")        name of buffer where "file2" matches.
  578.                             *buffer_name()*
  579.         Obsolete name: buffer_name().
  580.  
  581.                             *bufnr()*
  582. bufnr({expr})    The result is the number of a buffer, as it is displayed by
  583.         the ":ls" command.  For the use of {expr}, see bufname()
  584.         above.  If the buffer doesn't exist, -1 is returned.
  585.         bufnr("$") is the last buffer:
  586. >  :let last_buffer = bufnr("$")
  587.         The result is a Number, which is the highest buffer number
  588.         of existing buffers.  Note that not all buffers with a smaller
  589.         number necessarily exist, because ":bdel" may have removed
  590.         them.  Use bufexists() to test for the existence of a buffer.
  591.                             *buffer_number()*
  592.         Obsolete name: buffer_number().
  593.                             *last_buffer_nr()*
  594.         Obsolete name for bufnr("$"): last_buffer_nr().
  595.  
  596.                             *bufwinnr()*
  597. bufwinnr({expr})
  598.         The result is a Number, which is the number of the first
  599.         window associated with buffer {expr}.  For the use of {expr},
  600.         see bufname() above.  If buffer {expr} doesn't exist or there
  601.         is no such window, -1 is returned.  Example:
  602. >  echo "A window containing buffer 1 is " . (bufwinnr(1))
  603.  
  604.                             *byte2line()*
  605. byte2line({byte})
  606.         Return the line number that contains the character at byte
  607.         count {byte} in the current buffer.  This includes the
  608.         end-of-line character, depending on the 'fileformat' option
  609.         for the current buffer.  The first character has byte count
  610.         one.
  611.         Also see |line2byte()|, |go| and |:goto|.
  612.         {not available when compiled without the |+byte_offset|
  613.         feature}
  614.  
  615.                             *char2nr()*
  616. char2nr({expr})
  617.         Return ASCII value of the first char in {expr}.  Examples:
  618. >            char2nr(" ")        returns 32
  619. >            char2nr("ABC")        returns 65
  620.  
  621.                             *col()*
  622. col({expr})    The result is a Number, which is the column of the file
  623.         position given with {expr}.  The accepted positions are:
  624.             .        the cursor position
  625.             'x        position of mark x (if the mark is not set, 0 is
  626.                 returned)
  627.         Note that only marks in the current file can be used.
  628.         Examples:
  629. >            col(".")        column of cursor
  630. >            col("'t")        column of mark t
  631. >            col("'" . markname)    column of mark markname
  632.         The first column is 1.  0 is returned for an error.
  633.  
  634.                             *confirm()*
  635. confirm({msg}, {choices} [, {default} [, {type}]])
  636.         Confirm() offers the user a dialog, from which a choice can be
  637.         made.  It returns the number of the choice.  For the first
  638.         choice this is 1.
  639.         Note: confirm() is only supported when compiled with dialog
  640.         support, see |+dialog_con| and |+dialog_gui|.
  641.         {msg} is displayed in a |dialog| with {choices} as the
  642.         alternatives.
  643.         {msg} is a String, use '\n' to include a newline.  Only on
  644.         some systems the string is wrapped when it doesn't fit.
  645.         {choices} is a String, with the individual choices separated
  646.         by '\n', e.g.
  647. >            confirm("Save changes?", "&Yes\n&No\n&Cancel")
  648.         The letter after the '&' is the shortcut key for that choice.
  649.         Thus you can type 'c' to select "Cancel".  The shorcut does
  650.         not need to be the first letter:
  651. >            confirm("file has been modified", "&Save\nSave &All")
  652.         For the console, the first letter of each choice is used as
  653.         the default shortcut key.
  654.         The optional {default} argument is the number of the choice
  655.         that is made if the user hits <CR>.  Use 1 to make the first
  656.         choice the default one.  Use 0 to not set a default.  If
  657.         {default} is omitted, 0 is used.
  658.         The optional {type} argument gives the type of dialog.  This
  659.         is only used for the icon of the Win32 GUI.  It can be one of
  660.         these values: "Error", "Question", "Info", "Warning" or
  661.         "Generic".  Only the first character is relevant.
  662.         If the user aborts the dialog by pressing <Esc>, CTRL-C,
  663.         or another valid interrupt key, confirm() returns 0.
  664.  
  665.         An example:
  666. >   :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
  667. >   :if choice == 0
  668. >   :    echo "make up your mind!"
  669. >   :elseif choice == 3
  670. >   :    echo "tasteful"
  671. >   :else
  672. >   :    echo "I prefer bananas myself."
  673. >   :endif
  674.         In a GUI dialog, buttons are used.  The layout of the buttons
  675.         depends on the 'v' flag in 'guioptions'.  If it is included,
  676.         the buttons are always put vertically.  Otherwise,  confirm()
  677.         tries to put the buttons in one horizontal line.  If they
  678.         don't fit, a vertical layout is used anyway.  For some systems
  679.         the horizontal layout is always used.
  680.  
  681.                             *delete()*
  682. delete({fname})    Deletes the file by the name {fname}.  The result is a Number,
  683.         which is 0 if the file was deleted successfully, and non-zero
  684.         when the deletion failed.
  685.  
  686.                             *did_filetype()*
  687. did_filetype()    Returns non-zero when autocommands are being executed and the
  688.         FileType event has been triggered at least once.  Can be used
  689.         to avoid triggering the FileType event again in the scripts
  690.         that detect the file type. |FileType|
  691.  
  692. escape({string}, {chars})                *escape()*
  693.         Escape the characters in {chars} that occur in {string} with a
  694.         backslash.  Example:
  695. >            :echo escape('c:\program files\vim', ' \')
  696.         results in:
  697. >            c:\\program\ files\\vim
  698.  
  699.                             *exists()*
  700. exists({expr})    The result is a Number, which is 1 if {var} is defined, zero
  701.         otherwise.  The {expr} argument is a string, which contains
  702.         one of these:
  703.             &option-name    Vim option
  704.             $ENVNAME    environment variable (could also be
  705.                     done by comparing with an empty
  706.                     string)
  707.             *funcname    built-in function (see |functions|)
  708.                     or user defined function (see
  709.                     |user-functions|).
  710.             varname        internal variable (see
  711.                     |internal-variables|).
  712.  
  713.         Examples:
  714. >            exists("&shortname")
  715. >            exists("$HOSTNAME")
  716. >            exists("*strftime")
  717. >            exists("bufcount")
  718.         There must be no space between the symbol &/$/* and the name.
  719.         Note that the argument must be a string, not the name of the
  720.         variable itself!  This doesn't check for existence of the
  721.         "bufcount" variable, but gets the contents of "bufcount", and
  722.         checks if that exists:
  723.             exists(bufcount)
  724.  
  725.                             *expand()*
  726. expand({expr} [, {flag}])
  727.         Expand wildcards and the following special keywords in {expr}.
  728.         The result is a String.
  729.  
  730.         When there are several matches, they are separated by <NL>
  731.         characters.  [Note: in version 5.0 a space was used, which
  732.         caused problems when a file name contains a space]
  733.  
  734.         If the expansion fails, the result is an empty string.  A name
  735.         for a non-existing file is not included.
  736.  
  737.         When {expr} starts with '%', '#' or '<', the expansion is done
  738.         like for the |cmdline-special| variables with their associated
  739.         modifiers.  Here is a short overview:
  740.  
  741.             %        current file name
  742.             #        alternate file name
  743.             #n        alternate file name n
  744.             <cfile>        file name under the cursor
  745.             <afile>        autocmd file name
  746.             <abuf>        autocmd buffer number
  747.             <sfile>        sourced script file name
  748.             <cword>        word under the cursor
  749.             <cWORD>        WORD under the cursor
  750.         Modifiers:
  751.             :p        expand to full path
  752.             :h        head (last path component removed)
  753.             :t        tail (last path component only)
  754.             :r        root (one extension removed)
  755.             :e        extension only
  756.  
  757.         Example:
  758. >            :let &tags = expand("%:p:h") . "/tags"
  759.         Note that when expanding a string that starts with '%', '#' or
  760.         '<', any following text is ignored.  This does NOT work:
  761. >            :let doesntwork = expand("%:h.bak")
  762.         Use this:
  763. >            :let doeswork = expand("%:h") . ".bak"
  764.         Also note that expanding "<cfile>" and others only returns the
  765.         referenced file name without further expansion.  If "<cfile>"
  766.         is "~/.cshrc", you need to do another expand() to have the
  767.         "~/" expanded into the path of the home directory:
  768. >            :echo expand(expand("<cfile>"))
  769.  
  770.         There cannot be white space between the variables and the
  771.         following modifier.  The |fnamemodify()| function can be used
  772.         to modify normal file names.
  773.  
  774.         When using '%' or '#', and the current or alternate file name
  775.         is not defined, an empty string is used.  Using "%:p" in a
  776.         buffer with no name, results in the current directory, with a
  777.         '/' added.
  778.  
  779.         When {expr} does not start with '%', '#' or '<', it is
  780.         expanded like a file name is expanded on the command line.
  781.         'suffixes' and 'wildignore' are used, unless the optional
  782.         {flag} argument is given and it is non-zero.
  783.  
  784.         Expand() can also be used to expand variables and environment
  785.         variables that are only known in a shell.  But this can be
  786.         slow, because a shell must be started.  See |expr-env-expand|.
  787.  
  788.         See |glob()| for finding existing files.  See |system()| for
  789.         getting the raw output of an external command.
  790.  
  791.                             *filereadable()*
  792. filereadable({file})
  793.         The result is a Number, which is TRUE when a file with the
  794.         name {file} exists, and can be read.  If {file} doesn't exist,
  795.         or is a directory, the result is FALSE.  {file} is any
  796.         expression, which is used as a String.
  797.                             *file_readable()*
  798.         Obsolete name: file_readable().
  799.  
  800.                             *fnamemodify()*
  801. fnamemodify({fname}, {mods})
  802.         Modify file name {fname} according to {mods}.  {mods} is a
  803.         string of characters like it is used for file names on the
  804.         command line.  See |filename-modifiers|.
  805.         Example:
  806. >            :echo fnamemodify("main.c", ":p:h")
  807.         results in:
  808. >            /home/mool/vim/vim/src/
  809.  
  810.                             *getcwd()*
  811. getcwd()    The result is a String, which is the name of the current
  812.         working directory.
  813.  
  814.                             *getftime()*
  815. getftime({fname})
  816.         The result is a Number, which is the last modification time of
  817.         the given file {fname}.  The value is measured as seconds
  818.         since 1st Jan 1970, and may be passed to strftime().  See also
  819.         |localtime()| and |strftime()|.
  820.  
  821.                             *getline()*
  822. getline({lnum}) The result is a String, which is line {lnum} from the current
  823.         buffer.  Example:
  824. >            getline(1)
  825.         When {lnum} is a String that doesn't start with a
  826.         digit, line() is called to translate the String into a Number.
  827.         To get the line under the cursor:
  828. >            getline(".")
  829.         When {lnum} is smaller than 1 or bigger than the number of
  830.         lines in the buffer, an empty string is returned.
  831.  
  832.                             *getwinposx()*
  833. getwinposx()    The result is a Number, which is the X coordinate in pixels of
  834.         the left hand side of the GUI vim window.  The result will be
  835.         -1 if the information is not available.
  836.  
  837.                             *getwinposy()*
  838. getwinposy()    The result is a Number, which is the Y coordinate in pixels of
  839.         the top of the GUI vim window.  The result will be -1 if the
  840.         information is not available.
  841.  
  842.                             *glob()*
  843. glob({expr})    Expand the file wildcards in {expr}.  The result is a String.
  844.         When there are several matches, they are separated by <NL>
  845.         characters.
  846.         If the expansion fails, the result is an empty string.
  847.         A name for a non-existing file is not included.
  848.  
  849.         For most systems backticks can be used to get files names from
  850.         any external command.  Example:
  851. >            :let tagfiles = glob("`find . -name tags -print`")
  852. >            :let &tags = substitute(tagfiles, "\n", ",", "g")
  853.         The result of the program inside the backticks should be one
  854.         item per line.  Spaces inside an item are allowed.
  855.  
  856.         See |expand()| for expanding special Vim variables.  See
  857.         |system()| for getting the raw output of an external command.
  858.  
  859.                             *has()*
  860. has({feature})    The result is a Number, which is 1 if the feature {feature} is
  861.         supported, zero otherwise.  The {feature} argument is a
  862.         string.  See |feature-list| below.
  863.  
  864.                             *histadd()*
  865. histadd({history}, {item})
  866.         Add the String {item} to the history {history} which can be
  867.         one of:                    *hist-names*
  868.             "cmd"     or ":"      command line history
  869.             "search" or "/"   search pattern history
  870.             "expr"   or "="   typed expression history
  871.             "input"  or "@"      input line history
  872.         If {item} does already exist in the history, it will be
  873.         shifted to become the newest entry.
  874.         The result is a Number: 1 if the operation was successful,
  875.         otherwise 0 is returned.
  876.  
  877.         Example:
  878. >            :call histadd("input", strftime("%Y %b %d"))
  879. >            :let date=input("Enter date: ")
  880.  
  881.                             *histdel()*
  882. histdel({history} [, {item}])
  883.         Clear {history}, ie. delete all its entries.  See |hist-names|
  884.         for the possible values of {history}.
  885.  
  886.         If the parameter {item} is given as String, this is seen
  887.         as regular expression.  All entries matching that expression
  888.         will be removed from the history (if there are any).
  889.         If {item} is a Number, it will be interpreted as index, see
  890.         |:history-indexing|.  The respective entry will be removed
  891.         if it exists.
  892.  
  893.         The result is a Number: 1 for a successful operation,
  894.         otherwise 0 is returned.
  895.  
  896.         Examples:
  897.         Clear expression register history:
  898. >            :call histdel("expr")
  899.  
  900.         Remove all entries starting with "*" from the search history:
  901. >            :call histdel("/", '^\*')
  902.  
  903.         The following three are equivalent:
  904. >            :call histdel("search", histnr("search"))
  905. >            :call histdel("search", -1)
  906. >            :call histdel("search", '^'.histget("search", -1).'$')
  907.  
  908.         To delete the last search pattern and use the last-but-one for
  909.         the "n" command and 'hlsearch':
  910. >            :call histdel("search", -1)
  911. >            :let @/ = histget("search", -1)
  912.  
  913.  
  914.                             *histget()*
  915. histget({history} [, {index}])
  916.         The result is a String, the entry with Number {index} from
  917.         {history}.  See |hist-names| for the possible values of
  918.         {history}, and |:history-indexing| for {index}.  If there is
  919.         no such entry, an empty String is returned.  When {index} is
  920.         omitted, the most recent item from the history is used.
  921.  
  922.         Examples:
  923.             Redo the second last search from history.
  924. >            :execute '/' . histget("search", -2)
  925.  
  926.             Define an Ex command ":H {num}" that supports
  927.             re-execution of the {num}th entry from the output
  928.             of |:history|.
  929. >            :command -nargs=1 H execute histget("cmd",0+<args>)
  930.  
  931.                             *histnr()*
  932. histnr({history})
  933.         The result is the Number of the current entry in {history}.
  934.         See |hist-names| for the possible values of {history}.
  935.         If an error occurred, -1 is returned.
  936.  
  937.         Example:
  938. >            :let inp_index = histnr("expr")
  939.  
  940.                             *hlexists()*
  941. hlexists({name})
  942.         The result is a Number, which is non-zero if a highlight group
  943.         called {name} exists.  This is when the group has been
  944.         defined in some way.  Not necessarily when highlighting has
  945.         been defined for it, it may also have been used for a syntax
  946.         item.
  947.                             *highlight_exists()*
  948.         Obsolete name: highlight_exists().
  949.  
  950.                             *hlID()*
  951. hlID({name})    The result is a Number, which is the ID of the highlight group
  952.         with name {name}.  When the highlight group doesn't exist,
  953.         zero is returned.
  954.         This can be used to retrieve information about the highlight
  955.         group.  For example, to get the background color of the
  956.         "Comment" group:
  957. >    :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
  958.                             *highlightID()*
  959.         Obsolete name: highlightID().
  960.  
  961.                             *hostname()*
  962. hostname()
  963.         The result is a String, which is the name of the machine on
  964.         which Vim is currently running. Machine names greater than
  965.         256 characters long are truncated.
  966.  
  967. input({prompt})                        *input()*
  968.         The result is a String, which is whatever the user typed on
  969.         the command-line.  The parameter is either a prompt string, or
  970.         a blank string (for no prompt).  A '\n' can be used in the
  971.         prompt to start a new line.  The highlighting set with
  972.         |:echohl| is used for the prompt.  The input is entered just
  973.         like a command-line, with the same editing commands and
  974.         mappings.  There is a separate history for lines typed for
  975.         input().
  976.         NOTE: This must not be used in a startup file, for the
  977.         versions that only run in GUI mode (e.g., the Win32 GUI).
  978.  
  979.         Example:
  980. >    :let choice = input("What is your choice? ")
  981.  
  982.                             *isdirectory()*
  983. isdirectory({directory})
  984.         The result is a Number, which is TRUE when a directory with
  985.         the name {directory} exists.  If {directory} doesn't exist, or
  986.         isn't a directory, the result is FALSE.  {directory} is any
  987.         expression, which is used as a String.
  988.  
  989.                             *libcall()*
  990. libcall({libname}, {funcname}, {argument})
  991.         Call function {funcname} in the run-time library {libname}
  992.         with argument {argument}.  The result is the String returned.
  993.         If {argument} is a number, it is passed to the function as an
  994.         int; if {param} is a string, it is passed as a null-terminated
  995.         string.  If the function returns NULL, this will appear as an
  996.         empty string "" to Vim.
  997.         WARNING: If the function returns a non-valid pointer, Vim will
  998.         crash!  This also happens if the function returns a number.
  999.         For Win32 systems, {libname} should be the filename of the DLL
  1000.         without the ".DLL" suffix.  A full path is only required if
  1001.         the DLL is not in the usual places.
  1002.         {only in Win32 versions}
  1003.  
  1004.                             *line()*
  1005. line({expr})    The result is a Number, which is the line number of the file
  1006.         position given with {expr}.  The accepted positions are:
  1007.             .        the cursor position
  1008.             $        the last line in the current buffer
  1009.             'x        position of mark x (if the mark is not set, 0 is
  1010.                 returned)
  1011.         Note that only marks in the current file can be used.
  1012.         Examples:
  1013. >            line(".")        line number of the cursor
  1014. >            line("'t")        line number of mark t
  1015. >            line("'" . marker)    line number of mark marker
  1016.                             *last-position-jump*
  1017.         This autocommand jumps to the last known position in a file
  1018.         just after opening it, if the '" mark is set:
  1019. >    :au BufReadPost * if line("'\"") | exe "normal '\"" | endif
  1020.  
  1021.                             *line2byte()*
  1022. line2byte({lnum})
  1023.         Return the byte count from the start of the buffer for line
  1024.         {lnum}.  This includes the end-of-line character, depending on
  1025.         the 'fileformat' option for the current buffer.  The first
  1026.         line returns 1.
  1027.         This can also be used to get the byte count for the line just
  1028.         below the last line:
  1029. >            line2byte(line("$") + 1)
  1030.         This is the file size plus one.
  1031.         When {lnum} is invalid, or the |+byte_offset| feature has been
  1032.         disabled at compile time, -1 is returned.
  1033.         Also see |byte2line()|, |go| and |:goto|.
  1034.  
  1035.                             *localtime()*
  1036. localtime()
  1037.         Return the current time, measured as seconds since 1st Jan
  1038.         1970.  See also |strftime()| and |getftime()|.
  1039.  
  1040.                             *maparg()*
  1041. maparg({name}[, {mode}])
  1042.         Return the rhs of mapping {name} in mode {mode}.  When there
  1043.         is no mapping for {name}, an empty String is returned.
  1044.         These characters can be used for {mode}:
  1045.             "n"    Normal
  1046.             "v"    Visual
  1047.             "o"    Operator-pending
  1048.             "i"    Insert
  1049.             "c"    Cmd-line
  1050.             ""    Normal, Visual and Operator-pending
  1051.         When {mode} is omitted, the modes from "" are used.
  1052.         The {name} can have special key names, like in the ":map"
  1053.         command.  The returned String has special characters
  1054.         translated like in the output of the ":map" command listing.
  1055.  
  1056.                             *mapcheck()*
  1057. mapcheck({name}[, {mode}])
  1058.         Check if there is a mapping that matches with {name} in mode
  1059.         {mode}.  See |maparg()| for {mode} and special names in
  1060.         {name}.
  1061.         When there is no mapping that matches with {name}, and empty
  1062.         String is returned.  If there is one, the rhs of that mapping
  1063.         is returned.  If there are several matches, the rhs of one of
  1064.         them is returned.
  1065.         This function can be used to check if a mapping can be added
  1066.         without being ambiguous.  Example:
  1067. >    if mapcheck("_vv") == ""
  1068. >       map _vv :set guifont=7x13<CR>
  1069. >    endif
  1070.         The "_vv" mapping may conflict with a mapping for "_v" or for
  1071.         "_vvv".
  1072.  
  1073.                             *match()*
  1074. match({expr}, {pat})
  1075.         The result is a Number, which gives the index in {expr} where
  1076.         {pat} matches.  A match at the first character returns zero.
  1077.         If there is no match -1 is returned.  Example:
  1078. >            :echo match("testing", "ing")
  1079.         results in "4".
  1080.         See |pattern| for the patterns that are accepted.
  1081.         The 'ignorecase' option is used to set the ignore-caseness of
  1082.         the pattern.  'smartcase' is NOT used.  The matching is always
  1083.         done like 'magic' is set and 'cpoptions' is empty.
  1084.  
  1085.                             *matchend()*
  1086. matchend({expr}, {pat})
  1087.         Same as match(), but return the index of first character after
  1088.         the match.  Example:
  1089. >            :echo matchend("testing", "ing")
  1090.         results in "7".
  1091.  
  1092.                             *matchstr()*
  1093. matchstr({expr}, {pat})
  1094.         Same as match(), but return the matched string.  Example:
  1095. >            :echo matchstr("testing", "ing")
  1096.         results in "ing".
  1097.         When there is no match "" is returned.
  1098.  
  1099.                             *nr2char()*
  1100. nr2char({expr})
  1101.         Return a string with a single chararacter, which has the ASCII
  1102.         value {expr}.  Examples:
  1103. >            nr2char(64)        returns "@"
  1104. >            nr2char(32)        returns " "
  1105.  
  1106. rename({from}, {to})                    *rename()*
  1107.         Rename the file by the name {from} to the name {to}.  This
  1108.         should also work to move files across file systems.  The
  1109.         result is a Number, which is 0 if the file was renamed
  1110.         successfully, and non-zero when the renaming failed.
  1111.  
  1112.                             *setline()*
  1113. setline({lnum}, {line})
  1114.         Set line {lnum} of the current buffer to {line}.  If this
  1115.         succeeds, 0 is returned.  If this fails (most likely because
  1116.         {lnum} is invalid) 1 is returned.  Example:
  1117. >            :call setline(5, strftime("%c"))
  1118.  
  1119.                             *strftime()*
  1120. strftime({format} [, {time}])
  1121.         The result is a String, which is a formatted date and time, as
  1122.         specified by the {format} string.  The given {time} is used,
  1123.         or the current time if no time is given.  The accepted
  1124.         {format} depends on your system, thus this is not portable!
  1125.         See the manual page of the C function strftime() for the
  1126.         format.  The maximum length of the result is 80 characters.
  1127.         See also |localtime()| and |getftime()|.  Examples:
  1128. >          :echo strftime("%c")           Sun Apr 27 11:49:23 1997
  1129. >          :echo strftime("%Y %b %d %X")       1997 Apr 27 11:53:25
  1130. >          :echo strftime("%y%m%d %T")       970427 11:53:55
  1131. >          :echo strftime("%H:%M")       11:55
  1132. >          :echo strftime("%c", getftime("file.c"))
  1133. >                           Show mod time of file.c.
  1134.  
  1135.                             *strlen()*
  1136. strlen({expr})    The result is a Number, which is the length of the String
  1137.         {expr}.
  1138.  
  1139.                             *strpart()*
  1140. strpart({src}, {start}, {len})
  1141.         The result is a String, which is part of {src},
  1142.         starting from character {start}, with the length {len}.
  1143.         When non-existing characters are included, this doesn't result
  1144.         in an error, the characters are simply omitted.
  1145. >            strpart("abcdefg", 3, 2)    == "de"
  1146. >            strpart("abcdefg", -2, 4)   == "ab"
  1147. >            strpart("abcdefg", 5, 4)    == "fg"
  1148.         Note: To get the first character, {start} must be 0.  For
  1149.         example, to get three characters under and after the cursor:
  1150. >            strpart(getline(line(".")), col(".") - 1, 3)
  1151.  
  1152.                             *strtrans()*
  1153. strtrans({expr})
  1154.         The result is a String, which is {expr} with all unprintable
  1155.         characters translated into printable characters |'isprint'|.
  1156.         Like they are shown in a window.  Example:
  1157. >            echo strtrans(@a)
  1158.         This displays a newline in register a as "^@" instead of
  1159.         starting a new line.
  1160.  
  1161.                             *substitute()*
  1162. substitute({expr}, {pat}, {sub}, {flags})
  1163.         The result is a String, which is a copy of {expr}, in which
  1164.         the first match of {pat} is replaced with {sub}.  This works
  1165.         like the ":substitute" command (without any flags).  But the
  1166.         matching with {pat} is always done like the 'magic' option is
  1167.         set and 'cpoptions' is empty (to make scripts portable).
  1168.         And a "~" in {sub} is not replaced with the previous {sub}.
  1169.         Note that some codes in {sub} have a special meaning
  1170.         |sub-replace-special|.  For example, to replace something with
  1171.         a literal "\n", use "\\\\n" or '\\n'.
  1172.         When {pat} does not match in {expr}, {expr} is returned
  1173.         unmodified.
  1174.         When {flags} is "g", all matches of {pat} in {expr} are
  1175.         replaced.  Otherwise {flags} should be "".
  1176.         Example:
  1177. >            :let &path = substitute(&path, ",\\=[^,]*$", "", "")
  1178.         This removes the last component of the 'path' option.
  1179. >            :echo substitute("testing", ".*", "\\U\\0", "")
  1180.         results in "TESTING".
  1181.  
  1182.                             *synID()*
  1183. synID({line}, {col}, {trans})
  1184.         The result is a Number, which is the syntax ID at the position
  1185.         {line} and {col} in the current window.
  1186.         The syntax ID can be used with |synIDattr()| and
  1187.         |synIDtrans()| to obtain syntax information about text.
  1188.         {col} is 1 for the leftmost column, {line} is 1 for the first
  1189.         line.
  1190.         When {trans} is non-zero, transparent items are reduced to the
  1191.         item that they reveal.  This is useful when wanting to know
  1192.         the effective color.  When {trans} is zero, the transparent
  1193.         item is returned.  This is useful when wanting to know which
  1194.         syntax item is effective (e.g. inside parens).
  1195.         Warning: This function can be very slow.  Best speed is
  1196.         obtained by going through the file in forward direction.
  1197.  
  1198.         Example (echos the name of the syntax item under the cursor):
  1199. >            :echo synIDattr(synID(line("."), col("."), 1), "name")
  1200.  
  1201.                             *synIDattr()*
  1202. synIDattr({synID}, {what} [, {mode}])
  1203.         The result is a String, which is the {what} attribute of
  1204.         syntax ID {synID}.  This can be used to obtain information
  1205.         about a syntax item.
  1206.         {mode} can be "gui", "cterm" or "term", to get the attributes
  1207.         for that mode.  When {mode} is omitted, or an invalid value is
  1208.         used, the attributes for the currently active highlighting are
  1209.         used (GUI, cterm or term).
  1210.         Use synIDtrans() to follow linked highlight groups.
  1211.         {what}        result
  1212.         "name"        the name of the syntax item
  1213.         "fg"        foreground color (GUI: color name, cterm:
  1214.                 color number as a string, term: empty string)
  1215.         "bg"        background color (like "fg")
  1216.         "fg#"        like "fg", but name in "#RRGGBB" form
  1217.         "bg#"        like "bg", but name in "#RRGGBB" form
  1218.         "bold"        "1" if bold
  1219.         "italic"    "1" if italic
  1220.         "reverse"    "1" if reverse
  1221.         "inverse"    "1" if inverse (= reverse)
  1222.         "underline"    "1" if underlined
  1223.  
  1224.         When the GUI is not running or the cterm mode is asked for,
  1225.         "fg#" is equal to "fg" and "bg#" is equal to "bg".
  1226.  
  1227.         Example (echos the color of the syntax item under the cursor):
  1228. >    :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
  1229.  
  1230.                             *synIDtrans()*
  1231. synIDtrans({synID})
  1232.         The result is a Number, which is the translated syntax ID of
  1233.         {synID}.  This is the syntax group ID of what is being used to
  1234.         highlight the character.  Highlight links are followed.
  1235.  
  1236.                             *system()*
  1237. system({expr})    Get the output of the shell command {expr}.  Note: newlines
  1238.         in {expr} may cause the command to fail.  This is not to be
  1239.         used for interactive commands.
  1240.         The result is a String.  To make the result more
  1241.         system-independent, the shell output is filtered to replace
  1242.         <CR> with <NL> for Macintosh, and <CR><NL> with <NL> for
  1243.         DOS-like systems.
  1244.         'shellredir' is used to capture the output of the command.
  1245.         Depending on 'shell', you might be able to capture stdout with
  1246.         ">" and stdout plus stderr with ">&" (csh) or use "2>" to
  1247.         capture stderr (sh).
  1248.  
  1249.                         *tempname()* *temp-file-name*
  1250. tempname()
  1251.         The result is a String, which is the name of a file that
  1252.         doesn't exist.  It can be used for a temporary file.  The name
  1253.         is different for at least 26 consecutive calls.  Example:
  1254. >            let tmpfile = tempname()
  1255. >            exe "redir > " . tmpfile
  1256.  
  1257.                             *visualmode()*
  1258. visualmode()
  1259.         The result is a String, which describes the last Visual mode
  1260.         used.  Initially it returns an empty string, but once Visual
  1261.         mode has been used, it returns "v", "V", or "<CTRL-V>" (a
  1262.         single CTRL-V character) for character-wise, line-wise, or
  1263.         block-wise Visual mode respecively.
  1264.         Example:
  1265. >            exe "normal " . visualmode()
  1266.         This enters the same Visual mode as before.  It is also useful
  1267.         in scripts if you wish to act differently depending on the
  1268.         Visual mode that was used.
  1269.  
  1270.                             *virtcol()*
  1271. virtcol({expr})
  1272.         The result is a Number, which is the screen column of the file
  1273.         position given with {expr}.  That is, the last screen position
  1274.         occupied by the character at that position, when the screen
  1275.         would be of unlimited width.  When there is a <Tab> at the
  1276.         position, the returned Number will be the column at the end of
  1277.         the <Tab>.  For example, for a <Tab> in column 1, with 'ts'
  1278.         set to 8, it returns 8;
  1279.         The accepted positions are:
  1280.             .        the cursor position
  1281.             'x        position of mark x (if the mark is not set, 0 is
  1282.                 returned)
  1283.         Note that only marks in the current file can be used.
  1284.         Examples:
  1285. >  virtcol(".")        with text "foo^Lbar", with cursor on the "^L", returns 5
  1286. >  virtcol("'t")    with text "    there", with 't at 'h', returns 6
  1287.         The first column is 1.  0 is returned for an error.
  1288.  
  1289.                             *winbufnr()*
  1290. winbufnr({nr})    The result is a Number, which is the number of the buffer
  1291.         associated with window {nr}. When {nr} is zero, the number of
  1292.         the buffer in the current window is returned.  When window
  1293.         {nr} doesn't exist, -1 is returned.
  1294.         Example:
  1295. >  echo "The file in the current window is " . bufname(winbufnr(0))
  1296.  
  1297.                             *winheight()*
  1298. winheight({nr})
  1299.         The result is a Number, which is the height of window {nr}.
  1300.         When {nr} is zero, the height of the current window is
  1301.         returned.  When window {nr} doesn't exist, -1 is returned.
  1302.         An existing window always has a height of zero or more.
  1303.         Examples:
  1304. >  echo "The current window has " . winheight(0) . " lines."
  1305.  
  1306.                             *winnr()*
  1307. winnr()        The result is a Number, which is the number of the current
  1308.         window.  The top window has number 1.
  1309.  
  1310.                             *feature-list*
  1311. There are two types of features:
  1312. 1.  Features that are only supported when they have been enabled when Vim
  1313.     was compiled |+feature-list|.  Example:
  1314. >        :if has("cindent")
  1315. 2.  Features that are only supported when certain conditions have been met.
  1316.     Example:
  1317. >        :if has("gui_running")
  1318.  
  1319. all_builtin_terms    Compiled with all builtin terminals enabled.
  1320. amiga            Amiga version of Vim.
  1321. arp            Compiled with ARP support (Amiga).
  1322. autocmd            Compiled with autocommands support.
  1323. beos            BeOS version of Vim.
  1324. browse            Compiled with |:browse| support, and browse() will
  1325.             work.
  1326. builtin_terms        Compiled with some builtin terminals.
  1327. byte_offset        Compiled with support for 'o' in 'statusline'
  1328. cindent            Compiled with 'cindent' support.
  1329. clipboard        Compiled with 'clipboard' support.
  1330. cmdline_compl        Compiled with |cmdline-completion| support.
  1331. cmdline_info        Compiled with 'showcmd' and 'ruler' support.
  1332. comments        Compiled with |'comments'| support.
  1333. cryptv            Compiled with encryption support |encryption|.
  1334. cscope            Compiled with |cscope| support.
  1335. compatible        Compiled to be very Vi compatible.
  1336. debug            Compiled with "DEBUG" defined.
  1337. dialog_con        Compiled with console dialog support.
  1338. dialog_gui        Compiled with GUI dialog support.
  1339. digraphs        Compiled with support for digraphs.
  1340. dos32            32 bits DOS (DJGPP) version of Vim.
  1341. dos16            16 bits DOS version of Vim.
  1342. emacs_tags        Compiled with support for Emacs tags.
  1343. eval            Compiled with expression evaluation support.  Always
  1344.             true, of course!
  1345. ex_extra        Compiled with extra Ex commands |+ex_extra|.
  1346. extra_search        Compiled with support for |'incsearch'| and
  1347.             |'hlsearch'|
  1348. farsi            Compiled with Farsi support |farsi|.
  1349. file_in_path        Compiled with support for |gf| and |<cfile>|
  1350. find_in_path        Compiled with support for include file searches
  1351.             |+find_in_path|.
  1352. fname_case        Case in file names matters (for Amiga, MS-DOS, and
  1353.             Windows this is not present).
  1354. fork            Compiled to use fork()/exec() instead of system().
  1355. gui            Compiled with GUI enabled.
  1356. gui_athena        Compiled with Athena GUI.
  1357. gui_beos        Compiled with BeOs GUI.
  1358. gui_gtk            Compiled with GTK+ GUI.
  1359. gui_mac            Compiled with Macintosh GUI.
  1360. gui_motif        Compiled with Motif GUI.
  1361. gui_win32        Compiled with MS Windows Win32 GUI.
  1362. gui_win32s        idem, and Win32s system being used (Windows 3.1)
  1363. gui_running        Vim is running in the GUI, or it will start soon.
  1364. hangul_input        Compiled with Hangul input support. |hangul|
  1365. insert_expand        Compiled with support for CTRL-X expansion commands in
  1366.             Insert mode.
  1367. langmap            Compiled with 'langmap' support.
  1368. linebreak        Compiled with 'linebreak', 'breakat' and 'showbreak'
  1369.             support.
  1370. lispindent        Compiled with support for lisp indenting.
  1371. mac            Macintosh version of Vim.
  1372. menu            Compiled with support for |:menu|.
  1373. mksession        Compiled with support for |:mksession|.
  1374. modify_fname        Compiled with file name modifiers. |filename-modifiers|
  1375. mouse            Compiled with support mouse.
  1376. mouse_dec        Compiled with support for Dec terminal mouse.
  1377. mouse_gpm        Compiled with support for gpm (Linux console mouse)
  1378. mouse_netterm        Compiled with support for netterm mouse.
  1379. mouse_xterm        Compiled with support for xterm mouse.
  1380. multi_byte        Compiled with support for Korean et al.
  1381. multi_byte_ime        Compiled with support for IME input method
  1382. ole            Compiled with OLE automation support for Win32.
  1383. os2            OS/2 version of Vim.
  1384. osfiletype        Compiled with support for osfiletypes |+osfiletype|
  1385. perl            Compiled with Perl interface.
  1386. python            Compiled with Python interface.
  1387. quickfix        Compiled with |quickfix| support.
  1388. rightleft        Compiled with 'rightleft' support.
  1389. scrollbind        Compiled with 'scrollbind' support.
  1390. showcmd            Compiled with 'showcmd' support.
  1391. smartindent        Compiled with 'smartindent' support.
  1392. sniff            Compiled with SniFF interface support.
  1393. statusline        Compiled with support for 'statusline', 'rulerformat'
  1394.             and special formats of 'titlestring' and 'iconstring'.
  1395. syntax            Compiled with syntax highlighting support.
  1396. syntax_items        There are active syntax highlighting items for the
  1397.             current buffer.
  1398. system            Compiled to use system() instead of fork()/exec().
  1399. tag_binary        Compiled with binary searching in tags files
  1400.             |tag-binary-search|.
  1401. tag_old_static        Compiled with support for old static tags
  1402.             |tag-old-static|.
  1403. tag_any_white        Compiled with support for any white characters in tags
  1404.             files |tag-any-white|.
  1405. tcl            Compiled with Tcl interface.
  1406. terminfo        Compiled with terminfo instead of termcap.
  1407. textobjects        Compiled with support for |text-objects|.
  1408. tgetent            Compiled with tgetent support, able to use a termcap
  1409.             or terminfo file.
  1410. title            Compiled with window title support |'title'|.
  1411. unix            Unix version of Vim.
  1412. user_commands        User-defined commands.
  1413. viminfo            Compiled with viminfo support.
  1414. vim_starting            True while initial source'ing takes place.
  1415. visualextra        Compiled with extra Visual mode commands
  1416.             |blockwise-operators|.
  1417. vms            VMS version of Vim.
  1418. wildmenu        Compiled with 'wildmenu' option.
  1419. wildignore        Compiled with 'wildignore' option.
  1420. winaltkeys        Compiled with 'winaltkeys' option.
  1421. win16            Win16 version of Vim (Windows 3.1).
  1422. win32            Win32 version of Vim (Windows 95/NT).
  1423. writebackup        Compiled with 'writebackup' default on.
  1424. xim            Compiled with X input method support |xim|.
  1425. xfontset        Compiled with X fontset support |xfontset|.
  1426. xterm_clipboard        Compiled with support for xterm clipboard.
  1427. xterm_save        Compiled with support for saving and restoring the
  1428.             xterm screen.
  1429. x11            Compiled with X11 support.
  1430.  
  1431. ==============================================================================
  1432. 5. Defining functions                    *user-functions*
  1433.  
  1434. New functions can be defined.  These can be called with "Name()", just like
  1435. builtin functions.  The name must start with an uppercase letter, to avoid
  1436. confusion with builtin functions.
  1437.  
  1438.                             *:fu* *:function*
  1439. :fu[nction]        List all functions and their arguments.
  1440.  
  1441. :fu[nction] {name}    List function {name}.
  1442.  
  1443. :fu[nction][!] {name}([arguments]) [range] [abort]
  1444.             Define a new function by the name {name}.  The name
  1445.             must be made of alphanumeric characters and '_', and
  1446.             must start with a capital.
  1447.             An argument can be defined by giving its name.  In the
  1448.             function this can then be used as "a:name" ("a:" for
  1449.             argument).
  1450.             Up to 20 arguments can be given, separated by commas.
  1451.             Finally, an argument "..." can be specified, which
  1452.             means that more arguments may be following.  In the
  1453.             function they can be used as "a:1", "a:2", etc.  "a:0"
  1454.             is set to the number of extra arguments (which can be
  1455.             0).
  1456.             When not using "...", the number of arguments in a
  1457.             function call must be equal the number of named
  1458.             arguments.  When using "...", the number of arguments
  1459.             may be larger.
  1460.             It is also possible to define a function without any
  1461.             arguments.  You must still supply the () then.
  1462.             The body of the function follows in the next lines,
  1463.             until ":endfunction".
  1464.             When a function by this name already exists and [!] is
  1465.             not used an error message is given.  When [!] is used,
  1466.             an existing function is silently replaced.
  1467.             When the [range] argument is added, the function is
  1468.             expected to take care of a range itself.  The range is
  1469.             passed as "a:firstline" and "a:lastline".  If [range]
  1470.             is excluded, a ":call" with a range will call the
  1471.             function for each line, with the cursor on the start
  1472.             of each line.
  1473.             When the [abort] argument is added, the function will
  1474.             abort as soon as an error is detected.
  1475.             The last used search pattern and the redo command "."
  1476.             will not be changed by the function.
  1477.  
  1478.                             *:endf* *:endfunction*
  1479. :endf[unction]        The end of a function definition.
  1480.  
  1481.                             *:delf* *:delfunction*
  1482. :delf[unction] {name}    Delete function {name}.
  1483.  
  1484.                             *:retu* *:return*
  1485. :retu[rn] [expr]    Return from a function.  When "[expr]" is given, it is
  1486.             evaluated and returned as the result of the function.
  1487.             If "[expr]" is not given, the number 0 is returned.
  1488.             When a function ends without an explicit ":return",
  1489.             the number 0 is returned.
  1490.             Note that there is no check for unreachable lines,
  1491.             thus there is no warning if commands follow ":return".
  1492.  
  1493. Inside a function variables can be used.  These are local variables, which
  1494. will disappear when the function returns.  Global variables need to be
  1495. accessed with "g:".
  1496.  
  1497. Example:
  1498. >  :function Table(title, ...)
  1499. >  :  echohl Title
  1500. >  :  echo a:title
  1501. >  :  echohl None
  1502. >  :  let idx = 1
  1503. >  :  while idx <= a:0
  1504. >  :    exe "echo a:" . idx
  1505. >  :    let idx = idx + 1
  1506. >  :  endwhile
  1507. >  :  return idx
  1508. >  :endfunction
  1509.  
  1510. This function can then be called with:
  1511. >  let lines = Table("Table", "line1", "line2")
  1512. >  let lines = Table("Empty Table")
  1513.  
  1514. To return more than one value, pass the name of a global variable:
  1515. >  :function Compute(n1, n2, divname)
  1516. >  :  if a:n2 == 0
  1517. >  :    return "fail"
  1518. >  :  endif
  1519. >  :  exe "let " . a:divname . " = ". a:n1 / a:n2
  1520. >  :  return "ok"
  1521. >  :endfunction
  1522.  
  1523. This function can then be called with:
  1524. >  :let success = Compute(13, 1324, "div")
  1525. >  :if success == "ok"
  1526. >  :  echo div
  1527. >  :endif
  1528.  
  1529.                             *:cal* *:call*
  1530. :[range]cal[l] {name}([arguments])
  1531.         Call a function.  The name of the function and its arguments
  1532.         are as specified with |:function|.  Up to 20 arguments can be
  1533.         used.
  1534.         Without a range and for functions that accept a range, the
  1535.         function is called once, with the cursor at the current
  1536.         position.
  1537.         When a range is given and the function doesn't handle it
  1538.         itself, the function is executed for each line in the range,
  1539.         with the cursor in the first column of that line.  The cursor
  1540.         is left at the last line (possibly moved by the last function
  1541.         call).  The arguments are re-evaluated for each line.  Thus
  1542.         this works:
  1543.  
  1544. >    :function Mynumber(arg)
  1545. >    :  echo line(".") . " " . a:arg
  1546. >    :endfunction
  1547. >    :1,5call Mynumber(getline("."))
  1548.  
  1549. The recursiveness of user functions is restricted with the |'maxfuncdepth'|
  1550. option.
  1551.  
  1552. ==============================================================================
  1553. 6. Commands                        *expression-commands*
  1554.  
  1555. :let {var-name} = {expr1}                *:let*
  1556.             Set internal variable {var-name} to the result of the
  1557.             expression {expr1}.  The variable will get the type
  1558.             from the {expr}.  if {var-name} didn't exist yet, it
  1559.             is created.
  1560.  
  1561. :let ${env-name} = {expr1}            *:let-environment* *:let-$*
  1562.             Set environment variable {env-name} to the result of
  1563.             the expression {expr1}.  The type is always String.
  1564.  
  1565. :let @{reg-name} = {expr1}            *:let-register* *:let-@*
  1566.             Write the result of the expression {expr1} in register
  1567.             {reg-name}.  {reg-name} must be a single letter, and
  1568.             must be the name of a writable register (see
  1569.             |registers|).  "@@" can be used for the unnamed
  1570.             register, "@/" for the search pattern.
  1571.             If the result of {expr1} ends in a <CR> or <NL>, the
  1572.             register will be linewise, otherwise it will be set to
  1573.             characterwise.
  1574.  
  1575. :let &{option-name} = {expr1}            *:let-option* *:let-star*
  1576.             Set option {option-name} to the result of the
  1577.             expression {expr1}.  The type of the option is always
  1578.             used.
  1579.  
  1580.                             *:unlet* *:unl*
  1581. :unl[et][!] {var-name} ...
  1582.             Remove the internal variable {var-name}.  Several
  1583.             variable names can be given, they are all removed.
  1584.             With [!] no error message is given for non-existing
  1585.             variables.
  1586.  
  1587. :if {expr1}                        *:if* *:endif* *:en*
  1588. :en[dif]        Execute the commands until the next matching ":else"
  1589.             or ":endif" if {expr1} evaluates to non-zero.
  1590.  
  1591.             From Vim version 4.5 until 5.0, every Ex command in
  1592.             between the ":if" and ":endif" is ignored.  These two
  1593.             commands were just to allow for future expansions in a
  1594.             backwards compatible way.  Nesting was allowed.  Note
  1595.             that any ":else" or ":elseif" was ignored, the "else"
  1596.             part was not executed either.
  1597.  
  1598.             You can use this to remain compatible with older
  1599.             versions:
  1600. >                :if version >= 500
  1601. >                :  version-5-specific-commands
  1602. >                :endif
  1603.  
  1604.                             *:else* *:el*
  1605. :el[se]            Execute the commands until the next matching ":else"
  1606.             or ":endif" if they previously were not being
  1607.             executed.
  1608.  
  1609.                             *:elseif* *:elsei*
  1610. :elsei[f] {expr1}    Short for ":else" ":if", with the addition that there
  1611.             is no extra ":endif".
  1612.  
  1613. :wh[ile] {expr1}            *:while* *:endwhile* *:wh* *:endw*
  1614. :endw[hile]        Repeat the commands between ":while" and ":endwhile",
  1615.             as long as {expr1} evaluates to non-zero.
  1616.             When an error is detected from a command inside the
  1617.             loop, execution continues after the "endwhile".
  1618.  
  1619.         NOTE: The ":append" and ":insert" commands don't work properly
  1620.         inside a ":while" loop.
  1621.  
  1622.                             *:continue* *:con*
  1623. :con[tinue]        When used inside a ":while", jumps back to the
  1624.             ":while".
  1625.  
  1626.                             *:break* *:brea*
  1627. :brea[k]        When used inside a ":while", skips to the command
  1628.             after the matching ":endwhile".
  1629.  
  1630.                             *:ec* *:echo*
  1631. :ec[ho] {expr1} ..    Echoes each {expr1}, with a space in between and a
  1632.             terminating <EOL>.  Also see |:comment|.
  1633.             Use "\n" to start a new line.  Use "\r" to move the
  1634.             cursor to the first column.
  1635.             Cannot be followed by a comment.
  1636.             Example:
  1637. >        :echo "the value of 'shell' is" &shell
  1638.  
  1639.                             *:echon*
  1640. :echon {expr1} ..    Echoes each {expr1}, without anything added.  Also see
  1641.             |:comment|.
  1642.             Cannot be followed by a comment.
  1643.             Example:
  1644. >        :echon "the value of 'shell' is " &shell
  1645.  
  1646.             Note the difference between using ":echo", which is a
  1647.             Vim command, and ":!echo", which is an external shell
  1648.             command:
  1649. >        :!echo %        --> filename
  1650.             The arguments of ":!" are expanded, see |:_%|.
  1651. >        :!echo "%"        --> filename or "filename"
  1652.             Like the previous example.  Whether you see the double
  1653.             quotes or not depends on your 'shell'.
  1654. >        :echo %            --> nothing
  1655.             The '%' is an illegal character in an expression.
  1656. >        :echo "%"        --> %
  1657.             This just echoes the '%' character.
  1658. >        :echo expand("%")    --> filename
  1659.             This calls the expand() function to expand the '%'.
  1660.  
  1661.                             *:echoh* *:echohl*
  1662. :echoh[l] {name}    Use the highlight group {name} for the following
  1663.             ":echo[n]" commands.  Example:
  1664. >        :echohl WarningMsg | echo "Don't panic!" | echohl None
  1665.             Don't forget to set the group back to "None",
  1666.             otherwise all following echo's will be highlighted.
  1667.  
  1668.                             *:exe* *:execute*
  1669. :exe[cute] {expr1} ..    Executes the string that results from the evaluation
  1670.             of {expr1} as an Ex command.  Multiple arguments are
  1671.             concatenated, with a space in between.
  1672.             Cannot be followed by a comment.
  1673.             Examples:
  1674. >        :execute "buffer " nextbuf
  1675. >        :execute "normal " count . "w"
  1676.  
  1677.             Execute can be used to append a next command to
  1678.             commands that don't accept a '|'.  Example:
  1679. >        :execute '!ls' | echo "theend"
  1680.  
  1681.             Note: The executed string may be any command-line, but
  1682.             you cannot start or end a "while" or "if" command.
  1683.             Thus this is illegal:
  1684. >        :execute 'while i > 5'
  1685. >        :execute 'echo "test" | break'
  1686.  
  1687.             It is allowed to have a "while" or "if" command
  1688.             completely in the executed string:
  1689. >        :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
  1690.  
  1691.  
  1692.                             *:comment*
  1693.             ":execute", ":echo" and ":echon" cannot be followed by
  1694.             a comment directly, because they see the '"' as the
  1695.             start of a string.  But, you can use '|' followed by a
  1696.             comment.  Example:
  1697. >        :echo "foo" | "this is a comment
  1698.  
  1699. ==============================================================================
  1700. 7. Examples                        *eval-examples*
  1701.  
  1702. Printing in Hex ~
  1703.  
  1704. >  " The function Nr2Hex() returns the Hex string of a number.
  1705. >  func Nr2Hex(nr)
  1706. >    let n = a:nr
  1707. >    let r = ""
  1708. >    while n
  1709. >      let r = '0123456789ABCDEF'[n % 16] . r
  1710. >      let n = n / 16
  1711. >    endwhile
  1712. >    return r
  1713. >  endfunc
  1714. >
  1715. >  " The function String2Hex() converts each character in a string to a two
  1716. >  " character Hex string.
  1717. >  func String2Hex(str)
  1718. >    let out = ''
  1719. >    let ix = 0
  1720. >    while ix < strlen(a:str)
  1721. >      let out = out . Nr2Hex(char2nr(a:str[ix]))
  1722. >      let ix = ix + 1
  1723. >    endwhile
  1724. >    return out
  1725. >  endfunc
  1726.  
  1727. Example of its use:
  1728. >  echo Nr2Hex(32)
  1729. result: "20"
  1730. >  echo String2Hex("32")
  1731. result: "3332"
  1732.  
  1733.  
  1734. Sorting lines (by Robert Webb) ~
  1735.  
  1736. Here is a vim script to sort lines.  Highlight the lines in vim and type
  1737. ":Sort".  This doesn't call any external programs so it'll work on any
  1738. platform.  The function Sort() actually takes the name of a comparison
  1739. function as its argument, like qsort() does in C.  So you could supply it
  1740. with different comparison functions in order to sort according to date etc.
  1741.  
  1742. > " Function for use with Sort(), to compare two strings.
  1743. > func! Strcmp(str1, str2)
  1744. >     if (a:str1 < a:str2)
  1745. >    return -1
  1746. >     elseif (a:str1 > a:str2)
  1747. >    return 1
  1748. >     else
  1749. >    return 0
  1750. >     endif
  1751. > endfunction
  1752. >
  1753. > " Sort lines.  SortR() is called recursively.
  1754. > func! SortR(start, end, cmp)
  1755. >     if (a:start >= a:end)
  1756. >    return
  1757. >     endif
  1758. >     let partition = a:start - 1
  1759. >     let middle = partition
  1760. >     let partStr = getline((a:start + a:end) / 2)
  1761. >     let i = a:start
  1762. >     while (i <= a:end)
  1763. >    let str = getline(i)
  1764. >    exec "let result = " . a:cmp . "(str, partStr)"
  1765. >    if (result <= 0)
  1766. >        " Need to put it before the partition.  Swap lines i and partition.
  1767. >        let partition = partition + 1
  1768. >        if (result == 0)
  1769. >        let middle = partition
  1770. >        endif
  1771. >        if (i != partition)
  1772. >        let str2 = getline(partition)
  1773. >        call setline(i, str2)
  1774. >        call setline(partition, str)
  1775. >        endif
  1776. >    endif
  1777. >    let i = i + 1
  1778. >     endwhile
  1779. >
  1780. >     " Now we have a pointer to the "middle" element, as far as partitioning
  1781. >     " goes, which could be anywhere before the partition.  Make sure it is at
  1782. >     " the end of the partition.
  1783. >     if (middle != partition)
  1784. >    let str = getline(middle)
  1785. >    let str2 = getline(partition)
  1786. >    call setline(middle, str2)
  1787. >    call setline(partition, str)
  1788. >     endif
  1789. >     call SortR(a:start, partition - 1, a:cmp)
  1790. >     call SortR(partition + 1, a:end, a:cmp)
  1791. > endfunc
  1792. >
  1793. > " To Sort a range of lines, pass the range to Sort() along with the name of a
  1794. > " function that will compare two lines.
  1795. > func! Sort(cmp) range
  1796. >     call SortR(a:firstline, a:lastline, a:cmp)
  1797. > endfunc
  1798. >
  1799. > " :Sort takes a range of lines and sorts them.
  1800. > command! -nargs=0 -range Sort <line1>,<line2>call Sort("Strcmp")
  1801.  
  1802. ==============================================================================
  1803. 8. No +eval feature                *no-eval-feature*
  1804.  
  1805. When the |+eval| feature was disabled at compile time, all the expression
  1806. evaluation commands are not available.  To avoid that a Vim script generates
  1807. all kinds of errors, the ":if" and ":endif" commands are recognized.
  1808. Everything between the ":if" and the matching ":endif" is ignored.  It does
  1809. not matter what argument is used after the ":if".  Nesting of these commands
  1810. is recognized, but only if the commands are at the start of the line.  The
  1811. ":else" command is not recognized.
  1812.  
  1813. Example of how to avoid commands to be executed when the |+eval| feature is
  1814. missing:
  1815. >    if 1
  1816. >      echo "Expression evaluation is compiled in"
  1817. >    endif
  1818.  
  1819.  vim:tw=78:ts=8:sw=8:
  1820.