Skip to content

EgZvor/vim-black

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vim-black

This is a stripped down version of the official Black plugin for Vim that does not handle external dependencies for you.

Why?

Black is the uncompromising Python code formatter created by Łukasz Langa. That repository also features a Vim plugin that provides the Black command. It formats the current file according to the settings found in either your Vim configuration files or a toml file inside your project.

The problem with having a Vim plugin in the Black repository is that Vim plugin managers clone the entire project which may not necessarily be what you want. It also installs Black automatically in a virtual environment inside your .vim directory. So I decided to make a "fork" that does not do any of that and assumes you already installed Black in a virtual environment compatible with the python interpreter used by your Vim.

How to get started

Just assign g:black_virtualenv to the virtual environment directory containing Black.

For example:

let g:black_virtualenv = '~/.virtualenvs/black'

Consider using pipx to install Black in a dedicated virtual environment.

pipx install black

Commands

  • :[range]Black to format the selected lines
  • :BlackVersion to get the currently used version of Black

Example mappings

This plugin exposes two internal mappings (see :h <Plug>). A good place to put the following mappings is in .vim/after/ftplugin/python.vim.

Add an operator to apply Black on :h motion. For example, try <space>bip.

nmap <buffer> <space>b <Plug>(Blackify)

Apply Black on the current line:

nmap <buffer> <space>bb <Plug>(BlackifyLine)

Configuration

Your pyproject.toml config file will be discovered automatically. Failing to do that, the plugin will try using the following options.

  • g:black_fast (defaults to 0)
  • g:black_linelength (defaults to 88)
  • g:black_string_normalization (defaults to 1)

About

Vim plugin for the uncompromising Python code formatter

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Vim Script 100.0%