|
1 |
| -*change.txt* For Vim version 8.0. Last change: 2017 Feb 12 |
| 1 | +*change.txt* For Vim version 8.1. Last change: 2018 May 12 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar
|
@@ -110,7 +110,7 @@ is an error when 'cpoptions' includes the 'E' flag.
|
110 | 110 | J Join [count] lines, with a minimum of two lines.
|
111 | 111 | Remove the indent and insert up to two spaces (see
|
112 | 112 | below). Fails when on the last line of the buffer.
|
113 |
| - If [count] is too big it is reduce to the number of |
| 113 | + If [count] is too big it is reduced to the number of |
114 | 114 | lines available.
|
115 | 115 |
|
116 | 116 | *v_J*
|
@@ -446,7 +446,7 @@ This depends on the 'nrformats' option:
|
446 | 446 |
|
447 | 447 | For decimals a leading negative sign is considered for incrementing/
|
448 | 448 | decrementing, for binary, octal and hex values, it won't be considered. To
|
449 |
| -ignore the sign Visually select the number before using CTRL-A or CTRL-X. |
| 449 | +ignore the sign Visually select the number before using CTRL-A or CTRL-X. |
450 | 450 |
|
451 | 451 | For numbers with leading zeros (including all octal and hexadecimal numbers),
|
452 | 452 | Vim preserves the number of characters in the number when possible. CTRL-A on
|
@@ -533,6 +533,7 @@ If the 'shiftround' option is on, the indent is rounded to a multiple of
|
533 | 533 | If the 'smartindent' option is on, or 'cindent' is on and 'cinkeys' contains
|
534 | 534 | '#' with a zero value, shift right does not affect lines starting with '#'
|
535 | 535 | (these are supposed to be C preprocessor lines that must stay in column 1).
|
| 536 | +This can be changed with the 'cino' option, see |cino-#|. |
536 | 537 |
|
537 | 538 | When the 'expandtab' option is off (this is the default) Vim uses <Tab>s as
|
538 | 539 | much as possible to make the indent. You can use ">><<" to replace an indent
|
@@ -986,6 +987,11 @@ This replaces each 'E' character with a euro sign. Read more in |<Char->|.
|
986 | 987 | this (that's a good habit anyway).
|
987 | 988 | `:retab!` may also change a sequence of spaces by
|
988 | 989 | <Tab> characters, which can mess up a printf().
|
| 990 | + If the |+vartabs| feature is enabled then a list of |
| 991 | + tab widths separated by commas may be used in place of |
| 992 | + a single tabstop. Each value in the list represents |
| 993 | + the width of one tabstop, except the final value which |
| 994 | + applies to all following tabstops. |
989 | 995 | {not in Vi}
|
990 | 996 |
|
991 | 997 | *retab-example*
|
@@ -1444,6 +1450,55 @@ to the name of an external program for Vim to use for text formatting. The
|
1444 | 1450 | 'textwidth' and other options have no effect on formatting by an external
|
1445 | 1451 | program.
|
1446 | 1452 |
|
| 1453 | + *format-formatexpr* |
| 1454 | +The 'formatexpr' option can be set to a Vim Script function that performs |
| 1455 | +reformatting of the buffer. This should usually happen in an |ftplugin|, |
| 1456 | +since formatting is highly dependent on the type of file. It makes |
| 1457 | +sense to use an |autoload| script, so the corresponding script is only loaded |
| 1458 | +when actually needed and the script should be called <filetype>format.vim. |
| 1459 | + |
| 1460 | +For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME |
| 1461 | +directory, sets the 'formatexpr' option to: > |
| 1462 | +
|
| 1463 | + setlocal formatexpr=xmlformat#Format() |
| 1464 | +
|
| 1465 | +That means, you will find the corresponding script, defining the |
| 1466 | +xmlformat#Format() function, in the directory: |
| 1467 | +`$VIMRUNTIME/autoload/xmlformat.vim` |
| 1468 | + |
| 1469 | +Here is an example script that removes trailing whitespace from the selected |
| 1470 | +text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: > |
| 1471 | +
|
| 1472 | + func! format#Format() |
| 1473 | + " only reformat on explicit gq command |
| 1474 | + if mode() != 'n' |
| 1475 | + " fall back to Vims internal reformatting |
| 1476 | + return 1 |
| 1477 | + endif |
| 1478 | + let lines = getline(v:lnum, v:lnum + v:count - 1) |
| 1479 | + call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')}) |
| 1480 | + call setline('.', lines) |
| 1481 | +
|
| 1482 | + " do not run internal formatter! |
| 1483 | + return 0 |
| 1484 | + endfunc |
| 1485 | +
|
| 1486 | +You can then enable the formatting by executing: > |
| 1487 | + setlocal formatexpr=format#Format() |
| 1488 | +> |
| 1489 | +Note: this function explicitly returns non-zero when called from insert mode |
| 1490 | +(which basically means, text is inserted beyond the 'textwidth' limit). This |
| 1491 | +causes Vim to fall back to reformat the text by using the internal formatter. |
| 1492 | + |
| 1493 | +However, if the |gq| command is used to reformat the text, the function |
| 1494 | +will receive the selected lines, trim trailing whitespace from those lines and |
| 1495 | +put them back in place. If you are going to split single lines into multiple |
| 1496 | +lines, be careful not to overwrite anything. |
| 1497 | + |
| 1498 | +If you want to allow reformatting of text from insert or replace mode, one has |
| 1499 | +to be very careful, because the function might be called recursively. For |
| 1500 | +debugging it helps to set the 'debug' option. |
| 1501 | + |
1447 | 1502 | *right-justify*
|
1448 | 1503 | There is no command in Vim to right justify text. You can do it with
|
1449 | 1504 | an external command, like "par" (e.g.: "!}par" to format until the end of the
|
|
0 commit comments