Better vim support?
See original GitHub issueI started using prettier recently and ran into troubles with the vim format-on-save support. The recommended approaches don’t restore cursor position cleanly (even with the <C-o>
s), causing the code to jump upon save. Saving code is a reasonably frequent operation for me, and this behavior is fairly disturbing. See the gif below:
Other vim plugins that perform format-on-save, like vim-go and elm-vim don’t have any such jumps. They use winsaveview()
and winrestview()
to save/restore the window position. I repurposed the vim-go implementation for prettier in my .vimrc file at https://github.com/karthikv/dotfiles/blob/5a289e0/vimrc#L152-L203. It works like so:
If there’s interest, I’d be happy to factor this out into a simple vim plugin to help other prettier users. The installation would be a single command with standard vim package managers (vim-plug/vundle/neobundle/pathogen). If not, that’s fine too, but I’d love to hear any thoughts.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (3 by maintainers)
You might want to try out Neoformat - it supports prettier by default and is able to keep cursor position while auto-formatting on save.
@landabaso Try Neoformat as suggested by @tmcw – it works great!