Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upVim: How to run `standard --format` on `save` #195
Comments
This comment has been minimized.
This comment has been minimized.
|
As far as I know, Syntastic doesn't support formatters, so someone needs to write a vim plugin to do this. |
feross
added
feature request
help wanted
labels
Jul 23, 2015
This comment has been minimized.
This comment has been minimized.
|
@diasdavid There is a suggestion here for how to make a plugin. https://twitter.com/feross/status/624033217016930304 Looks like it might be a one-liner! |
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 23, 2015
|
Minor variation, primarily calling it after the file has finished writing and making it a silent operation. autocmd bufwritepost *.js silent !standard % --formatTested in Vim 7.3, just append it to your |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Haven't verified if it works yet, but |
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 23, 2015
|
That's with the post write event? was getting it with |
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 23, 2015
|
If thats still the case, |
This comment has been minimized.
This comment has been minimized.
|
rad! it works :D
|
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 23, 2015
|
Just a side note, |
This comment has been minimized.
This comment has been minimized.
|
Sweet! Glad you guys got it figured out. Thanks for the help @caspervonb! I'll add this snippet to the readme. Should someone publish this as a standalone vim plugin? I'm not sure if the community does small modules like npm does ;) |
feross
closed this
Jul 24, 2015
This comment has been minimized.
This comment has been minimized.
|
There was a suggestion on Twitter to persist cursor position as well: https://twitter.com/oObsi/status/624533766434910208 I haven't tested the snippet out yet. Is this actually necessary? |
This comment has been minimized.
This comment has been minimized.
cryptix
commented
Jul 24, 2015
|
IIRC from some buffer replacement hacking, your cursor gets reset to line 0 but i might be or did things wrong. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 25, 2015
|
That's "expected", but i did not expect |
This comment has been minimized.
This comment has been minimized.
|
@caspervonb Can't you just ignore stdout? The formatting happens in place to the file on disk, so it's safe to just throw away that output if you don't want to show it in the UI. I just published 5.0.0-6 which makes sure that all expected linter output goes to stdout. |
This comment has been minimized.
This comment has been minimized.
|
@caspervonb Also, if it's helpful, you can format a file by piping it to stdin using |
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Jul 26, 2015
@feross true you could just muffle it by redirection. autocmd bufwritepost *.js silent !standard % --format > /dev/null
@feross did you mean stderr here? (because of below)
For vim, I think it's better to just replace do it externally and reload the buffer, don't want to mess up the command history too much. |
This comment has been minimized.
This comment has been minimized.
don-smith
commented
Feb 12, 2016
|
Now that the formatting feature of standard has been moved into standard-format, has anyone worked out how to apply this in vim? |
This comment has been minimized.
This comment has been minimized.
caspervonb
commented
Feb 12, 2016
|
@locksmithdon What is the difference? just invoke it as you would from a shell basically. |
This comment has been minimized.
This comment has been minimized.
don-smith
commented
Feb 12, 2016
|
@caspervonb I was missing autocmd bufwritepost *.js silent !standard-format -w %
set autoread |
This comment has been minimized.
This comment has been minimized.
tim-phillips
commented
Oct 31, 2017
|
Just to close the loop since I got here from google, this is explained in the docs: |


daviddias commentedJul 19, 2015
Following this thread, one of the features I've enjoyed a lot using vim-go was its ability to run
gofmton each save, saving me a ton of work. Would love to have this functionality for JavaScript with Standard codestyle, but I'm not sure how to do it or if there is an option available out there already. Thoughts?Thank you.