diff options
Diffstat (limited to 'runtime/doc')
-rw-r--r-- | runtime/doc/change.txt | 49 | ||||
-rw-r--r-- | runtime/doc/cmdline.txt | 5 |
2 files changed, 53 insertions, 1 deletions
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index 1846b562aa..67f8aa47dd 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -1372,6 +1372,55 @@ to the name of an external program for Vim to use for text formatting. The 'textwidth' and other options have no effect on formatting by an external program. + *format-formatexpr* +The 'formatexpr' option can be set to a Vim Script function that performs +reformatting of the buffer. This should usually happen in an |ftplugin|, +since formatting is highly dependent on the type of file. It makes +sense to use an |autoload| script, so the corresponding script is only loaded +when actually needed and the script should be called <filetype>format.vim. + +For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME +directory, sets the 'formatexpr' option to: > + + setlocal formatexpr=xmlformat#Format() + +That means, you will find the corresponding script, defining the +xmlformat#Format() function, in the directory: +`$VIMRUNTIME/autoload/xmlformat.vim` + +Here is an example script that removes trailing whitespace from the selected +text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: > + + func! format#Format() + " only reformat on explicit gq command + if mode() != 'n' + " fall back to Vims internal reformatting + return 1 + endif + let lines = getline(v:lnum, v:lnum + v:count - 1) + call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')}) + call setline('.', lines) + + " do not run internal formatter! + return 0 + endfunc + +You can then enable the formatting by executing: > + setlocal formatexpr=format#Format() +> +Note: this function explicitly returns non-zero when called from insert mode +(which basically means, text is inserted beyond the 'textwidth' limit). This +causes Vim to fall back to reformat the text by using the internal formatter. + +However, if the |gq| command is used to reformat the text, the function +will receive the selected lines, trim trailing whitespace from those lines and +put them back in place. If you are going to split single lines into multiple +lines, be careful not to overwrite anything. + +If you want to allow reformatting of text from insert or replace mode, one has +to be very careful, because the function might be called recursively. For +debugging it helps to set the 'debug' option. + *right-justify* There is no command in Vim to right justify text. You can do it with an external command, like "par" (e.g.: "!}par" to format until the end of the diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt index e72799c65b..48229d8991 100644 --- a/runtime/doc/cmdline.txt +++ b/runtime/doc/cmdline.txt @@ -378,10 +378,13 @@ CTRL-D List names that match the pattern in front of the cursor. match is inserted. After the last match, the first is used again (wrap around). The behavior can be changed with the 'wildmode' option. + *c_<S-Tab>* +<S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and + then go to the previous match. *c_CTRL-N* CTRL-N After using 'wildchar' which got multiple matches, go to next match. Otherwise recall more recent command-line from history. -<S-Tab> *c_CTRL-P* *c_<S-Tab>* + *c_CTRL-P* CTRL-P After using 'wildchar' which got multiple matches, go to previous match. Otherwise recall older command-line from history. |