This repository contains Vim configuration files that set the formatprg
option for various common code file types, according to the availability of the most common format programs on your computer.
The formatprg
option in Vim specifies an external program to use for formatting the current buffer.
It determines in particular the behavior of the gq
operator;
for example, gqip
formats the current text block.
Each configuration file in this repository is tailored to a specific file type and sets formatprg
to a suitable formatter with appropriate options.
Some example file types and their formatters:
-
For shell scripts, the
shfmt
tool is used with the following options:--simplify
: Minify the code.--case-indent
: Indent switch cases.--space-redirects
: add trailing space to redirect operators.--indent
: Set the indentation level to the value ofshiftwidth
(if applicable).
-
For JavaScript files,
prettier
is used as the formatter, whenever available.prettier
is an opinionated code formatter. -
For HTML files,
tidy
is used as the formatter, whenever available, tool for cleaning up and pretty-printing HTML. -
...
-
there are many more filetypes; please check the
ftplugin
folder.
To use these configuration files, copy them to your Vim configuration directory (usually ~/.vim/ftplugin/
).
For example, to install the sh.vim
configuration:
mkdir -p ~/.vim/ftplugin
cp sh.vim ~/.vim/ftplugin/
Repeat the above steps for each file type configuration you want to use.
You may also use a plug-in manager such as vim-plug.
In this case, add Plug 'konfekt/vim-formatprgs
to your vimrc
to use them.
Once installed, Vim will automatically use the specified formatter when you use the gq
command (see :help gq
) in a buffer of the corresponding file type.
Contributions are welcome! If you have a configuration for a new file type or improvements to existing configurations, please open a pull request.
This repository is licensed under the Unlicense.
See the LICENSE
file for more details.
Feel free to reach out if you have any questions or need further assistance.