correct Vim integration code (#2853)
- use `Black` directly: the commands an autocommand runs are Ex commands, so no execute or colon is necessary. - use an `augroup` (best practice) to prevent duplicate autocommands from hindering performance.
This commit is contained in:
parent
50a856970d
commit
8089aaad6b
@ -189,10 +189,13 @@ If you need to do anything special to make your virtualenv work and install _Bla
|
|||||||
example you want to run a version from main), create a virtualenv manually and point
|
example you want to run a version from main), create a virtualenv manually and point
|
||||||
`g:black_virtualenv` to it. The plugin will use it.
|
`g:black_virtualenv` to it. The plugin will use it.
|
||||||
|
|
||||||
To run _Black_ on save, add the following line to `.vimrc` or `init.vim`:
|
To run _Black_ on save, add the following lines to `.vimrc` or `init.vim`:
|
||||||
|
|
||||||
```
|
```
|
||||||
autocmd BufWritePre *.py execute ':Black'
|
augroup black_on_save
|
||||||
|
autocmd!
|
||||||
|
autocmd BufWritePre *.py Black
|
||||||
|
augroup end
|
||||||
```
|
```
|
||||||
|
|
||||||
To run _Black_ on a key press (e.g. F9 below), add this:
|
To run _Black_ on a key press (e.g. F9 below), add this:
|
||||||
|
Loading…
Reference in New Issue
Block a user