Name: vim-prettier
Owner: Prettier
Description: A Vim plugin for Prettier
Created: 2017-05-24 22:39:57.0
Updated: 2018-05-23 08:29:30.0
Pushed: 2018-05-16 16:30:31.0
Size: 481
Language: Vim script
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A vim plugin wrapper for prettier, pre-configured with custom default prettier settings.
Note: We are currently working towards a major release on branch release/1.x
, while under development bugfixes will be applied to master branch and then ported back to release/1.x
branch.
If you have feature request and/or suggestions please comment on issue 1.0 release
By default it will auto format javascript, typescript, less, scss, css, json, graphql and markdown files if they have/support the “@format” pragma annotation in the header of the file.
![vim-prettier](/media/vim-prettier.gif?raw=true 'vim-prettier')
Install with vim-plug, assumes node and yarn|npm installed globally.
st install (yarn install | npm install) then load plugin only for editing supported files
'prettier/vim-prettier', {
'do': 'yarn install',
'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue'] }
or simply enable for all formats by:
st install (yarn install | npm install) then load plugin only for editing supported files
'prettier/vim-prettier', { 'do': 'yarn install' }
For those using vim-pathogen, you can run the following in a terminal:
/.vim/bundle
clone https://github.com/prettier/vim-prettier
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
When installed via vim-plug, a default prettier executable is installed inside vim-prettier.
vim-prettier executable resolution:
node_modules
Prettier by default will run on auto save but can also be manually triggered by:
der>p
or
ttier
If your are on vim 8+ you can also trigger async formatting by:
ttierAsync
You can check what is the vim-prettier
plugin version by:
ttierVersion
You can send commands to the resolved prettier
cli by:
ttierCli <q-args>
You can check what is the resolved prettier
cli path by:
ttierCliPath
You can check what is the resolved prettier
cli version by:
ttierCliVersion
Change the mapping to run from the default of <Leader>p
<Leader>py <Plug>(Prettier)
Disable auto formatting of files that have “@format” tag
g:prettier#autoformat = 0
Set the prettier CLI executable path
g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
The command :Prettier
by default is synchronous but can also be forced async
g:prettier#exec_cmd_async = 1
By default parsing errors will open the quickfix but can also be disabled
g:prettier#quickfix_enabled = 0
By default we auto focus on the quickfix when there are errors but can also be disabled
g:prettier#quickfix_auto_focus = 0
To enable vim-prettier to run in files without requiring the “@format” doc tag. First disable the default autoformat, then update to your own custom behaviour
Running before saving sync:
g:prettier#autoformat = 0
cmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue Prettier
Running before saving async (vim 8+):
g:prettier#autoformat = 0
cmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
Running before saving, changing text or leaving insert mode:
en running at every change you may want to disable quickfix
g:prettier#quickfix_enabled = 0
g:prettier#autoformat = 0
cmd BufWritePre,TextChanged,InsertLeave *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync
Note: vim-prettier default settings differ from prettier intentionally. However they can be configured by:
x line length that prettier will wrap on
ettier default: 80
g:prettier#config#print_width = 80
mber of spaces per indentation level
ettier default: 2
g:prettier#config#tab_width = 2
e tabs over spaces
ettier default: false
g:prettier#config#use_tabs = 'false'
int semicolons
ettier default: true
g:prettier#config#semi = 'true'
ngle quotes over double quotes
ettier default: false
g:prettier#config#single_quote = 'true'
int spaces between brackets
ettier default: true
g:prettier#config#bracket_spacing = 'false'
t > on the last line instead of new line
ettier default: false
g:prettier#config#jsx_bracket_same_line = 'true'
oid|always
ettier default: avoid
g:prettier#config#arrow_parens = 'always'
ne|es5|all
ettier default: none
g:prettier#config#trailing_comma = 'all'
ow|babylon|typescript|css|less|scss|json|graphql|markdown
ettier default: babylon
g:prettier#config#parser = 'flow'
i-override|file-override|prefer-file
g:prettier#config#config_precedence = 'prefer-file'
ways|never|preserve
g:prettier#config#prose_wrap = 'preserve'
If prettier installation can't be found no code formatting will happen