The Computer Oracle

How to add a new line with the same indentation

--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Secret Catacombs

--

Chapters
00:00 How To Add A New Line With The Same Indentation
00:17 Accepted Answer Score 45
00:28 Answer 2 Score 9
00:41 Answer 3 Score 5
00:51 Answer 4 Score 0
01:07 Thank you

--

Full question
https://superuser.com/questions/99741/ho...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#vim

#avk47



ACCEPTED ANSWER

Score 45


Adding set autoindent to your ~/.vimrc can do that for you automagically.




ANSWER 2

Score 9


I'd also suggest adding this to your .vimrc:

set smartindent

It will increase the indent in a new block.




ANSWER 3

Score 5


Both will annoy you when pasting, as Vim will try and indent everything on the fly.

Prior to pasting enter:

:set paste



ANSWER 4

Score 0


At bottom of the file, I'm using:

# vim: ts=2 sw=2 sts=2 sr noet st ai si

For example Dockerfile:

FROM centos-7
RUN ...
CMD ...

# vim: ts=2 sw=2 sts=2 sr noet st ai si

If you want keep the indentation only, use # vim: st ai si