How to make auto indention in nano while programming in python in linux?

Sugam Adhikari picture Sugam Adhikari · Mar 3, 2017 · Viewed 14.2k times · Source

I am a beginner programmer as well as linux user. Before, I was using windows and the python IDLE was so good. I need not needed to press tab button after the "If" statement or any other loops.

Now, I am using Linux and started to write programs through the command line text editor of ubuntu called as "nano". Here, I need to press tab all the time i use "if" statement. It is very tedious. Especially when there is bunch of nested loops, it becomes difficult to remember the tabs count. And i was thinking if there was any idea to make it work like in the IDLE in windows. I also tried to google the problem but i couldn't explain it in few words. I hope you've got what my problem actually is. And i need a descent solution for this.

Answer

0x5453 picture 0x5453 · Mar 3, 2017

Try adding the following to ~/.nanorc (you may need to create the file if it doesn't exist):

set autoindent

Note that nano is pretty lightweight editor, so it lacks a lot of features and customization that other editors provide. You might look into something like emacs or vim if you find yourself limited by your editor.

EDIT: More detail as requested:

Type nano ~/.nanorc in your terminal to open the config file with nano.
Once inside nano, type set autoindent to enable auto-indentation.
Then type Ctrl-o Ctrl-x to save the file.