3

When I press o or O it indents to the necessary level since I have smartindent on. However, what happens when I'm at the start of a line and want to go to where the 'smartindent' for that line would be. Is there a way to do that? Here is an example video of what I'm trying to do:

https://gyazo.com/da4351def5a0af93df5f7fff0d462adb

I suppose dd ShiftO is the best way I have thought up so far.

David542
  • 104,438
  • 178
  • 489
  • 842
  • 1
    How about `b` `o`? I guess it only works when you're right below the line as in your video, but not for arbitrary lines... – ggorlen May 21 '20 at 04:19
  • 2
    Does this answer your question? [Vim: Smart indent when entering insert mode on blank line?](https://stackoverflow.com/questions/3003393/vim-smart-indent-when-entering-insert-mode-on-blank-line) – ggorlen May 21 '20 at 04:23
  • @ggorlen thanks for that, Yes I think `cc` is better than the `ddO` / `bo` option. – David542 May 21 '20 at 04:27
  • 1
    `cc` or `S` respect an indent. – Matt May 21 '20 at 04:27
  • @Matt thanks, even better. `S` is the simplest/best. Oddly enough the accepted answer doesn't mention that (another one does though). – David542 May 21 '20 at 04:27

2 Answers2

5

the most simple thing you can do is press S, it works just like pressing cc

Chelz
  • 437
  • 1
  • 4
  • 9
  • This doesn't work if your goal is to give a blankline a hanging indent in order to fix the bug that prevents vim folding indented sections that contain within them blanklines without any indent spaces. Press `S` on a blankline and it will indeed cause vim to enter `insert' mode on that line at an autoindent level flush with the line above. But press `Esc` to leave indent mode and thus leave the blankline with its hanging indent, and the indent spaces will disappear again. – markling Dec 22 '22 at 12:00
2

In insert mode, CTRL-F is the default key for re-indenting the current line. See :h i_ctrl-f for more information.

doopNudles
  • 635
  • 4
  • 9
  • Hm, looks like I learned something new today. It turns out CTRL-F is only used when `cindent` is turned on. I'm not sure what language you use, but you could check whether it already is on with `:set cindent?`. If it is, just hit CTRL-F while at the start of the line. If not, you could turn on `cindent` with `:set cindent` and customize it if necessary. Also, I saw some threads that suggest `smartindent` is outdated and should not be used. I would suggest either just using `autoindent`, finding a filetype plugin depending on what language you use, or using `cindent`. – doopNudles May 21 '20 at 15:40