Issue
I just purchased a "Kano" (raspberry pi) for my daughter, and we're trying to create a python script using the terminal. I've been using the nano text editor, and so far it's been going well, but I know that there are better code editors for python.
Does anyone have a recommendation for a code editor for python that I can launch from the LXTerminal? For example, in a manner similar to how the nano editor is launched to edit a python script ("nano mygame.py")
Ideally, I want something that comes re-installed with kano/Debian that I can use out of the box, which is very user-friendly. I feel like always having to resort to ^O and ^X etc. to save and exit is really not user-friendly. Also, nano doesn't seem to have good syntax highlighting and indentation, etc. which would be nice for coding.
I have the Pi 3 with all the latest software updates (as of the writing of this post)
thanks, Darren
Solution
For editing text using the terminal vim
is an excellent choice (vim mygame.py
). Initially it is going to be confusing, because it has two different modes and it is easy to forget which one you are in. But in the long term learning it will pay off, because it can do some incredible things for you. Once you get used to it, it will make nano
look like a bad joke. And this is probably the best time for your daughter to learn it: later on it is only going to get more difficult to learn a more abstract, and more powerful editor.
The first thing to remember is that initially, after starting vim, you are in command mode so you cannot type text like you would expect. To change into editing mode, just press i
(without a colon), then you can type text like in any other editor, until you press Esc, which goes back to command mode. Commands start with a colon. For example you can quit vim by typing :q
(with the colon) and then pressing Enter. You write the file (i.e. save your changes) using :w
. You can give it a filename too, which works exactly like "Save as...". To open another file for editing you can use :e otherfile.py
.
These were the most essential things I could think of, but there are other modes for selecting lines, characters, rectangular blocks. For copy & pasting, and other things I would recommend going through a tutorial, or just searching for vim copy paste
or whatever is needed. I cannot emphasize enough that it is worth learning these, because of the advanced features of the editor, especially if you are planning to use the editor for coding! As a quick example, you can completely reindent your whole code by typing gg=G
in command mode.
The default settings of vim will give you a very basic look and feel, but you can download (and later customize) a .vimrc
file which simply goes into your home directory, and from then on this will be used at every start. If you just Google vimrc, you will find a lots of good examples to start with, which will turn on syntax highlighting with pretty colours, and give you some more sensible settings in general. I would recommend downloading one or two versions of the .vimrc
file early on, and trying out the difference it can make.
Another option would be emacs
, which is equally powerful, and equally confusing for a beginner. If you want an editor that is intuitive using the terminal, nano
is probably your best bet, from those that are installed by default. Yes, nano counts as intuitive. Anything else will be somewhat more difficult, and far more powerful.
Answered By - Adam