11

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.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
Sugam Adhikari
  • 131
  • 1
  • 1
  • 6
  • I don't use nano but could be [this](https://www.nano-editor.org/dist/v2.0/nano.html)? Seach for "-i, --autoindent" in that page. – Juan T Mar 03 '17 at 17:04
  • 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. – Sugam Adhikari Mar 03 '17 at 17:10
  • 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) – gboffi Mar 03 '17 at 17:12
  • 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 Mar 03 '17 at 17:16
  • 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](https://atom.io/). – Charles Duffy Mar 03 '17 at 17:17
  • 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 Mar 03 '17 at 17:25
  • @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 Mar 03 '17 at 17:29
  • thanks for correction Charles, It was a typing mistake. I will avoid doing such typing mistakes in the future. – Sugam Adhikari Mar 03 '17 at 17:33
  • @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... – gboffi Mar 03 '17 at 19:43

3 Answers3

14

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.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
0x5453
  • 12,753
  • 1
  • 32
  • 61
3

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

Also you might find this useful.

Juan T
  • 1,219
  • 1
  • 10
  • 21
DorElias
  • 2,243
  • 15
  • 18
3

Try just M-I (Esc-I) to switch on autoindent (or off, if not required; for example, before pasting with Ctrl-Ins (or right mouse click)).

David Jones
  • 4,766
  • 3
  • 32
  • 45
St Jo
  • 31
  • 2
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/30493726) – 2e0byo Dec 03 '21 at 19:12