Is it possible to see the immediate formatted code in the real-time ? If so, life could be much easier.
Therefore, I created a little plugin vim-rt-format, which can format the current line immediately in INSERT mode as soon as you press ENTER:
When you are focusing on editing, everything is done without paying extra attention. No need to stop your work to run an extra command like
Ready to try this out ? Firstly,
+python3 feature must be enabled in your vim, check it by:
It will return
1 if python is supported in your current vim version. If not, install a new vim with
+python3 feature, for example in ubuntu/debian:
sudo apt-get install vim-nox
Secondly, a python module named
autopep8 is required:
sudo pip install autopep8
Then add a few code in your
" Install the plugin with vim-plug: Plug 'skywind3000/vim-rt-format' " By default, it will be triggered by `ENTER` in insert mode. " set this to 1 to use `CTRL+ENTER` instead, and keep the " default `ENTER` behavior unchanged. let g:rtf_ctrl_enter = 0 " Enable formatting when leaving insert mode let g:rtf_on_insert_leave = 1
And everything is ready, restart your vim, edit some files then you will have a nice day.
BTW: Currently, it supports