Skip to content

Set nosmartindent to avoid comments auto-indenting to first column #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
memeplex opened this issue Jul 20, 2015 · 11 comments
Closed

Set nosmartindent to avoid comments auto-indenting to first column #46

memeplex opened this issue Jul 20, 2015 · 11 comments

Comments

@memeplex
Copy link

For example, the cursor being ^:

def test():
    ^

say you now type #, you get:

def test():
#

instead of:

def test():
    #

The reason is smartindent. I think your indent plugin should unsetlocal it by default.

@blueyed
Copy link
Member

blueyed commented Jul 20, 2015

Agreed, without having looked into it.

Should be a trivial change (which should include a test). A PR for this would be welcome, of course!

@blueyed
Copy link
Member

blueyed commented Jun 26, 2016

I could not reproduce it, using both smartindent and set indentexpr+=#.

(not on master though but while fixing something else)

@hynek
Copy link
Contributor

hynek commented Jul 3, 2016

Closing then. Feel free to re-open if we missed something.

@hynek hynek closed this as completed Jul 3, 2016
@bharadwaj-raju
Copy link

Note that this can fix it without disabling smartindent:

inoremap # X<BS>#

@blueyed
Copy link
Member

blueyed commented Sep 16, 2016

@bharadwaj-raju
So you can reproduce this?
Do you have # in :set indentkeys??

@bharadwaj-raju
Copy link

Yes, I can. I don't have # in indentkeys.

Removing the inoremap and adding # to indentkeys re-introduces the problem.

@blueyed
Copy link
Member

blueyed commented Sep 17, 2016

What Vim/Neovim version?
'smartindent' is set, right?
Other settings that might be involved?!

@bharadwaj-raju
Copy link

Smartindent is set.

NVIM 0.1.5
Build type: RelWithDebInfo
Compilation: /usr/bin/cc -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -Wconversion -O2 -g -DDISABLE_LOG -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wvla -fstack-protector-strong -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -DHAVE_CONFIG_H -D_GNU_SOURCE -I/build/neovim/src/build/config -I/build/neovim/src/neovim-0.1.5/src -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/usr/include -I/build/neovim/src/build/src/nvim/auto -I/build/neovim/src/build/include
Compiled by builduser

Optional features included (+) or not (-): +acl   +iconv    +jemalloc +tui      
For differences from Vim, see :help vim-differences

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

@blueyed
Copy link
Member

blueyed commented Sep 17, 2016

I could still not reproduce it yesterday. Can you try it with a minimal init.vim, please, and provide this here?!

@bharadwaj-raju
Copy link

bharadwaj-raju commented Sep 17, 2016

/tmp/minimalvimrc:

set nocompatible

syntax on

filetype plugin on

set smartindent

set smartindent cinwords=if,else,elif,try,except,finally,while,for,def,class
$ nvim -u /tmp/minimalvimrc /tmp/test.py

Reproducible.

@blueyed
Copy link
Member

blueyed commented Sep 18, 2016

Thanks for the test case.

As we can see it's not caused by this plugin (which I assumed).

From :h 'smartindent':

    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.

Which is what you suggested.

I could imagine adding this to Python buffers via ftplugin/python.vim if smartindent is enabled, but that should be done for Vim by default then probably?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants