4

I'm using the plugin auto-pairs to help auto close brackets.

In vim when defining dicts or lists it'll auto formatting like this

| is the cursor position

a_dict = {
        | # the indent is 8 spaces width, but I already set 4 spaces width indent in .vimrc
        }

a_lst = [
        |
        ]

a_lst_with_a_very_loooooooooooong_name = [
        |
        ]

but I want it formats the code like this

lst = [
    |
]

How can I do this?

1
  • I have the same issue. Tried other plugins, works fine with them but they all pale in comparison to auto-pairs. Did you manage to fix it? Commented Apr 28, 2017 at 6:12

1 Answer 1

3

For Python indenting in vim, I use this plugin for pep8 indentation with Vundle. This plugin works with yours and gives you the functionality you want (at least on my machine)

Example:

lst = [
    |
]

abc = {
    |
}

You especially want the let g:pymode_indent = 0 line in your .vimrc for the pep8 plugin.

Someone who is skilled in vim programming might be able to modify your plugin to do what you need, but this solution might bring you another benefits if you use vim for Python programming.

To address your issue with 8 spaces as a tab - try having all

set tabstop=4
set shiftwidth=4
set expandtab
filetype indent on

in your .vimrc (this is what I have and it gives me 4 spaces indentation)

1
  • 1
    Sweet googly moogly this had me tearing my hair out - the plugin solves the issue
    – Tom Malkin
    Commented Jun 19, 2020 at 4:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .