Indenting lines with leading tabs is an important technique for writing clear and readable code, and are essential in Python where they have syntactic meaning. Many IDEs insert tabs automatically, but if you’re using
vi it can be tedious to insert tabs individually. Fortunately, there is an easy shortcut, and it’s a very handy command to remember.
vi session, enter command mode by pressing
ESC. Then, set the size of the tabs with the following command:
To make this the default, put “set shiftwidth=2” in your ~/.exrc file.
Then, to tab shift the next 13 lines, you’d type a command like this:
Matt Parsons is a freelance Linux specialist who has designed, built and supported Unix and Linux systems in the finance, telecommunications and media industries.
He lives and works in London.