Odd comment indentation behavior
glacials opened this issue · 5 comments
Hiya, this is a great plugin that's been very helpful! I've run into an indentation quirk recently that doesn't seem intended. Steps to repro:
-
Set these Vim options:
set smartindent set tabstop=2 set softtabstop=2 set shiftwidth=2 set expandtab
-
Make a
user.graphql
file with some contents liketype User { name: String email: String }
-
Place your cursor on the first line and press
o
to insert a new line. You'll see something like this:type User { <CURSOR> name: String email: String }
-
Now start a comment by pressing
#
. I expect to see this:type User { #<CURSOR> name: String email: String }
But instead I see this:
type User { #<CURSOR> name: String email: String }
Additionally, when I try to indent the comment line with >>
, nothing happens.
It seems Vim wants to force me to use no indentation for all comments, but I don't see any places in the GraphQL spec (or any style guides anywhere) that mention this behavior.
I'm using Neovim 0.2.0 if it helps.
I can reproduce this and will look into it soon. Thanks for the bug report!
This appears to be :smartindent
's default behavior:
When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use this
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.
I'll have to consider whether this is something that should be changed / overridden by this plugin, perhaps by implementing our own indent rules, although I'm also reluctant to make things too complex for this case.
I'm still thinking about whether the plugin should set inoremap # X<c-h>#<space>
itself for GraphQL buffers (perhaps with a global option to disable the mapping). That would appear to be the expected behavior in all cases, but I also have some misgivings about overriding vim behavior in a filetype-specific plugin.
I decided to just implement my own indentation rules that supersede smartindent
. It's a pretty simple implementation, and it specifically addresses the comment behavior described by this issue, but please let me know if there are cases I'm not covering correctly.