Skip to content
TheChatArchiveThe Chat Archive
vicuna-13b· LMSYSHugging Face Arena Human Preference 55K

I'm using neovim. in my init.lua, how to run autopep8, then black then isort on my…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4-0314’s answer.
  1. User

    I'm using neovim. in my init.lua, how to run autopep8, then black then isort on my python file up on saving

  2. Assistant

    To run autopep8, black, and isort on your Python files in Neovim, you need to configure your Neovim init file (init.lua) to run these tools on save. Follow these steps:

    1. Install the required dependencies:
      • autopep8: pip install autopep8
      • black: pip install black
      • isort: pip install isort
    2. Configure the init.lua file to run these tools on save:

    Create or edit your init.lua file, and add the following configuration:

    local lspconfig = require('lspconfig')
    local on_attach = require('on_attach')
    
    -- Enable LSP for Python
    lspconfig.pyright.setup({
      settings = {
        ['python.formatting.provider'] = 'black',
        ['python.formatting.provider.black.enabled'] = true,
        ['python.formatting.provider.black.path'] = 'pyproject.toml',
        ['python.formatting.provider.black.args'] = {
          '--config',
          'pyproject.toml',
        },
      },
    })
    
    -- Enable autopep8 for automatic peeping
    on_attach(function(client, bufnr)
      local on_save = vim.api.nvim_buf_list_autocmd(bufnr, 'BufWritePre *.py', function()
        vim.api.nvim_exec([[
          autopep8 -f python -r -s %s
        ]], false)
      end)
    
      -- Run isort on save
      local on_save_isort = vim.api.nvim_buf_list_autocmd(bufnr, 'BufWritePre *.py', function()
        vim.api.nvim_exec([[
          isort %s
        ]], false)
      end)
    
      -- Return the autopep8 and isort functions
      return { on_save, on_save_isort }
    end)
    

    This configuration sets up LSP for Python with Black as the formatter, and it also configures autopep8 and isort to run on save for Python files.

    With these changes, every time you save a Python file in Neovim, autopep8 will be run for automatic peeping, followed by black for formatting, and then isort for type checking.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.