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 / vim54rt.sit / runtime / doc / eval.txt < prev    next >
Encoding:
Text File  |  1999-08-24  |  65.3 KB  |  1,804 lines  |  [TEXT/MPS ]

  1. *eval.txt*      For Vim version 5.4.  Last change: 1999 Aug 22
  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. setline( {lnum}, {line})    Number    set line {lnum} to {line}
  491. strftime( {format}[, {time}])    String    time in specified format
  492. strlen( {expr})            Number    length of the String {expr}
  493. strpart( {src}, {start}, {len})    String    {len} characters of {src} at {start}
  494. strtrans( {expr})        String    translate sting to make it printable
  495. substitute( {expr}, {pat}, {sub}, {flags})
  496.                 String    all {pat} in {expr} replaced with {sub}
  497. synID( {line}, {col}, {trans})    Number    syntax ID at {line} and {col}
  498. synIDattr( {synID}, {what} [, {mode}])
  499.                 String    attribute {what} of syntax ID {synID}
  500. synIDtrans( {synID})        Number    translated syntax ID of {synID}
  501. system( {expr})            String    output of shell command {expr}
  502. tempname()            String    name for a temporary file
  503. virtcol( {expr})        Number    screen column of cursor or mark
  504. visualmode()            String    last visual mode used
  505. winbufnr( {nr})            Number    buffer number of window {nr}
  506. winheight( {nr})        Number    height of window {nr}
  507. winnr()                Number    number of current window
  508.  
  509. append({lnum}, {string}                    *append()*
  510.         Append the text {string} after line {lnum} in the current
  511.         buffer.  {lnum} can be zero, to insert a line before the first
  512.         one.  Returns 1 for failure ({lnum} out of range) or 0 for
  513.         success.
  514.  
  515.                             *argc()*
  516. argc()        The result is the number of files in the argument list.  See
  517.         |arglist|.
  518.  
  519.                             *argv()*
  520. argv({nr})    The result is the {nr}th file in the argument list.  See
  521.         |arglist|.  "argv(0)" is the first one.  Example:
  522. >    let i = 0
  523. >    while i < argc()
  524. >      let f = substitute(argv(i), '\([. ]\)', '\\&', 'g')
  525. >      exe 'amenu Arg.' . f . ' :e ' . f . '<CR>'
  526. >      let i = i + 1
  527. >    endwhile
  528.  
  529.                             *browse()*
  530. browse({save}, {title}, {initdir}, {default})
  531.         Put up a file requester.  This only works when "has("browse")"
  532.         returns non-zero (only in some GUI versions).
  533.         The input fields are:
  534.             {save}    when non-zero, select file to write
  535.             {title}    title for the requester
  536.             {initdir}    directory to start browsing in
  537.             {default}    default file name
  538.         When the "Cancel" button is hit, something went wrong, or
  539.         browsing is not possible, an empty string is returned.
  540.  
  541.                             *bufexists()*
  542. bufexists({expr})
  543.         The result is a Number, which is non-zero if a buffer called
  544.         {expr} exists.  If the {expr} argument is a string it must
  545.         match a buffer name exactly.  If the {expr} argument is a
  546.         number buffer numbers are used.  Use "bufexists(0)" to test
  547.         for the existence of an alternate file name.
  548.                             *buffer_exists()*
  549.         Obsolete name: buffer_exists().
  550.  
  551.                             *bufloaded()*
  552. bufloaded({expr})
  553.         The result is a Number, which is non-zero if a buffer called
  554.         {expr} exists and is loaded (shown in a window or hidden).
  555.         The {expr} argument is used like with bufexists().
  556.  
  557.                             *bufname()*
  558. bufname({expr})
  559.         The result is the name of a buffer, as it is displayed by the
  560.         ":ls" command.
  561.         If {expr} is a Number, that buffer number's name is given.
  562.         Number zero is the alternate buffer for the current window.
  563.         If {expr} is a String, it is used as a regexp pattern to match
  564.         with the buffer names.  This is always done like 'magic' is
  565.         set and 'cpoptions' is empty.  When there is more than one
  566.         match an empty string is returned.  "" or "%" can be used for
  567.         the current buffer, "#" for the alternate buffer.
  568.         If the {expr} is a String, but you want to use it as a buffer
  569.         number, force it to be a Number by adding zero to it:
  570. >            echo bufname("3" + 0)
  571.         If the buffer doesn't exist, or doesn't have a name, an empty
  572.         string is returned.
  573. >  bufname("#")            alternate buffer name
  574. >  bufname(3)            name of buffer 3
  575. >  bufname("%")            name of current buffer
  576. >  bufname("file2")        name of buffer where "file2" matches.
  577.                             *buffer_name()*
  578.         Obsolete name: buffer_name().
  579.  
  580.                             *bufnr()*
  581. bufnr({expr})    The result is the number of a buffer, as it is displayed by
  582.         the ":ls" command.  For the use of {expr}, see bufname()
  583.         above.  If the buffer doesn't exist, -1 is returned.
  584.         bufnr("$") is the last buffer:
  585. >  :let last_buffer = bufnr("$")
  586.         The result is a Number, which is the highest buffer number
  587.         of existing buffers.  Note that not all buffers with a smaller
  588.         number necessarily exist, because ":bdel" may have removed
  589.         them.  Use bufexists() to test for the existence of a buffer.
  590.                             *buffer_number()*
  591.         Obsolete name: buffer_number().
  592.                             *last_buffer_nr()*
  593.         Obsolete name for bufnr("$"): last_buffer_nr().
  594.  
  595.                             *bufwinnr()*
  596. bufwinnr({expr})
  597.         The result is a Number, which is the number of the first
  598.         window associated with buffer {expr}.  For the use of {expr},
  599.         see bufname() above.  If buffer {expr} doesn't exist or there
  600.         is no such window, -1 is returned.  Example:
  601. >  echo "A window containing buffer 1 is " . (bufwinnr(1))
  602.  
  603.                             *byte2line()*
  604. byte2line({byte})
  605.         Return the line number that contains the character at byte
  606.         count {byte} in the current buffer.  This includes the
  607.         end-of-line character, depending on the 'fileformat' option
  608.         for the current buffer.  The first character has byte count
  609.         one.
  610.         Also see |line2byte()|, |go| and |:goto|.
  611.  
  612.                             *char2nr()*
  613. char2nr({expr})
  614.         Return ASCII value of the first char in {expr}.  Examples:
  615. >            char2nr(" ")        returns 32
  616. >            char2nr("ABC")        returns 65
  617.  
  618.                             *col()*
  619. col({expr})    The result is a Number, which is the column of the file
  620.         position given with {expr}.  The accepted positions are:
  621.             .        the cursor position
  622.             'x        position of mark x (if the mark is not set, 0 is
  623.                 returned)
  624.         Note that only marks in the current file can be used.
  625.         Examples:
  626. >            col(".")        column of cursor
  627. >            col("'t")        column of mark t
  628. >            col("'" . markname)    column of mark markname
  629.         The first column is 1.  0 is returned for an error.
  630.  
  631.                             *confirm()*
  632. confirm({msg}, {choices} [, {default} [, {type}]])
  633.         Confirm() offers the user a dialog, from which a choice can be
  634.         made.  It returns the number of the choice.  For the first
  635.         choice this is 1.
  636.         Note: confirm() is only supported when compiled with dialog
  637.         support, see |+dialog_con| and |+dialog_gui|.
  638.         {msg} is displayed in a |dialog| with {choices} as the
  639.         alternatives.
  640.         {msg} is a String, use '\n' to include a newline.  Only on
  641.         some systems the string is wrapped when it doesn't fit.
  642.         {choices} is a String, with the individual choices separated
  643.         by '\n', e.g.
  644. >            confirm("Save changes?", "&Yes\n&No\n&Cancel")
  645.         The letter after the '&' is the shortcut key for that choice.
  646.         Thus you can type 'c' to select "Cancel".  The shorcut does
  647.         not need to be the first letter:
  648. >            confirm("file has been modified", "&Save\nSave &All")
  649.         For the console, the first letter of each choice is used as
  650.         the default shortcut key.
  651.         The optional {default} argument is the number of the choice
  652.         that is made if the user hits <CR>.  Use 1 to make the first
  653.         choice the default one.  Use 0 to not set a default.  If
  654.         {default} is omitted, 0 is used.
  655.         The optional {type} argument gives the type of dialog.  This
  656.         is only used for the icon of the Win32 GUI.  It can be one of
  657.         these values: "Error", "Question", "Info", "Warning" or
  658.         "Generic".  Only the first character is relevant.
  659.         If the user aborts the dialog by pressing <Esc>, CTRL-C,
  660.         or another valid interrupt key, confirm() returns 0.
  661.  
  662.         An example:
  663. >   :let choice = confirm("What do you want?", "&Apples\n&Oranges\n&Bananas", 2)
  664. >   :if choice == 0
  665. >   :    echo "make up your mind!"
  666. >   :elseif choice == 3
  667. >   :    echo "tasteful"
  668. >   :else
  669. >   :    echo "I prefer bananas myself."
  670. >   :endif
  671.         In a GUI dialog, buttons are used.  The layout of the buttons
  672.         depends on the 'v' flag in 'guioptions'.  If it is included,
  673.         the buttons are always put vertically.  Otherwise,  confirm()
  674.         tries to put the buttons in one horizontal line.  If they
  675.         don't fit, a vertical layout is used anyway.  For some systems
  676.         the horizontal layout is always used.
  677.  
  678.                             *delete()*
  679. delete({fname})    Deletes the file by the name {fname}.  The result is a Number,
  680.         which is 0 if the file was deleted successfully, and non-zero
  681.         when the deletion failed.
  682.  
  683.                             *did_filetype()*
  684. did_filetype()    Returns non-zero when autocommands are being executed and the
  685.         FileType event has been triggered at least once.  Can be used
  686.         to avoid triggering the FileType event again in the scripts
  687.         that detect the file type. |FileType|
  688.  
  689.                             *escape()*
  690. escape({string}, {chars})
  691.         Escape the characters in {chars} that occur in {string} with a
  692.         backslash.  Example:
  693. >            :echo escape('c:\program files\vim', ' \')
  694.         results in:
  695. >            c:\\program\ files\\vim
  696.  
  697.                             *exists()*
  698. exists({expr})    The result is a Number, which is 1 if {var} is defined, zero
  699.         otherwise.  The {expr} argument is a string, which contains
  700.         one of these:
  701.             &option-name    Vim option
  702.             $ENVNAME    environment variable (could also be
  703.                     done by comparing with an empty
  704.                     string)
  705.             *funcname    built-in function (see |functions|)
  706.                     or user defined function (see
  707.                     |user-functions|).
  708.             varname        internal variable (see
  709.                     |internal-variables|).
  710.  
  711.         Examples:
  712. >            exists("&shortname")
  713. >            exists("$HOSTNAME")
  714. >            exists("*strftime")
  715. >            exists("bufcount")
  716.         There must be no space between the symbol &/$/* and the name.
  717.         Note that the argument must be a string, not the name of the
  718.         variable itself!  This doesn't check for existence of the
  719.         "bufcount" variable, but gets the contents of "bufcount", and
  720.         checks if that exists:
  721.             exists(bufcount)
  722.  
  723.                             *expand()*
  724. expand({expr} [, {flag}])
  725.         Expand wildcards and the following special keywords in {expr}.
  726.         The result is a String.
  727.  
  728.         When there are several matches, they are separated by <NL>
  729.         characters.  [Note: in version 5.0 a space was used, which
  730.         caused problems when a file name contains a space]
  731.  
  732.         If the expansion fails, the result is an empty string.  A name
  733.         for a non-existing file is not included.
  734.  
  735.         When {expr} starts with '%', '#' or '<', the expansion is done
  736.         like for the |cmdline-special| variables with their associated
  737.         modifiers.  Here is a short overview:
  738.  
  739.             %        current file name
  740.             #        alternate file name
  741.             #n        alternate file name n
  742.             <cfile>        file name under the cursor
  743.             <afile>        autocmd file name
  744.             <abuf>        autocmd buffer number
  745.             <sfile>        sourced script file name
  746.             <cword>        word under the cursor
  747.             <cWORD>        WORD under the cursor
  748.         Modifiers:
  749.             :p        expand to full path
  750.             :h        head (last path component removed)
  751.             :t        tail (last path component only)
  752.             :r        root (one extension removed)
  753.             :e        extension only
  754.  
  755.         Example:
  756. >            :let &tags = expand("%:p:h") . "/tags"
  757.         Note that when expanding a string that starts with '%', '#' or
  758.         '<', any following text is ignored.  This does NOT work:
  759. >            :let doesntwork = expand("%:h.bak")
  760.         Use this:
  761. >            :let doeswork = expand("%:h") . ".bak"
  762.         Also note that expanding "<cfile>" and others only returns the
  763.         referenced file name without further expansion.  If "<cfile>"
  764.         is "~/.cshrc", you need to do another expand() to have the
  765.         "~/" expanded into the path of the home directory:
  766. >            :echo expand(expand("<cfile>"))
  767.  
  768.         There cannot be white space between the variables and the
  769.         following modifier.  The |fnamemodify()| function can be used
  770.         to modify normal file names.
  771.  
  772.         When using '%' or '#', and the current or alternate file name
  773.         is not defined, an empty string is used.  Using "%:p" in a
  774.         buffer with no name, results in the current directory, with a
  775.         '/' added.
  776.  
  777.         When {expr} does not start with '%', '#' or '<', it is
  778.         expanded like a file name is expanded on the command line.
  779.         'suffixes' and 'wildignore' are used, unless the optional
  780.         {flag} argument is given and it is non-zero.
  781.  
  782.         Expand() can also be used to expand variables and environment
  783.         variables that are only known in a shell.  But this can be
  784.         slow, because a shell must be started.  See |expr-env-expand|.
  785.  
  786.         See |glob()| for finding existing files.  See |system()| for
  787.         getting the raw output of an external command.
  788.  
  789.                             *filereadable()*
  790. filereadable({file})
  791.         The result is a Number, which is TRUE when a file with the
  792.         name {file} exists, and can be read.  If {file} doesn't exist,
  793.         or is a directory, the result is FALSE.  {file} is any
  794.         expression, which is used as a String.
  795.                             *file_readable()*
  796.         Obsolete name: file_readable().
  797.  
  798.                             *fnamemodify()*
  799. fnamemodify({fname}, {mods})
  800.         Modify file name {fname} according to {mods}.  {mods} is a
  801.         string of characters like it is used for file names on the
  802.         command line.  See |filename-modifiers|.
  803.         Example:
  804. >            :echo fnamemodify("main.c", ":p:h")
  805.         results in:
  806. >            /home/mool/vim/vim/src/
  807.  
  808.                             *getcwd()*
  809. getcwd()    The result is a String, which is the name of the current
  810.         working directory.
  811.  
  812.                             *getftime()*
  813. getftime({fname})
  814.         The result is a Number, which is the last modification time of
  815.         the given file {fname}.  The value is measured as seconds
  816.         since 1st Jan 1970, and may be passed to strftime().  See also
  817.         |localtime()| and |strftime()|.
  818.  
  819.                             *getline()*
  820. getline({lnum}) The result is a String, which is line {lnum} from the current
  821.         buffer.  Example:
  822. >            getline(1)
  823.         When {lnum} is a String that doesn't start with a
  824.         digit, line() is called to translate the String into a Number.
  825.         To get the line under the cursor:
  826. >            getline(".")
  827.         When {lnum} is smaller than 1 or bigger than the number of
  828.         lines in the buffer, an empty string is returned.
  829.  
  830.                             *getwinposx()*
  831. getwinposx()    The result is a Number, which is the X coordinate in pixels of
  832.         the left hand side of the GUI vim window.  The result will be
  833.         -1 if the information is not available.
  834.  
  835.                             *getwinposy()*
  836. getwinposy()    The result is a Number, which is the Y coordinate in pixels of
  837.         the top of the GUI vim window.  The result will be -1 if the
  838.         information is not available.
  839.  
  840.                             *glob()*
  841. glob({expr})    Expand the file wildcards in {expr}.  The result is a String.
  842.         When there are several matches, they are separated by <NL>
  843.         characters.
  844.         If the expansion fails, the result is an empty string.
  845.         A name for a non-existing file is not included.
  846.  
  847.         For most systems backticks can be used to get files names from
  848.         any external command.  Example:
  849. >            :let tagfiles = glob("`find . -name tags -print`")
  850. >            :let &tags = substitute(tagfiles, "\n", ",", "g")
  851.         The result of the program inside the backticks should be one
  852.         item per line.  Spaces inside an item are allowed.
  853.  
  854.         See |expand()| for expanding special Vim variables.  See
  855.         |system()| for getting the raw output of an external command.
  856.  
  857.                             *has()*
  858. has({feature})    The result is a Number, which is 1 if the feature {feature} is
  859.         supported, zero otherwise.  The {feature} argument is a
  860.         string.  See |feature-list| below.
  861.  
  862.                             *histadd()*
  863. histadd({history}, {item})
  864.         Add the String {item} to the history {history} which can be
  865.         one of:                    *hist-names*
  866.             "cmd"     or ":"      command line history
  867.             "search" or "/"   search pattern history
  868.             "expr"   or "="   typed expression history
  869.             "input"  or "@"      input line history
  870.         If {item} does already exist in the history, it will be
  871.         shifted to become the newest entry.
  872.         The result is a Number: 1 if the operation was successful,
  873.         otherwise 0 is returned.
  874.  
  875.         Example:
  876. >            :call histadd("input", strftime("%Y %b %d"))
  877. >            :let date=input("Enter date: ")
  878.  
  879.                             *histdel()*
  880. histdel({history} [, {item}])
  881.         Clear {history}, ie. delete all its entries.  See |hist-names|
  882.         for the possible values of {history}.
  883.  
  884.         If the parameter {item} is given as String, this is seen
  885.         as regular expression.  All entries matching that expression
  886.         will be removed from the history (if there are any).
  887.         If {item} is a Number, it will be interpreted as index, see
  888.         |:history-indexing|.  The respective entry will be removed
  889.         if it exists.
  890.  
  891.         The result is a Number: 1 for a successful operation,
  892.         otherwise 0 is returned.
  893.  
  894.         Examples:
  895.         Clear expression register history:
  896. >            :call histdel("expr")
  897.  
  898.         Remove all entries starting with "*" from the search history:
  899. >            :call histdel("/", '^\*')
  900.  
  901.         The following three are equivalent:
  902. >            :call histdel("search", histnr("search"))
  903. >            :call histdel("search", -1)
  904. >            :call histdel("search", '^'.histget("search", -1).'$')
  905.  
  906.         To delete the last search pattern and use the last-but-one for
  907.         the "n" command and 'hlsearch':
  908. >            :call histdel("search", -1)
  909. >            :let @/ = histget("search", -1)
  910.  
  911.  
  912.                             *histget()*
  913. histget({history} [, {index}])
  914.         The result is a String, the entry with Number {index} from
  915.         {history}.  See |hist-names| for the possible values of
  916.         {history}, and |:history-indexing| for {index}.  If there is
  917.         no such entry, an empty String is returned.  When {index} is
  918.         omitted, the most recent item from the history is used.
  919.  
  920.         Examples:
  921.             Redo the second last search from history.
  922. >            :execute '/' . histget("search", -2)
  923.  
  924.             Define an Ex command ":H {num}" that supports
  925.             re-execution of the {num}th entry from the output
  926.             of |:history|.
  927. >            :command -nargs=1 H execute histget("cmd",0+<args>)
  928.  
  929.                             *histnr()*
  930. histnr({history})
  931.         The result is the Number of the current entry in {history}.
  932.         See |hist-names| for the possible values of {history}.
  933.         If an error occurred, -1 is returned.
  934.  
  935.         Example:
  936. >            :let inp_index = histnr("expr")
  937.  
  938.                             *hlexists()*
  939. hlexists({name})
  940.         The result is a Number, which is non-zero if a highlight group
  941.         called {name} exists.  This is when the group has been
  942.         defined in some way.  Not necessarily when highlighting has
  943.         been defined for it, it may also have been used for a syntax
  944.         item.
  945.                             *highlight_exists()*
  946.         Obsolete name: highlight_exists().
  947.  
  948.                             *hlID()*
  949. hlID({name})    The result is a Number, which is the ID of the highlight group
  950.         with name {name}.  When the highlight group doesn't exist,
  951.         zero is returned.
  952.         This can be used to retrieve information about the highlight
  953.         group.  For example, to get the background color of the
  954.         "Comment" group:
  955. >    :echo synIDattr(synIDtrans(hlID("Comment")), "bg")
  956.                             *highlightID()*
  957.         Obsolete name: highlightID().
  958.  
  959.                             *hostname()*
  960. hostname()
  961.         The result is a String, which is the name of the machine on
  962.         which Vim is currently running. Machine names greater than
  963.         256 characters long are truncated.
  964.  
  965. input({prompt})                        *input()*
  966.         The result is a String, which is whatever the user typed on
  967.         the command-line.  The parameter is either a prompt string, or
  968.         a blank string (for no prompt).  A '\n' can be used in the
  969.         prompt to start a new line.  The highlighting set with
  970.         |:echohl| is used for the prompt.  The input is entered just
  971.         like a command-line, with the same editing commands and
  972.         mappings.  There is a separate history for lines typed for
  973.         input().
  974.         NOTE: This must not be used in a startup file, for the
  975.         versions that only run in GUI mode (e.g., the Win32 GUI).
  976.  
  977.         Example:
  978. >    :let choice = input("What is your choice? ")
  979.  
  980.                             *isdirectory()*
  981. isdirectory({directory})
  982.         The result is a Number, which is TRUE when a directory with
  983.         the name {directory} exists.  If {directory} doesn't exist, or
  984.         isn't a directory, the result is FALSE.  {directory} is any
  985.         expression, which is used as a String.
  986.  
  987.                             *libcall()*
  988. libcall({libname}, {funcname}, {argument})
  989.         Call function {funcname} in the run-time library {libname}
  990.         with argument {argument}.  The result is the String returned.
  991.         If {argument} is a number, it is passed to the function as an
  992.         int; if {param} is a string, it is passed as a null-terminated
  993.         string.  If the function returns NULL, this will appear as an
  994.         empty string "" to Vim.
  995.         WARNING: If the function returns a non-valid pointer, Vim will
  996.         crash!  This also happens if the function returns a number.
  997.         For Win32 systems, {libname} should be the filename of the DLL
  998.         without the ".DLL" suffix.  A full path is only required if
  999.         the DLL is not in the usual places.
  1000.         {only in Win32 versions}
  1001.  
  1002.                             *line()*
  1003. line({expr})    The result is a Number, which is the line number of the file
  1004.         position given with {expr}.  The accepted positions are:
  1005.             .        the cursor position
  1006.             $        the last line in the current buffer
  1007.             'x        position of mark x (if the mark is not set, 0 is
  1008.                 returned)
  1009.         Note that only marks in the current file can be used.
  1010.         Examples:
  1011. >            line(".")        line number of the cursor
  1012. >            line("'t")        line number of mark t
  1013. >            line("'" . marker)    line number of mark marker
  1014.                             *last-position-jump*
  1015.         This autocommand jumps to the last known position in a file
  1016.         just after opening it, if the '" mark is set:
  1017. >    :au BufReadPost * if line("'\"") | exe "normal '\"" | endif
  1018.  
  1019.                             *line2byte()*
  1020. line2byte({lnum})
  1021.         Return the byte count from the start of the buffer for line
  1022.         {lnum}.  This includes the end-of-line character, depending on
  1023.         the 'fileformat' option for the current buffer.  The first
  1024.         line returns 1;
  1025.         Also see |byte2line()|, |go| and |:goto|.
  1026.  
  1027.                             *localtime()*
  1028. localtime()
  1029.         Return the current time, measured as seconds since 1st Jan
  1030.         1970.  See also |strftime()| and |getftime()|.
  1031.  
  1032.                             *maparg()*
  1033. maparg({name}[, {mode}])
  1034.         Return the rhs of mapping {name} in mode {mode}.  When there
  1035.         is no mapping for {name}, an empty String is returned.
  1036.         These characters can be used for {mode}:
  1037.             "n"    Normal
  1038.             "v"    Visual
  1039.             "o"    Operator-pending
  1040.             "i"    Insert
  1041.             "c"    Cmd-line
  1042.             ""    Normal, Visual and Operator-pending
  1043.         When {mode} is omitted, the modes from "" are used.
  1044.         The {name} can have special key names, like in the ":map"
  1045.         command.  The returned String has special characters
  1046.         translated like in the output of the ":map" command listing.
  1047.  
  1048.                             *mapcheck()*
  1049. mapcheck({name}[, {mode}])
  1050.         Check if there is a mapping that matches with {name} in mode
  1051.         {mode}.  See |maparg()| for {mode} and special names in
  1052.         {name}.
  1053.         When there is no mapping that matches with {name}, and empty
  1054.         String is returned.  If there is one, the rhs of that mapping
  1055.         is returned.  If there are several matches, the rhs of one of
  1056.         them is returned.
  1057.         This function can be used to check if a mapping can be added
  1058.         without being ambiguous.  Example:
  1059. >    if mapcheck("_vv") == ""
  1060. >       map _vv :set guifont=7x13<CR>
  1061. >    endif
  1062.         The "_vv" mapping may conflict with a mapping for "_v" or for
  1063.         "_vvv".
  1064.  
  1065.                             *match()*
  1066. match({expr}, {pat})
  1067.         The result is a Number, which gives the index in {expr} where
  1068.         {pat} matches.  A match at the first character returns zero.
  1069.         If there is no match -1 is returned.  Example:
  1070. >            :echo match("testing", "ing")
  1071.         results in "4".
  1072.         See |pattern| for the patterns that are accepted.
  1073.         The 'ignorecase' option is used to set the ignore-caseness of
  1074.         the pattern.  'smartcase' is NOT used.  The matching is always
  1075.         done like 'magic' is set and 'cpoptions' is empty.
  1076.  
  1077.                             *matchend()*
  1078. matchend({expr}, {pat})
  1079.         Same as match(), but return the index of first character after
  1080.         the match.  Example:
  1081. >            :echo matchend("testing", "ing")
  1082.         results in "7".
  1083.  
  1084.                             *matchstr()*
  1085. matchstr({expr}, {pat})
  1086.         Same as match(), but return the matched string.  Example:
  1087. >            :echo matchstr("testing", "ing")
  1088.         results in "ing".
  1089.         When there is no match "" is returned.
  1090.  
  1091.                             *nr2char()*
  1092. nr2char({expr})
  1093.         Return a string with a single chararacter, which has the ASCII
  1094.         value {expr}.  Examples:
  1095. >            nr2char(64)        returns "@"
  1096. >            nr2char(32)        returns " "
  1097.  
  1098.                             *setline()*
  1099. setline({lnum}, {line})
  1100.         Set line {lnum} of the current buffer to {line}.  If this
  1101.         succeeds, 0 is returned.  If this fails (most likely because
  1102.         {lnum} is invalid) 1 is returned.  Example:
  1103. >            :call setline(5, strftime("%c"))
  1104.  
  1105.                             *strftime()*
  1106. strftime({format} [, {time}])
  1107.         The result is a String, which is a formatted date and time, as
  1108.         specified by the {format} string.  The given {time} is used,
  1109.         or the current time if no time is given.  The accepted
  1110.         {format} depends on your system, thus this is not portable!
  1111.         See the manual page of the C function strftime() for the
  1112.         format.  The maximum length of the result is 80 characters.
  1113.         See also |localtime()| and |getftime()|.  Examples:
  1114. >          :echo strftime("%c")           Sun Apr 27 11:49:23 1997
  1115. >          :echo strftime("%Y %b %d %X")       1997 Apr 27 11:53:25
  1116. >          :echo strftime("%y%m%d %T")       970427 11:53:55
  1117. >          :echo strftime("%H:%M")       11:55
  1118. >          :echo strftime("%c", getftime("file.c"))
  1119. >                           Show mod time of file.c.
  1120.  
  1121.                             *strlen()*
  1122. strlen({expr})    The result is a Number, which is the length of the String
  1123.         {expr}.
  1124.  
  1125.                             *strpart()*
  1126. strpart({src}, {start}, {len})
  1127.         The result is a String, which is part of {src},
  1128.         starting from character {start}, with the length {len}.
  1129.         When non-existing characters are included, this doesn't result
  1130.         in an error, the characters are simply omitted.
  1131. >            strpart("abcdefg", 3, 2)    == "de"
  1132. >            strpart("abcdefg", -2, 4)   == "ab"
  1133. >            strpart("abcdefg", 5, 4)    == "fg"
  1134.         Note: To get the first character, {start} must be 0.  For
  1135.         example, to get three characters under and after the cursor:
  1136. >            strpart(getline(line(".")), col(".") - 1, 3)
  1137.  
  1138.                             *strtrans()*
  1139. strtrans({expr})
  1140.         The result is a String, which is {expr} with all unprintable
  1141.         characters translated into printable characters |'isprint'|.
  1142.         Like they are shown in a window.  Example:
  1143. >            echo strtrans(@a)
  1144.         This displays a newline in register a as "^@" instead of
  1145.         starting a new line.
  1146.  
  1147.                             *substitute()*
  1148. substitute({expr}, {pat}, {sub}, {flags})
  1149.         The result is a String, which is a copy of {expr}, in which
  1150.         the first match of {pat} is replaced with {sub}.  This works
  1151.         like the ":substitute" command (without any flags).  But the
  1152.         matching with {pat} is always done like the 'magic' option is
  1153.         set and 'cpoptions' is empty (to make scripts portable).
  1154.         And a "~" in {sub} is not replaced with the previous {sub}.
  1155.         Note that some codes in {sub} have a special meaning
  1156.         |sub-replace-special|.  For example, to replace something with
  1157.         a literal "\n", use "\\\\n" or '\\n'.
  1158.         When {pat} does not match in {expr}, {expr} is returned
  1159.         unmodified.
  1160.         When {flags} is "g", all matches of {pat} in {expr} are
  1161.         replaced.  Otherwise {flags} should be "".
  1162.         Example:
  1163. >            :let &path = substitute(&path, ",\\=[^,]*$", "", "")
  1164.         This removes the last component of the 'path' option.
  1165. >            :echo substitute("testing", ".*", "\\U\\0", "")
  1166.         results in "TESTING".
  1167.  
  1168.                             *synID()*
  1169. synID({line}, {col}, {trans})
  1170.         The result is a Number, which is the syntax ID at the position
  1171.         {line} and {col} in the current window.
  1172.         The syntax ID can be used with |synIDattr()| and
  1173.         |synIDtrans()| to obtain syntax information about text.
  1174.         {col} is 1 for the leftmost column, {line} is 1 for the first
  1175.         line.
  1176.         When {trans} is non-zero, transparent items are reduced to the
  1177.         item that they reveal.  This is useful when wanting to know
  1178.         the effective color.  When {trans} is zero, the transparent
  1179.         item is returned.  This is useful when wanting to know which
  1180.         syntax item is effective (e.g. inside parens).
  1181.         Warning: This function can be very slow.  Best speed is
  1182.         obtained by going through the file in forward direction.
  1183.  
  1184.         Example (echos the name of the syntax item under the cursor):
  1185. >            :echo synIDattr(synID(line("."), col("."), 1), "name")
  1186.  
  1187.                             *synIDattr()*
  1188. synIDattr({synID}, {what} [, {mode}])
  1189.         The result is a String, which is the {what} attribute of
  1190.         syntax ID {synID}.  This can be used to obtain information
  1191.         about a syntax item.
  1192.         {mode} can be "gui", "cterm" or "term", to get the attributes
  1193.         for that mode.  When {mode} is omitted, or an invalid value is
  1194.         used, the attributes for the currently active highlighting are
  1195.         used (GUI, cterm or term).
  1196.         Use synIDtrans() to follow linked highlight groups.
  1197.         {what}        result
  1198.         "name"        the name of the syntax item
  1199.         "fg"        foreground color (GUI: color name, cterm:
  1200.                 color number as a string, term: empty string)
  1201.         "bg"        background color (like "fg")
  1202.         "fg#"        like "fg", but name in "#RRGGBB" form
  1203.         "bg#"        like "bg", but name in "#RRGGBB" form
  1204.         "bold"        "1" if bold
  1205.         "italic"    "1" if italic
  1206.         "reverse"    "1" if reverse
  1207.         "inverse"    "1" if inverse (= reverse)
  1208.         "underline"    "1" if underlined
  1209.  
  1210.         When the GUI is not running or the cterm mode is asked for,
  1211.         "fg#" is equal to "fg" and "bg#" is equal to "bg".
  1212.  
  1213.         Example (echos the color of the syntax item under the cursor):
  1214. >    :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
  1215.  
  1216.                             *synIDtrans()*
  1217. synIDtrans({synID})
  1218.         The result is a Number, which is the translated syntax ID of
  1219.         {synID}.  This is the syntax group ID of what is being used to
  1220.         highlight the character.  Highlight links are followed.
  1221.  
  1222.                             *system()*
  1223. system({expr})    Get the output of the shell command {expr}.  Note: newlines
  1224.         in {expr} may cause the command to fail.  This is not to be
  1225.         used for interactive commands.
  1226.         The result is a String.  To make the result more
  1227.         system-independent, the shell output is filtered to replace
  1228.         <CR> with <NL> for Macintosh, and <CR><NL> with <NL> for
  1229.         DOS-like systems.
  1230.         'shellredir' is used to capture the output of the command.
  1231.         Depending on 'shell', you might be able to capture stdout with
  1232.         ">" and stdout plus stderr with ">&" (csh) or use "2>" to
  1233.         capture stderr (sh).
  1234.  
  1235.                         *tempname()* *temp-file-name*
  1236. tempname()
  1237.         The result is a String, which is the name of a file that
  1238.         doesn't exist.  It can be used for a temporary file.  The name
  1239.         is different for at least 26 consecutive calls.  Example:
  1240. >            let tmpfile = tempname()
  1241. >            exe "redir > " . tmpfile
  1242.  
  1243.                             *visualmode()*
  1244. visualmode()
  1245.         The result is a String, which describes the last Visual mode
  1246.         used.  Initially it returns an empty string, but once Visual
  1247.         mode has been used, it returns "v", "V", or "<CTRL-V>" (a
  1248.         single CTRL-V character) for character-wise, line-wise, or
  1249.         block-wise Visual mode respecively.
  1250.         Example:
  1251. >            exe "normal " . visualmode()
  1252.         This enters the same Visual mode as before.  It is also useful
  1253.         in scripts if you wish to act differently depending on the
  1254.         Visual mode that was used.
  1255.  
  1256.                             *virtcol()*
  1257. virtcol({expr})
  1258.         The result is a Number, which is the screen column of the file
  1259.         position given with {expr}.  That is, the last screen position
  1260.         occupied by the character at that position, when the screen
  1261.         would be of unlimited width.  When there is a <Tab> at the
  1262.         position, the returned Number will be the column at the end of
  1263.         the <Tab>.  For example, for a <Tab> in column 1, with 'ts'
  1264.         set to 8, it returns 8;
  1265.         The accepted positions are:
  1266.             .        the cursor position
  1267.             'x        position of mark x (if the mark is not set, 0 is
  1268.                 returned)
  1269.         Note that only marks in the current file can be used.
  1270.         Examples:
  1271. >  virtcol(".")        with text "foo^Lbar", with cursor on the "^L", returns 5
  1272. >  virtcol("'t")    with text "    there", with 't at 'h', returns 6
  1273.         The first column is 1.  0 is returned for an error.
  1274.  
  1275.                             *winbufnr()*
  1276. winbufnr({nr})    The result is a Number, which is the number of the buffer
  1277.         associated with window {nr}. When {nr} is zero, the number of
  1278.         the buffer in the current window is returned.  When window
  1279.         {nr} doesn't exist, -1 is returned.
  1280.         Example:
  1281. >  echo "The file in the current window is " . bufname(winbufnr(0))
  1282.  
  1283.                             *winheight()*
  1284. winheight({nr})
  1285.         The result is a Number, which is the height of window {nr}.
  1286.         When {nr} is zero, the height of the current window is
  1287.         returned.  When window {nr} doesn't exist, -1 is returned.
  1288.         An existing window always has a height of zero or more.
  1289.         Examples:
  1290. >  echo "The current window has " . winheight(0) . " lines."
  1291.  
  1292.                             *winnr()*
  1293. winnr()        The result is a Number, which is the number of the current
  1294.         window.  The top window has number 1.
  1295.  
  1296.                             *feature-list*
  1297. There are two types of features:
  1298. 1.  Features that are only supported when they have been enabled when Vim
  1299.     was compiled |+feature-list|.  Example:
  1300. >        :if has("cindent")
  1301. 2.  Features that are only supported when certain conditions have been met.
  1302.     Example:
  1303. >        :if has("gui_running")
  1304.  
  1305. all_builtin_terms    Compiled with all builtin terminals enabled.
  1306. amiga            Amiga version of Vim.
  1307. arp            Compiled with ARP support (Amiga).
  1308. autocmd            Compiled with autocommands support.
  1309. beos            BeOS version of Vim.
  1310. browse            Compiled with |:browse| support, and browse() will
  1311.             work.
  1312. builtin_terms        Compiled with some builtin terminals.
  1313. byte_offset        Compiled with support for 'o' in 'statusline'
  1314. cindent            Compiled with 'cindent' support.
  1315. clipboard        Compiled with 'clipboard' support.
  1316. cmdline_compl        Compiled with |cmdline-completion| support.
  1317. cmdline_info        Compiled with 'showcmd' and 'ruler' support.
  1318. comments        Compiled with |'comments'| support.
  1319. cryptv            Compiled with encryption support |encryption|.
  1320. cscope            Compiled with |cscope| support.
  1321. compatible        Compiled to be very Vi compatible.
  1322. debug            Compiled with "DEBUG" defined.
  1323. dialog_con        Compiled with console dialog support.
  1324. dialog_gui        Compiled with GUI dialog support.
  1325. digraphs        Compiled with support for digraphs.
  1326. dos32            32 bits DOS (DJGPP) version of Vim.
  1327. dos16            16 bits DOS version of Vim.
  1328. emacs_tags        Compiled with support for Emacs tags.
  1329. eval            Compiled with expression evaluation support.  Always
  1330.             true, of course!
  1331. ex_extra        Compiled with extra Ex commands |+ex_extra|.
  1332. extra_search        Compiled with support for |'incsearch'| and
  1333.             |'hlsearch'|
  1334. farsi            Compiled with Farsi support |farsi|.
  1335. file_in_path        Compiled with support for |gf| and |<cfile>|
  1336. find_in_path        Compiled with support for include file searches
  1337.             |+find_in_path|.
  1338. fname_case        Case in file names matters (for Amiga, MS-DOS, and
  1339.             Windows this is not present).
  1340. fork            Compiled to use fork()/exec() instead of system().
  1341. gui            Compiled with GUI enabled.
  1342. gui_athena        Compiled with Athena GUI.
  1343. gui_beos        Compiled with BeOs GUI.
  1344. gui_gtk            Compiled with GTK+ GUI.
  1345. gui_mac            Compiled with Macintosh GUI.
  1346. gui_motif        Compiled with Motif GUI.
  1347. gui_win32        Compiled with MS Windows Win32 GUI.
  1348. gui_win32s        idem, and Win32s system being used (Windows 3.1)
  1349. gui_running        Vim is running in the GUI, or it will start soon.
  1350. hangul_input        Compiled with Hangul input support. |hangul|
  1351. insert_expand        Compiled with support for CTRL-X expansion commands in
  1352.             Insert mode.
  1353. langmap            Compiled with 'langmap' support.
  1354. linebreak        Compiled with 'linebreak', 'breakat' and 'showbreak'
  1355.             support.
  1356. lispindent        Compiled with support for lisp indenting.
  1357. mac            Macintosh version of Vim.
  1358. menu            Compiled with support for |:menu|.
  1359. mksession        Compiled with support for |:mksession|.
  1360. modify_fname        Compiled with file name modifiers. |filename-modifiers|
  1361. mouse            Compiled with support mouse.
  1362. mouse_dec        Compiled with support for Dec terminal mouse.
  1363. mouse_gpm        Compiled with support for gpm (Linux console mouse)
  1364. mouse_netterm        Compiled with support for netterm mouse.
  1365. mouse_xterm        Compiled with support for xterm mouse.
  1366. multi_byte        Compiled with support for Korean et al.
  1367. multi_byte_ime        Compiled with support for IME input method
  1368. ole            Compiled with OLE automation support for Win32.
  1369. os2            OS/2 version of Vim.
  1370. osfiletype        Compiled with support for osfiletypes |+osfiletype|
  1371. perl            Compiled with Perl interface.
  1372. python            Compiled with Python interface.
  1373. quickfix        Compiled with |quickfix| support.
  1374. rightleft        Compiled with 'rightleft' support.
  1375. scrollbind        Compiled with 'scrollbind' support.
  1376. showcmd            Compiled with 'showcmd' support.
  1377. smartindent        Compiled with 'smartindent' support.
  1378. sniff            Compiled with SniFF interface support.
  1379. statusline        Compiled with support for 'statusline', 'rulerformat'
  1380.             and special formats of 'titlestring' and 'iconstring'.
  1381. syntax            Compiled with syntax highlighting support.
  1382. syntax_items        There are active syntax highlighting items for the
  1383.             current buffer.
  1384. system            Compiled to use system() instead of fork()/exec().
  1385. tag_binary        Compiled with binary searching in tags files
  1386.             |tag-binary-search|.
  1387. tag_old_static        Compiled with support for old static tags
  1388.             |tag-old-static|.
  1389. tag_any_white        Compiled with support for any white characters in tags
  1390.             files |tag-any-white|.
  1391. tcl            Compiled with Tcl interface.
  1392. terminfo        Compiled with terminfo instead of termcap.
  1393. textobjects        Compiled with support for |text-objects|.
  1394. tgetent            Compiled with tgetent support, able to use a termcap
  1395.             or terminfo file.
  1396. title            Compiled with window title support |'title'|.
  1397. unix            Unix version of Vim.
  1398. user_commands        User-defined commands.
  1399. viminfo            Compiled with viminfo support.
  1400. vim_starting            True while initial source'ing takes place.
  1401. visualextra        Compiled with extra Visual mode commands
  1402.             |blockwise-operators|.
  1403. vms            VMS version of Vim.
  1404. wildmenu        Compiled with 'wildmenu' option.
  1405. wildignore        Compiled with 'wildignore' option.
  1406. winaltkeys        Compiled with 'winaltkeys' option.
  1407. win32            Win32 version of Vim (Windows 95/NT).
  1408. writebackup        Compiled with 'writebackup' default on.
  1409. xim            Compiled with X input method support |xim|.
  1410. xfontset        Compiled with X fontset support |xfontset|.
  1411. xterm_clipboard        Compiled with support for xterm clipboard.
  1412. xterm_save        Compiled with support for saving and restoring the
  1413.             xterm screen.
  1414. x11            Compiled with X11 support.
  1415.  
  1416. ==============================================================================
  1417. 5. Defining functions                    *user-functions*
  1418.  
  1419. New functions can be defined.  These can be called with "Name()", just like
  1420. builtin functions.  The name must start with an uppercase letter, to avoid
  1421. confusion with builtin functions.
  1422.  
  1423.                             *:fu* *:function*
  1424. :fu[nction]        List all functions and their arguments.
  1425.  
  1426. :fu[nction] {name}    List function {name}.
  1427.  
  1428. :fu[nction][!] {name}([arguments]) [range] [abort]
  1429.             Define a new function by the name {name}.  The name
  1430.             must be made of alphanumeric characters and '_', and
  1431.             must start with a capital.
  1432.             An argument can be defined by giving its name.  In the
  1433.             function this can then be used as "a:name" ("a:" for
  1434.             argument).
  1435.             Several arguments can be given, separated by commas.
  1436.             Finally, an argument "..." can be specified, which
  1437.             means that more arguments may be following.  In the
  1438.             function they can be used as "a:1", "a:2", etc.  "a:0"
  1439.             is set to the number of extra arguments (which can be
  1440.             0).
  1441.             When not using "...", the number of arguments in a
  1442.             function call must be equal the number of named
  1443.             arguments.  When using "...", the number of arguments
  1444.             may be larger.
  1445.             It is also possible to define a function without any
  1446.             arguments.  You must still supply the () then.
  1447.             The body of the function follows in the next lines,
  1448.             until ":endfunction".
  1449.             When a function by this name already exists and [!] is
  1450.             not used an error message is given.  When [!] is used,
  1451.             an existing function is silently replaced.
  1452.             When the [range] argument is added, the function is
  1453.             expected to take care of a range itself.  The range is
  1454.             passed as "a:firstline" and "a:lastline".  If [range]
  1455.             is excluded, a ":call" with a range will call the
  1456.             function for each line, with the cursor on the start
  1457.             of each line.
  1458.             When the [abort] argument is added, the function will
  1459.             abort as soon as an error is detected.
  1460.             The last used search pattern and the redo command "."
  1461.             will not be changed by the function.
  1462.  
  1463.                             *:endf* *:endfunction*
  1464. :endf[unction]        The end of a function definition.
  1465.  
  1466.                             *:delf* *:delfunction*
  1467. :delf[unction] {name}    Delete function {name}.
  1468.  
  1469.                             *:retu* *:return*
  1470. :retu[rn] [expr]    Return from a function.  When "[expr]" is given, it is
  1471.             evaluated and returned as the result of the function.
  1472.             If "[expr]" is not given, the number 0 is returned.
  1473.             When a function ends without an explicit ":return",
  1474.             the number 0 is returned.
  1475.             Note that there is no check for unreachable lines,
  1476.             thus there is no warning if commands follow ":return".
  1477.  
  1478. Inside a function variables can be used.  These are local variables, which
  1479. will disappear when the function returns.  Global variables need to be
  1480. accessed with "g:".
  1481.  
  1482. Example:
  1483. >  :function Table(title, ...)
  1484. >  :  echohl Title
  1485. >  :  echo a:title
  1486. >  :  echohl None
  1487. >  :  let idx = 1
  1488. >  :  while idx <= a:0
  1489. >  :    exe "echo a:" . idx
  1490. >  :    let idx = idx + 1
  1491. >  :  endwhile
  1492. >  :  return idx
  1493. >  :endfunction
  1494.  
  1495. This function can then be called with:
  1496. >  let lines = Table("Table", "line1", "line2")
  1497. >  let lines = Table("Empty Table")
  1498.  
  1499. To return more than one value, pass the name of a global variable:
  1500. >  :function Compute(n1, n2, divname)
  1501. >  :  if a:n2 == 0
  1502. >  :    return "fail"
  1503. >  :  endif
  1504. >  :  exe "let " . a:divname . " = ". a:n1 / a:n2
  1505. >  :  return "ok"
  1506. >  :endfunction
  1507.  
  1508. This function can then be called with:
  1509. >  :let success = Compute(13, 1324, "div")
  1510. >  :if success == "ok"
  1511. >  :  echo div
  1512. >  :endif
  1513.  
  1514.                             *:cal* *:call*
  1515. :[range]cal[l] {name}([arguments])
  1516.         Call a function.  The name of the function and its arguments
  1517.         are as before.
  1518.         Without a range and for functions that accept a range, the
  1519.         function is called once, with the cursor at the current
  1520.         position.
  1521.         When a range is given and the function doesn't handle it
  1522.         itself, the function is executed for each line in the range,
  1523.         with the cursor in the first column of that line.  The cursor
  1524.         is left at the last line (possibly moved by the last function
  1525.         call).  The arguments are re-evaluated for each line.  Thus
  1526.         this works:
  1527.  
  1528. >    :function Mynumber(arg)
  1529. >    :  echo line(".") . " " . a:arg
  1530. >    :endfunction
  1531. >    :1,5call Mynumber(getline("."))
  1532.  
  1533. The recursiveness of user functions is restricted with the |'maxfuncdepth'|
  1534. option.
  1535.  
  1536. ==============================================================================
  1537. 6. Commands                        *expression-commands*
  1538.  
  1539. :let {var-name} = {expr1}                *:let*
  1540.             Set internal variable {var-name} to the result of the
  1541.             expression {expr1}.  The variable will get the type
  1542.             from the {expr}.  if {var-name} didn't exist yet, it
  1543.             is created.
  1544.  
  1545. :let ${env-name} = {expr1}            *:let-environment* *:let-$*
  1546.             Set environment variable {env-name} to the result of
  1547.             the expression {expr1}.  The type is always String.
  1548.  
  1549. :let @{reg-name} = {expr1}            *:let-register* *:let-@*
  1550.             Write the result of the expression {expr1} in register
  1551.             {reg-name}.  {reg-name} must be a single letter, and
  1552.             must be the name of a writable register (see
  1553.             |registers|).  "@@" can be used for the unnamed
  1554.             register, "@/" for the search pattern.
  1555.             If the result of {expr1} ends in a <CR> or <NL>, the
  1556.             register will be linewise, otherwise it will be set to
  1557.             characterwise.
  1558.  
  1559. :let &{option-name} = {expr1}            *:let-option* *:let-star*
  1560.             Set option {option-name} to the result of the
  1561.             expression {expr1}.  The type of the option is always
  1562.             used.
  1563.  
  1564.                             *:unlet* *:unl*
  1565. :unl[et][!] {var-name} ...
  1566.             Remove the internal variable {var-name}.  Several
  1567.             variable names can be given, they are all removed.
  1568.             With [!] no error message is given for non-existing
  1569.             variables.
  1570.  
  1571. :if {expr1}                        *:if* *:endif* *:en*
  1572. :en[dif]        Execute the commands until the next matching ":else"
  1573.             or ":endif" if {expr1} evaluates to non-zero.
  1574.  
  1575.             From Vim version 4.5 until 5.0, every Ex command in
  1576.             between the ":if" and ":endif" is ignored.  These two
  1577.             commands were just to allow for future expansions in a
  1578.             backwards compatible way.  Nesting was allowed.  Note
  1579.             that any ":else" or ":elseif" was ignored, the "else"
  1580.             part was not executed either.
  1581.  
  1582.             You can use this to remain compatible with older
  1583.             versions:
  1584. >                :if version >= 500
  1585. >                :  version-5-specific-commands
  1586. >                :endif
  1587.  
  1588.                             *:else* *:el*
  1589. :el[se]            Execute the commands until the next matching ":else"
  1590.             or ":endif" if they previously were not being
  1591.             executed.
  1592.  
  1593.                             *:elseif* *:elsei*
  1594. :elsei[f] {expr1}    Short for ":else" ":if", with the addition that there
  1595.             is no extra ":endif".
  1596.  
  1597. :wh[ile] {expr1}            *:while* *:endwhile* *:wh* *:endw*
  1598. :endw[hile]        Repeat the commands between ":while" and ":endwhile",
  1599.             as long as {expr1} evaluates to non-zero.
  1600.             When an error is detected from a command inside the
  1601.             loop, execution continues after the "endwhile".
  1602.  
  1603.         NOTE: The ":append" and ":insert" commands don't work properly
  1604.         inside a ":while" loop.
  1605.  
  1606.                             *:continue* *:con*
  1607. :con[tinue]        When used inside a ":while", jumps back to the
  1608.             ":while".
  1609.  
  1610.                             *:break* *:brea*
  1611. :brea[k]        When used inside a ":while", skips to the command
  1612.             after the matching ":endwhile".
  1613.  
  1614.                             *:ec* *:echo*
  1615. :ec[ho] {expr1} ..    Echoes each {expr1}, with a space in between and a
  1616.             terminating <EOL>.  Also see |:comment|.
  1617.             Use "\n" to start a new line.  Use "\r" to move the
  1618.             cursor to the first column.
  1619.             Cannot be followed by a comment.
  1620.             Example:
  1621. >        :echo "the value of 'shell' is" &shell
  1622.  
  1623.                             *:echon*
  1624. :echon {expr1} ..    Echoes each {expr1}, without anything added.  Also see
  1625.             |:comment|.
  1626.             Cannot be followed by a comment.
  1627.             Example:
  1628. >        :echon "the value of 'shell' is " &shell
  1629.  
  1630.             Note the difference between using ":echo", which is a
  1631.             Vim command, and ":!echo", which is an external shell
  1632.             command:
  1633. >        :!echo %        --> filename
  1634.             The arguments of ":!" are expanded, see |:_%|.
  1635. >        :!echo "%"        --> filename or "filename"
  1636.             Like the previous example.  Whether you see the double
  1637.             quotes or not depends on your 'shell'.
  1638. >        :echo %            --> nothing
  1639.             The '%' is an illegal character in an expression.
  1640. >        :echo "%"        --> %
  1641.             This just echoes the '%' character.
  1642. >        :echo expand("%")    --> filename
  1643.             This calls the expand() function to expand the '%'.
  1644.  
  1645.                             *:echoh* *:echohl*
  1646. :echoh[l] {name}    Use the highlight group {name} for the following
  1647.             ":echo[n]" commands.  Example:
  1648. >        :echohl WarningMsg | echo "Don't panic!" | echohl None
  1649.             Don't forget to set the group back to "None",
  1650.             otherwise all following echo's will be highlighted.
  1651.  
  1652.                             *:exe* *:execute*
  1653. :exe[cute] {expr1} ..    Executes the string that results from the evaluation
  1654.             of {expr1} as an Ex command.  Multiple arguments are
  1655.             concatenated, with a space in between.
  1656.             Cannot be followed by a comment.
  1657.             Examples:
  1658. >        :execute "buffer " nextbuf
  1659. >        :execute "normal " count . "w"
  1660.  
  1661.             Execute can be used to append a next command to
  1662.             commands that don't accept a '|'.  Example:
  1663. >        :execute '!ls' | echo "theend"
  1664.  
  1665.             Note: The executed string may be any command-line, but
  1666.             you cannot start or end a "while" or "if" command.
  1667.             Thus this is illegal:
  1668. >        :execute 'while i > 5'
  1669. >        :execute 'echo "test" | break'
  1670.  
  1671.             It is allowed to have a "while" or "if" command
  1672.             completely in the executed string:
  1673. >        :execute 'while i < 5 | echo i | let i = i + 1 | endwhile'
  1674.  
  1675.  
  1676.                             *:comment*
  1677.             ":execute", ":echo" and ":echon" cannot be followed by
  1678.             a comment directly, because they see the '"' as the
  1679.             start of a string.  But, you can use '|' followed by a
  1680.             comment.  Example:
  1681. >        :echo "foo" | "this is a comment
  1682.  
  1683. ==============================================================================
  1684. 7. Examples                        *eval-examples*
  1685.  
  1686. Printing in Hex ~
  1687.  
  1688. >  " The function Nr2Hex() returns the Hex string of a number.
  1689. >  func Nr2Hex(nr)
  1690. >    let n = a:nr
  1691. >    let r = ""
  1692. >    while n
  1693. >      let r = '0123456789ABCDEF'[n % 16] . r
  1694. >      let n = n / 16
  1695. >    endwhile
  1696. >    return r
  1697. >  endfunc
  1698. >
  1699. >  " The function String2Hex() converts each character in a string to a two
  1700. >  " character Hex string.
  1701. >  func String2Hex(str)
  1702. >    let out = ''
  1703. >    let ix = 0
  1704. >    while ix < strlen(a:str)
  1705. >      let out = out . Nr2Hex(char2nr(a:str[ix]))
  1706. >      let ix = ix + 1
  1707. >    endwhile
  1708. >    return out
  1709. >  endfunc
  1710.  
  1711. Example of its use:
  1712. >  echo Nr2Hex(32)
  1713. result: "20"
  1714. >  echo String2Hex("32")
  1715. result: "3332"
  1716.  
  1717.  
  1718. Sorting lines (by Robert Webb) ~
  1719.  
  1720. Here is a vim script to sort lines.  Highlight the lines in vim and type
  1721. ":Sort".  This doesn't call any external programs so it'll work on any
  1722. platform.  The function Sort() actually takes the name of a comparison
  1723. function as its argument, like qsort() does in C.  So you could supply it
  1724. with different comparison functions in order to sort according to date etc.
  1725.  
  1726. > " Function for use with Sort(), to compare two strings.
  1727. > func! Strcmp(str1, str2)
  1728. >     if (a:str1 < a:str2)
  1729. >    return -1
  1730. >     elseif (a:str1 > a:str2)
  1731. >    return 1
  1732. >     else
  1733. >    return 0
  1734. >     endif
  1735. > endfunction
  1736. >
  1737. > " Sort lines.  SortR() is called recursively.
  1738. > func! SortR(start, end, cmp)
  1739. >     if (a:start >= a:end)
  1740. >    return
  1741. >     endif
  1742. >     let partition = a:start - 1
  1743. >     let middle = partition
  1744. >     let partStr = getline((a:start + a:end) / 2)
  1745. >     let i = a:start
  1746. >     while (i <= a:end)
  1747. >    let str = getline(i)
  1748. >    exec "let result = " . a:cmp . "(str, partStr)"
  1749. >    if (result <= 0)
  1750. >        " Need to put it before the partition.  Swap lines i and partition.
  1751. >        let partition = partition + 1
  1752. >        if (result == 0)
  1753. >        let middle = partition
  1754. >        endif
  1755. >        if (i != partition)
  1756. >        let str2 = getline(partition)
  1757. >        call setline(i, str2)
  1758. >        call setline(partition, str)
  1759. >        endif
  1760. >    endif
  1761. >    let i = i + 1
  1762. >     endwhile
  1763. >
  1764. >     " Now we have a pointer to the "middle" element, as far as partitioning
  1765. >     " goes, which could be anywhere before the partition.  Make sure it is at
  1766. >     " the end of the partition.
  1767. >     if (middle != partition)
  1768. >    let str = getline(middle)
  1769. >    let str2 = getline(partition)
  1770. >    call setline(middle, str2)
  1771. >    call setline(partition, str)
  1772. >     endif
  1773. >     call SortR(a:start, partition - 1, a:cmp)
  1774. >     call SortR(partition + 1, a:end, a:cmp)
  1775. > endfunc
  1776. >
  1777. > " To Sort a range of lines, pass the range to Sort() along with the name of a
  1778. > " function that will compare two lines.
  1779. > func! Sort(cmp) range
  1780. >     call SortR(a:firstline, a:lastline, a:cmp)
  1781. > endfunc
  1782. >
  1783. > " :Sort takes a range of lines and sorts them.
  1784. > command! -nargs=0 -range Sort <line1>,<line2>call Sort("Strcmp")
  1785.  
  1786. ==============================================================================
  1787. 8. No +eval feature                *no-eval-feature*
  1788.  
  1789. When the |+eval| feature was disabled at compile time, all the expression
  1790. evaluation commands are not available.  To avoid that a Vim script generates
  1791. all kinds of errors, the ":if" and ":endif" commands are recognized.
  1792. Everything between the ":if" and the matching ":endif" is ignored.  It does
  1793. not matter what argument is used after the ":if".  Nesting of these commands
  1794. is recognized, but only if the commands are at the start of the line.  The
  1795. ":else" command is not recognized.
  1796.  
  1797. Example of how to avoid commands to be executed when the |+eval| feature is
  1798. missing:
  1799. >    if 1
  1800. >      echo "Expression evaluation is compiled in"
  1801. >    endif
  1802.  
  1803.  vim:tw=78:ts=8:sw=8:
  1804.