5

Is there a command to make a newline without the autoindent? In other words, I want o and O to normally autoindent, but is there another command that will not autoindent for just the duration of that command?

Alternatively (if there isn't a way to that exactly), what's a better workaround than just backspacing a ton after autoindenting many tabs too far.


Example

if some_check():
    self.some_long_function_name(withlots, ofargs
                                 andmaybe=keywordargs)
                               # ^ Indents to the caret

Pressing o on the andmaybe=keywordargs line leaves me way more indented than I want to be.

Stephen C
  • 210
  • 2
  • 9
  • You seem to have some special indent settings. For me andmaybe is indented 8 chars (double shiftwidth). When I hit o, the cursor is aligned with self. This even works when I indent andmybe manually to align it with the open paranthesis. BTW: Vim 8.1.1223 – Ralf Apr 30 '19 at 21:17
  • 1
    It's probably a Python plugin that indents it like this? This indenting style is fairly common in Python. As for the question, what does "without the autoindent" mean for you? That it starts at column 0? Anything other than that would be using some form of autoindent (just a different one that what you get right now). – Martin Tournoij Apr 30 '19 at 21:21
  • Python indent script was last updated in February. – Ralf Apr 30 '19 at 21:23
  • I'm not using anything special for Python. – Stephen C Apr 30 '19 at 21:24
  • Is there an indentation to start at column 0? That would be better than what I'm doing – Stephen C Apr 30 '19 at 21:24
  • When I hit o on andmaybe, it lines me up right under the a in and. – Stephen C Apr 30 '19 at 21:25
  • Does it work better if you start Vim with vim --clean file.py ? – Ralf Apr 30 '19 at 21:36
  • @Ralf Yes. If I o at andmaybe after making clean, it sets me under the s in self. So it's probably something weird in my vimrc then, right? – Stephen C May 01 '19 at 15:03
  • 1
    Yes, it is something in your vimrc. You should Debug your vimrc. – Ralf May 01 '19 at 18:04
  • @Ralf That’s the behaviour of autoindent – Rich May 02 '19 at 17:24

1 Answers1

5

I don't think there is an normal mode command to start a new line without indent. You can, however, remove the indent while in insert mode with the keystrokes 0Ctrl-D, and so it's easy to set up new mappings to do so:

nnoremap <leader>o o0<C-D>
nnoremap <leader>O O0<C-D>

Personally, though, I'd install an indent plugin to handle this for you*.

I use vim-python-pep8-indent which handles your example nicely.

Or indeed, just use the Python indent script included in Vim (via the :filetype command) instead of the 'autoindent' setting. This is the one @Ralf describes in the comments.

Rich
  • 31,891
  • 3
  • 72
  • 139