Linux Terminal - Text Editors

From Computer Science
Revision as of 14:36, 13 August 2019 by Jkinne (talk | contribs) (GUI Editors)
Jump to: navigation, search

This page is a part of the Linux and CS Systems Bootcamp. This page assumes you have your computer setup to connect to the CS server, or have the appropriate software installed on your computer to run commands. Go back to the Linux and CS Systems Bootcamp main page if you don't have our system setup yet.

First Editor - Nano

One thing programmers need to do is edit text files. The text files could be your programs, or they could be data files. There are many different text editors that are normally installed on Linux systems. The most popular are - vim, emacs, nano.

nano is among the easiest text editors to use, so let's get you started using nano. You first need to be logged into Linux and open a terminal. Type the following

nano hello.txt

You will now be running the nano editor and editing a file named hello.txt. Note that the interface is completely text-based. There is nothing for you to click on. Instead of clicking on menus, you have control codes that you can type to save, close, etc. The bottom of the screen lists the control codes that you can use. Each control code is typed by holding down the control key on your keyboard and then pressing a letter.

For example, hold down control and press x to Exit nano. You can type nano hello.txt again to open the nano editor again.

Now type some text, for example "Hello World". You can save your file by holding down control and pressing o. When you do this, nano prompts you to ask what the name of the file should be; you can leave it alone as hello.txt and press enter. Your file is now saved! You can type more into your hello.txt file if you wish. Use the arrow keys on your keyboard to move around inside of your text file. When you are done editing, use control-o to write out (save) your file, and then use control-x to exit nano.

  • [video demo of nano]

Text-based Editors

There are a variety of other text-based editors that are normally installed on most Linux (and Mac) systems, and can be used when logged in to the CS server. With all of these, since they are text-based you type keyboard shortcuts to open and save, search, etc. For each of the text-based editors below we give enough shortcuts to get started, and you can search online for more (e.g., search for vim shortcuts, or vim tutorial, or vim cheat sheet).

Vim

Basic shortcuts

[video demo]

Emacs

Basic shortcuts

[video demo]

Jove

Basic shortcuts

[video demo]

GUI Editors

GUI / graphical editors can be easier to use because you can point-and-click on menus rather than needing to remember short-cut keys. Some GUI editors also have other features that are nice (auto-completing some parts of your code if the right plug-in is installed, being able to run your code from within the editor, etc.). Some of those features are also available in text-based editors (vim and emacs in particular) as well, but rely on yet-more-shortcuts. The following are a few graphical editors which are available on the CS lab machines; some of these can also be installed on Windows and Mac.

  • Atom - download video demos ([on cs] [on Windows] [on Mac])
  • Emacs - also has a GUI interface - download video demos ([on cs] [on Windows] [on Mac])
  • Kate - download video demos' ([on cs] [on Windows] [on mac])