Mercurial > vim
comparison runtime/doc/change.txt @ 13912:a9fdf01085a8
Update runtime files.
commit https://github.com/vim/vim/commit/7db25fed5de1be922b8cbb0328149469606a0424
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 13 00:02:36 2018 +0200
Update runtime files.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 13 May 2018 00:15:05 +0200 |
parents | e751b5c9dff3 |
children | 1174611ad715 |
comparison
equal
deleted
inserted
replaced
13911:c02f0e120b11 | 13912:a9fdf01085a8 |
---|---|
1 *change.txt* For Vim version 8.0. Last change: 2018 May 06 | 1 *change.txt* For Vim version 8.0. Last change: 2018 May 12 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
1442 | 1442 |
1443 You can set the 'formatexpr' option to an expression or the 'formatprg' option | 1443 You can set the 'formatexpr' option to an expression or the 'formatprg' option |
1444 to the name of an external program for Vim to use for text formatting. The | 1444 to the name of an external program for Vim to use for text formatting. The |
1445 'textwidth' and other options have no effect on formatting by an external | 1445 'textwidth' and other options have no effect on formatting by an external |
1446 program. | 1446 program. |
1447 | |
1448 *format-formatexpr* | |
1449 The 'formatexpr' option can be set to a Vim Script function that performs | |
1450 reformatting of the buffer. This should usually happen in an |ftplugin|, | |
1451 since formatting is highly dependent on the type of file. It makes | |
1452 sense to use an |autoload| script, so the corresponding script is only loaded | |
1453 when actually needed and the script should be called <filetype>format.vim. | |
1454 | |
1455 For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME | |
1456 directory, sets the 'formatexpr' option to: > | |
1457 | |
1458 setlocal formatexpr=xmlformat#Format() | |
1459 | |
1460 That means, you will find the corresponding script, defining the | |
1461 xmlformat#Format() function, in the directory: | |
1462 `$VIMRUNTIME/autoload/xmlformat.vim` | |
1463 | |
1464 Here is an example script that removes trailing whitespace from the selected | |
1465 text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: > | |
1466 | |
1467 func! format#Format() | |
1468 " only reformat on explicit gq command | |
1469 if mode() != 'n' | |
1470 " fall back to Vims internal reformatting | |
1471 return 1 | |
1472 endif | |
1473 let lines = getline(v:lnum, v:lnum + v:count - 1) | |
1474 call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')}) | |
1475 call setline('.', lines) | |
1476 | |
1477 " do not run internal formatter! | |
1478 return 0 | |
1479 endfunc | |
1480 | |
1481 You can then enable the formatting by executing: > | |
1482 setlocal formatexpr=format#Format() | |
1483 > | |
1484 Note: this function explicitly returns non-zero when called from insert mode | |
1485 (which basically means, text is inserted beyond the 'textwidth' limit). This | |
1486 causes Vim to fall back to reformat the text by using the internal formatter. | |
1487 | |
1488 However, if the |gq| command is used to reformat the text, the function | |
1489 will receive the selected lines, trim trailing whitespace from those lines and | |
1490 put them back in place. If you are going to split single lines into multiple | |
1491 lines, be careful not to overwrite anything. | |
1492 | |
1493 If you want to allow reformatting of text from insert or replace mode, one has | |
1494 to be very careful, because the function might be called recursively. For | |
1495 debugging it helps to set the 'debug' option. | |
1447 | 1496 |
1448 *right-justify* | 1497 *right-justify* |
1449 There is no command in Vim to right justify text. You can do it with | 1498 There is no command in Vim to right justify text. You can do it with |
1450 an external command, like "par" (e.g.: "!}par" to format until the end of the | 1499 an external command, like "par" (e.g.: "!}par" to format until the end of the |
1451 paragraph) or set 'formatprg' to "par". | 1500 paragraph) or set 'formatprg' to "par". |