jiangmiao / auto-pairs

Vim plugin, insert or delete brackets, parens, quotes in pair
http://www.vim.org/scripts/script.php?script_id=3599
4.09k stars 373 forks source link

Parentheses indentation conflict with vim-javascript plugin #154

Open madox2 opened 7 years ago

madox2 commented 7 years ago

When using this plugin together with vim-javascript, indentation of parentheses is wrong after new line. I have following js code:

function render() {
  return (|)
}

After pressing ENTER:

function render() {
  return (
    |
)
}

Notice that last parenthesis is not indented.

Also see https://github.com/pangloss/vim-javascript/issues/663

valerybugakov commented 7 years ago

+1 same issue here

dderg commented 7 years ago

I've got

function render() {
    return (
    |
    )
}

expected:

function render() {
    return (
        |
    )
}

The issue happens only for parens, for braces everything is ok

heydemoura commented 7 years ago

+1 same here

u10root commented 6 years ago

+1 same here. Anybody has solution????

wei-yuuuu commented 5 years ago

+1 same here

nschurmann commented 3 years ago

Is there a solution for this?

LunarWatcher commented 3 years ago

Lunarwatcher/auto-pairs#26 Lunarwatcher/auto-pairs#27 (tl;dr: fix your indent config)

nschurmann commented 3 years ago

Thanks @LunarWatcher , I forgot to mention that this only happens when writing javascript in a file that contains JSX (it can be a .js or .jsx) and inside a function or class method. Here's a screenshot. If I use something different than vim polyglot then it works fine.

Screen Shot 2021-08-02 at 9 42 03 PM
LunarWatcher commented 3 years ago

The second TL;DR: on this topic is that auto-pairs doesn't actually do what the docs promise, in terms of:

Input: (|)   <cr> at |
Output: (
    |
)

Because it has to respect a number of systems. In practice, all it does is <CR>=ko (or enter, format one up, create and jump into insert mode on the line under).

As a consequence, bad indent functions does make auto-pairs "misbehave" in the sense that it doesn't do what the docs promise, but it does respect how Vim was configured. And to be clear, polyglot isn't the only way out. It too can have bugs - use whatever plugin works for your use, or write an indentexpr if you know how and have some time to kill (or just because you want to). Having a language-portable way to do what the docs promise without relying on the indentexpr for the language to work like it should, though, is a lot harder to implement than it is to use indentexprs. (in theory, anyway. I've tried and failed to do that in a way that just works regardless of the indentexpr and other style options - and that was even prior to accounting for spaces and tabs)