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

18,678

Solution 1

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.

Solution 2

When you run nano add -i to the command (as in nano -i).

Also you might find this useful.

Share:
18,678
Sugam Adhikari
Author by

Sugam Adhikari

Updated on June 09, 2022

Comments

  • Sugam Adhikari
    Sugam Adhikari almost 2 years

    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.

    • Juan T
      Juan T about 7 years
      I don't use nano but could be this? Seach for "-i, --autoindent" in that page.
    • Sugam Adhikari
      Sugam Adhikari about 7 years
      Juan T, i think that intends for all new lines i go for. I mean it would indent even after i use common statement line "print" or any variables assignment and that could make it of no use.
    • gboffi
      gboffi about 7 years
      Why don't you install IDLE on your Linux system? It's as easy as sudo apt install idle (details may vary depending on your distro)
    • Charles Duffy
      Charles Duffy about 7 years
      FYI, "lunux" is a typo you might try to avoid. There was a time historically when detractors made a practice of spelling "Linux as "Loonix" or "lunix", to imply insanity on the part of its developers or users. Thus, it has some historical weight as something calculated and intended to provide offense.
    • Charles Duffy
      Charles Duffy about 7 years
      Beyond that, I'd really suggest finding a better editor than nano. Even if you aren't willing to give gvim (the graphical vim interface) a try, there are very nice cross-platform editors you can use such as Atom.
    • Sugam Adhikari
      Sugam Adhikari about 7 years
      I just need be able to code in python like in windows IDLE of python where there should be syntax highiting and auto-indention after if statement. You may suggest what code should I type in the terminal to get that that type of environment. I prefer simple language as i am very young to understand vague syntax and words
    • Sugam Adhikari
      Sugam Adhikari about 7 years
      @goffi thanks a lot! as i visited the python's official page, i didn't find any release for linux version and i thought there wouldn't be any thing like that for python. Thanks man, You made my day
    • Sugam Adhikari
      Sugam Adhikari about 7 years
      thanks for correction Charles, It was a typing mistake. I will avoid doing such typing mistakes in the future.
    • gboffi
      gboffi about 7 years
      @SugamAdhikari In Linux binary packages are provided by the "OS vendor", in Windows by the "application vendor". This is a difference that you have to keep in mind! Further, many Linux distributions use the idea of a "Software Centre" application from which you can install LOTS of different software and applications. Explore your environment...
  • Sugam Adhikari
    Sugam Adhikari about 7 years
    please explain in detail
  • Sugam Adhikari
    Sugam Adhikari about 7 years
    i couldn't get what you are saying
  • Sugam Adhikari
    Sugam Adhikari about 7 years
    wait, i'll try again
  • Admin
    Admin over 3 years
    vim and emacs are way too complicated
  • 2e0byo
    2e0byo over 2 years
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review