install.fairie/dotfiles/.vim/plugged/vim-prettier/doc/prettier.txt

224 lines
7.8 KiB
Text
Raw Normal View History

*vim-prettier.txt* A prettier plugin for vim.
-------------------------------------------------------
vim-prettier: plugin wrapper for prettier
-------------------------------------------------------
Author: Mitermayer Reis <mitermayer.reis@gmail.com>
WebSite: https://prettier.io/
Repository: https://github.com/prettier/vim-prettier
License: MIT style license
Version: 1.0.0-beta
==============================================================================
CONTENTS *vim-prettier-contents*
Introduction |vim-prettier-introduction|
Install |vim-prettier-install|
Usage |vim-prettier-usage|
Configuration |vim-prettier-configuration|
Requirements |vim-prettier-requirements|
==============================================================================
INTRODUCTION *vim-prettier-introduction*
A vim plugin wrapper for prettier, pre-configured with
custom default prettier settings.
By default it will auto format javascript, typescript, less, scss, css,
json, and graphql files that have '@format' annotation in the header of the file.
When installed via vim-plug, a default prettier executable is installed inside
vim-prettier.
vim-prettier executable resolution:
1. Look for user defined prettier cli path from vim configuration file
2. Traverse parents and search for Prettier installation inside `node_modules`
3. Look for a global prettier installation
4. Use locally installed vim-prettier prettier executable
==============================================================================
INSTALL *vim-prettier-install*
Install with [vim-plug](https://github.com/junegunn/vim-plug), assumes
node and yarn|npm installed globally.
>
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css',
\ 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml',
'html'] }
<
or simply enable for all formats by:
>
Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
<
If using other vim plugin managers or doing manual setup make sure to have
`prettier` installed globally or go to your vim-prettier directory and
either do `npm install` or `yarn install`
==============================================================================
USAGE *vim-prettier-usage*
Prettier by default will run on auto save but can also
be manually triggered by:
>
<Leader>p
<
or
>
:Prettier
<
If your are on vim 8+ you can also trigger async formatting by:
>
:PrettierAsync
<
You can check what is the `vim-prettier` plugin version by:
>
:PrettierVersion
<
You can send commands to the resolved `prettier` cli by:
>
:PrettierCli <q-args>
<
You can check what is the resolved `prettier` cli path by:
>
:PrettierCliPath
<
You can check what is the resolved `prettier` cli version by:
>
:PrettierCliVersion
You can send to prettier your entire buffer but ensure that it
formats only your selection.
**note:** differs from `:PrettierFragment` by sending the entire buffer
to prettier, allowing identation level to be preserved, but it requires
the whole file to be valid.
>
:PrettierPartial
You can send to prettier your current selection as a fragment of same type as
the file being edited.
**note:** differs from `:PrettierPartial` by sending only the current selection
to prettier, this allows for faster formatting but wont preserve indentation.
>
:PrettierFragment
==============================================================================
CONFIGURATION *vim-prettier-configuration*
Enable auto formatting of files that have "@format" or "@prettier" tag
>
let g:prettier#autoformat = 1
Enable auto formatting of files based on whether a Prettier configuration file has been
found in the project directory or any parent directories.
>
let g:prettier#autoformat_config_present = 1
Configuration file names to search for when attempting to find an appropriate
Prettier configuration file for the current project.
>
let g:prettier#autoformat_config_files = [...]
<
Set the prettier CLI executable path
>
let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
<
The command `:Prettier` by default is synchronous but can also be forced async
>
let g:prettier#exec_cmd_async = 1
<
By default parsing errors will open the quickfix but can also be disabled
>
let g:prettier#quickfix_enabled = 1
<
By default we auto focus on the quickfix when there are errors but can also be disabled
>
let g:prettier#quickfix_auto_focus = 0
<
To enable vim-prettier to auto run in files without requiring the "@format" or "@prettier" doc tag.
First ensure that `g:prettier#autoformat` is not enabled on your `vimrc` (it should be disabled by default), then update to your own custom behaviour
Running before saving sync:
>
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html Prettier
<
Running before saving async (vim 8+):
>
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync
<
Running before saving, changing text or leaving insert mode:
>
" when running at every change you may want to disable quickfix
let g:prettier#quickfix_enabled = 0
autocmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.svelte,*.yaml,*.html PrettierAsync
<
Buffer-level custom commands
To use an alternative command, like `prettier-stylelint`, set this at the
buffer level with `b:prettier_exec_cmd`, e.g.:
>
au FileType css,scss let b:prettier_exec_cmd = "prettier-stylelint"
<
vim-prettier will look for the executable in the same places it looks for
`prettier`, and will fall back to `prettier` if it can't find
`b:prettier_exec_cmd`
Overwrite default prettier configuration
**Note:** vim-prettier default settings differ from prettier intentionally.
However they can be configured by:
>
" Max line length that prettier will wrap on: a number or 'auto' (use
" textwidth).
" default: 'auto'
let g:prettier#config#print_width = 'auto'
" number of spaces per indentation level: a number or 'auto' (use
" softtabstop)
" default: 'auto'
let g:prettier#config#tab_width = 'auto'
" use tabs instead of spaces: true, false, or auto (use the expandtab setting).
" default: 'auto'
let g:prettier#config#use_tabs = 'auto'
" flow|babylon|typescript|css|less|scss|json|graphql|markdown or empty string
" (let prettier choose).
" default: ''
let g:prettier#config#parser = ''
" cli-override|file-override|prefer-file
" default: 'file-override'
let g:prettier#config#config_precedence = 'file-override'
" always|never|preserve
" default: 'preserve'
let g:prettier#config#prose_wrap = 'preserve'
" css|strict|ignore
let g:prettier#config#html_whitespace_sensitivity = 'css'
" false|true
" default: 'false'
" let g:prettier#config#require_pragma = 'false'
" Define the flavor of line endings
" lf|crlf|cr|all
" defaut: 'lf'
let g:prettier#config#end_of_line = get(g:, 'prettier#config#end_of_line', 'lf')
==============================================================================
REQUIREMENT(S) *vim-prettier-requirements*
If prettier is not installed locally, globally or inside vim-prettier project
no code formatting will happen
==============================================================================
vim:tw=78:ts=4:ft=help:norl:noet:fen:noet: