7 Command-line text editors

When working with remote machnies, such as AWS ec2, you will be required to edit files and write code without a GUI. While there have been developments on using tools such as VSCode to edit remote files, sometimes it’s easier to use a command-line text editor. There are many such tools, but the most popular are nano, vim and emacs. The latter two of those are actually the tools of choice for many programmers, and are extremely powerful (at the cost of a very steep learning curve). A nice way to learn VIM is by checking out the VIM Adventures website - you can learn it by playing a game!

For our purposes we’ll focus on using the basics of vim to edit files. It is more complex than nano but provides some great added functionality, such as synthax highlighting, to make your remote editing work easier.

Vim comes preinstalled on Linux, which is the typical server machine, and you can start it like this:

vim testfile.py

This will create this new file and start editing. Vim has several modes of operation, the default one is the selection mode. You can use this to navigate the code by using the arrows. If you want to enter the insert mode, to edit files, press i. Then you can start typing, as you would normally in a GUI editor. After you’re done, you have to come back to the select mode, by pressing ESC. Then you can use the vim commands to save and exit. This command is :wq. If you want to quit without saving do :q!.