Development Environments: Text Editors for Programming, Text Editing and Ergonomics
Video Version
This entry has a video version available on the YouTube channel. Although this text version is more complete, you can follow the video first, if you prefer it.
Writing Source Code
In traditional programming languages, the source code is stored in text format, in files called text files. If you use an Integrated Development Environment (IDE), you can write source code in the environment to create programs.
However, sometimes you need to create or modify external files or in formats that are not supported by the IDE. The good news is that these files usually are text files as well. If you want to edit them, you can use a text editor. Text editors can create new text file and modify existing ones, serving as complements or event replacements to writing code in an IDE.
Before starting to program, many people use text processors, such as Microsoft Word or LibreOffice Writer. Perhaps surprisingly, text processors are not text editors suitable for programming activities. Similarly, the text documents created by office programs are not text files. Then what are text files and editors?
Text Documents and Text Files
History starts with writing.
Writing is also fundamental for software development. Traditional programming activities also require writing (although there are programming languages that are not written, such as visual programming languages). Writing is present in source code of programs, documentation, reports, messages for communication, reminders, program configuration in some operating systems...
Unlike school and office activities, programming activities do not use text processors. A text processor (such as Microsoft Word and LibreOffice Writer) can create formatted text, on which words and lines can different have sizes, fonts, colors and styles. Formatted text files are often called text documents.
Programming activities use text without formatting, called plain text. A common term to refer to files storing plain text content is text file. Plain text is one of the simplest and most primitive ways to store text in a computer file. The file stores values encoded as characters, that can be symbols or control values. Letters, numbers, spacing, punctuation symbols. Control values include spacing, and other values or special symbols (line breaks, end of file mark), which are not always visible. A program that creates and edit text file is called a text editor.
If you use Linux, distributions often include preinstalled text editors with suitable features for programming. Depending on the distribution, it is possible that the operating system setup itself required the use of a text file to configure the system.
Windows and Notepad
If you use Windows, the preinstalled text editor is called Notepad, with an executable file named notepad.exe
.
If you have ever used Notepad, the generated files are text files.
Text Editors for Programming
Text editor for programming provide features to ease writing source code, such as:
- Ease of choosing a file extension;
- Choice of encoding (for instance, ASCII or UTF-8) for data stored in the file;
- Visual highlighting for programming language syntax, such as syntax highlighting. Characters (and words) identified as reserved words, logic and arithmetic operators, functions, variables and scope can be highlighted by the editor, and it can provide additional navigation support;
- Better options to undo e redo operations on source code;
- Search by values, search by patterns (for instance, using regular expressions);
- Automatic or semi-automatic (for instance, using
TAB
) indenting (spaces and tabulations to ease reading source code); - Suggestion to complete words and symbols based on file content, on a project, or even from the analysis of the structure of the written code;
- Command line integration;
- Back-up of files;
- Source code version management integration (for instance,
git
).
In other words, text editors for programming help to make the practice a little more accessible. The features are necessary nor required, but they are convenient and helpful to have.
If you consider the previous list, Notepad is not a good text editor for programming. Evidently, you can use it if you like the program. However, there are better alternatives.
Before continuing, it should be noted that the entries for most editors will be short simply because they fulfill all basic text editing for programming purposes well. High quality text editors do not disturb text writing, do not provide unnecessary distractions, are fast and responsive (for instance, they have a short time interval between the input of a character and its presentation on an output device, such as a screen).
The provided images display the default text editor configuration with only syntax highlighting enabled. You can change the appearance (fonts, sizes, colors) of all listed text editors, either manually (creating your own theme) or choosing among the available predefined themes. However, more advanced text editors allow more complex customization.
Furthermore, there are other alternatives other than the ones listed here. If you want to discover others, you can search for terms such as "programming text editor".
I Use an IDE; Do I Need a Text Editor?
In general, the answer for beginners is usually not; use the editor embedded in your UDE, especially when you are starting to learn.
If you use an IDE, the integrated text editor probably offers many of the previously listed features. Some IDEs can even offer more advanced and complex features, based on the programming language of the project or even of the program under creation.
An example of a traditional feature are context-aware auto-complete resources. More sophisticated examples are IDEs that create a structure called abstract syntax tree (AST), that maps code to a data structure. Among other possibilities, this allows performing semi-automatic source code modification such as refactors.
Furthermore, the integration with compilers, interpreters, debuggers and file mangers provided by IDEs make it a good option for software developers of all levels, and even more convenient for beginners.
Yet, there are some scenarios on which a text editor can be useful or required. For instance:
- You may need to edit configuration files in languages that are not supported by your IDE;
- The embed is not good enough for your needs (or you simply do not like it);
- Experienced programmers may know several programming languages and wish to use a very same system to write code for all languages.
Recently, technologies such as Microsoft's Language Server Protocols (LSP) enable using advanced resources present in IDE in other text editors that support the technologies. In some cases, they can transform a text editor of your choice into a simpler IDE.
Notepad++
Notepad++ is a text editor with good features. The program has a simple and clean graphical user interfaces, and advanced features available under menus and shortcuts. It is a good option to complement an IDE for programming beginners, especially for those who use Windows. One advantage is that you only need to open the program to start editing files with it, as the editor opens with an empty file ready to use (or it restores the files that were being edited on the last session to restart the activities from where you left them). Thus, Notepad++ combines the simplicity of Notepad with features that are suitable for programming activities.In particular, Notepad++ is one of the options available to install with Ninite, as previously presented on how to install programs. Even if you do not use it as your primary programming tool, you may find it worth to keep it installed in your machine as an alternative once you need a text editor.
gedit
gedit, the default text editor of the Gnome environment for Linux, is a competent option to start programming activities. Similar to Notepad, gedit starts with a ready to use empty file. Besides Linux, the editor works on Windows and Mac, thus also being a good option for beginners.Kate
Kate editor is a reflex of KDE: a program full of useful features for software development, ranging from basic to advanced. As it can be integrated to command line interpreters and LSP, and it even provides basic Vim keybindings, Kate is a good option both as a primary or as a secondary text editor.For instance, although I use Emacs, sometimes I use Kate in machines with more modest hardware or in files with very long lines (for instance, with thousands of characters in a single line), which can be a little problematic in my Emacs setup.
GNU Nano
Either by preference or necessity, Nano is a good option for people who want to program using the command line instead of a graphical environment.
Besides programming, it is useful to know how to use (at least) one command line text editor in the case you need to edit files remotely. In addition, although many Linux distributions provide graphical user interfaces to install and/or configure, some do not for different reasons, which results in a potential need for a command line text editor. There are also people who prefer writing using a terminal and others to whom the graphical interface is irrelevant.
Whatever the case, Nano is a command line editor with good features and one of the simplest to use among its alternatives.
Some notes about Nano:
In the bottom part of the screen, the marked commands that start with a circunflex accent (
^
) useCtrl
. For instance, to save the file, you pressCtrl O
;Nano, as well as in other command line text editors, allow using commands started with
Esc
. Unlike modifier keys, to use anEsc
command you should pressEsc
then release it before continuing the combination.For instance, to enable line wrap (that is, to continue a long line below its end instead of truncating it), you can use
Esc L
. To do this, you pressEsc
, release it, then you pressL
.
Atom
Perhaps Atom is an intermediate option among the previous and the next text editors; perhapts it may also be closer to an IDE than of a traditional text editor. For the aesthetic standards of text editors, Atom is an option that distinguishes itself for using Web technologies to define its graphical user interface. It is modern, with an equally modern appearance, and implemented using Electron.
Besides the expected features, Atom allows adding graphical effects that can be appealing to some people. The result is an interesting option both for beginners and for those with Web programming experience (for instance, CSS and JavaScript) who want to customize their own editor.
Visual Studio Code
Perhaps closer to an IDE than a text editor, Visual Studio Code is becoming a popular option for programming. It is also the most recent option of this list.
Created by Microsoft as an alternative to the Visual Studio IDE, Visual Studio Code is multiplatform (in other words, it can be used in Windows, Linux and Mac, unlike the original Visual Studio), and provides support and integration to multiple programming languages.
Like Atom, Visual Studio Code is also implemented using Electron.
As Notepad++, Visual Studio Code can be installed using Ninite (as shown in how to install programs).
Vim (and Vi)
The last two options of this list (Vim and Emacs) are the oldest, as well as most advanced and complex. They were released decades ago, something that show their qualities and relevance over time. I would not recommend either of them for beginners in programming (for they require time to learn), though as a future option to test once they become more experienced.
Vim (Vi Improved) is a popular text editor among software developers since its release in the 1990s, as an improved version of the Vi text editor, created decades before it (1976). Nowadays, there is also Neovim, which is a modern version of Vim. One advantage of Neovim is the possibility to extend the editor using Lua instead of Vimscript.Unlike the other alternatives list in this article, Vim is a modal text editor. This means that the program functions in modes, some of which allow writing text, and perform the functions of the active mode. Besides modes for writing, there are modes for keyboard navigation, selection or modification in a more programmatic way, using command composition.
In other words, Vim is a different editor, which requires a different way to think text editing.
To write text using the program, you have to alternate from the standard command mode (called Normal
) to the insertion mode (Insertion
or Append
, depending on the position that you want to add text: before or after the cursor, respectively).
An advantage of Vim is that many (virtually every) Unix-based systems (such as Linux) have the program preinstalled in the default configuration. Therefore, Vim is useful and convenient for system administrators.
In my opinion and for my needs, Vim's modal edition is the best alternative for text editing. However, Vim is not the best program for text editing (although this can certainly be polemic among the enthusiasts of the program).
GNU Emacs
Alongside the original Vi, Emacs is the oldest option of this list, being first released in 1976. It is older than the author, and probably older than most people accessing this website.
There are people who say that Emacs is an operating system in the form of a text editor. They are not wrong. Besides a text editor, Emacs can serve as, among many others:
- E-mail client;
- Agenda;
- Diary;
- File manager;
- Command line interpreter;
- Literate programming environment (with Org Mode Babel);
- Remote file text editor;
- Web server;
- Internet browser (albeit basic);
- Client for social networks;
- Advanced calculator;
- Spreadsheet;
- Financial control system;
- Controller for coffee making machines;
- Pseudo therapist (see Eliza)...
There are also people who say that Emacs is an operating system that has everything but a text editor. This time, there are controversies.
Emacs precedes the Common User Access (CUA) convention and, therefore, has shortcuts and terminology that are different from modern expectations.
Although Emacs do have a special setting called cua-mode
, which changes the keybindings to match some of the CUA's specifications, it does not redefine everything.
On the other hand, Emacs is an end-user reprogrammable application, a software example of a LISP machine. Its configuration language, called Emacs Lisp, can be used to redefined virtually the entire editor.
Emacs also provides one of the most complete Vim emulation modes, called Evil mode. Thus, as there are people who say that Emacs has everything but a text editor, there are others that say that Emacs is a better Vim than Vim itself.
In my case, a combination of Vim and Emacs (using Evil mode) is the one that best suits my necessities. I would recommend it for those who are starting, as it requires learning two advanced text editors. However, I would recommend it for people who are curious to discover a possible way to improve modern systems by allowing end-users to reprogram a system according to their own needs.
Text Editing
Have you installed a text editor or will you use the one provided by your IDE? Great.
There is not much to explain about basic text editing. Almost every editor operates similarly:
- You open the program;
- You create a new file or open an existing one;
- You access the text editing mode, which is the default in most programs;
- You press a key in your keyboard to create content;
- You save the file to persist changes in the disk.
A more sophisticated version could redefine the fourth item as:
- You press a key in your keyboard.
- If the key is a character, its value is stored in the memory and the corresponding character appear in the output device (for instance, a screen);
- If the key is a modifier or dead key, you press another key;
- If the key is an editor shortcut, the editor performs the requested processing.
Concepts
Besides text file, there are few basic terms and concepts that you should know to use a text editor:
- Cursor: it is the current position to read and/or write in a text file. The cursors are commonly represented as a vertical bar (
|
) or a vertical rectangle (▮
), both of which may or may not blink; - Line break: a value that marks the intent of ending the current line to start the next one;
- Line: as in a notebook, it is a vertical offset in the text. A line break marks the position in which a line ends and the next one starts;
- Blank line or empty line: line without content;
- Column: the horizontal direction of a line. A column starts from the first character of the line until the last, marked by the line break. Some (human) languages determine that text flows from the left to the right, while others adopt a right to left flow;
- Position: a combination of line and column;
- Buffer: work memory, usually primary memory, that stores the data being used. The buffer must be saved in secondary memory to avoid data loss before the text editor is closed. It is wise to save the file often, as you never know when adverse situations may happen (such as power outage);
- End of file marker (EOF): special value to mark the end of a file;
- Dead key: a key that, when pressed, noes not result into a character input, as it depends on the next key to determine is value. It is a concept used to write characters that do not have a corresponding key in a keyboard (such as accented characters and diacritics for the most varied (human) languages);
- Leading space: spacing before the first non-blank character of a line;
- Trailing space: spacing before the last non-blank character of a line. This is often removed as it usually does nothing in many programming languages, though they waste space.
Some concepts refer to the term "line break". Although simple, there are some historic inheritances that require discussion.
Line Breaks
A computer does not have concepts for sentences, paragraphs of lines. For a computer, text files store sequences of characters as bytes.
A line break is a possible valid value encoded as a character. When a text editor finds a line break, it draws the next character on the first column of the following line.
The concept is simple, yet operating systems diverge about that is a line break. In the time of typewriters, the action to add a new line on a page required moving the press back to the first column of the paper (carrier return), then scroll down the page and start the next line (line feed).
Some operating systems follow the typewriter convention for new lines. Others, such as Linux, consider that a line feed is enough to make the next character show on the next line.
In the first case, a line break requires two values: a carrier return (CR) and a line feed (LF), resulting in CR LF. In the second case, a line feed is enough, that is, a LF value.
Unfortunately, there are a few text editors that do not handle line breaks in both formats. For instance, Notepad was one of those programs until recently, when it was updated to support LF only on Windows 10. Thus, text files written on Linux machines can appear without new lines in programs such as Notepad in machines that are using older or out of date versions of Windows.
Good Habits
If you use multiple operating systems (or contribute in projects that support multiple operating systems), you should decide if the lines of all your files will end in LF or in CR LF.
You should ideally adopt one format, configure your editor to use salve files using this format and follow the defined standard.
Some version control systems (such as git
) can be configured to use a format locally on the machine and another in the repository, avoiding problems.
Furthermore, there are some programming languages that recommend ending a source code file with an empty line. As there is usually no harm in ending files with an empty line in languages that do not have such recommendation, it can be a good idea to end all files with an empty line. This can be configured in some text editors.
Finally, it is usually a good idea to avoid trailing space. It is also possible to configure automatic removal (trim) in some text editors.
Common Shortcuts
It is recommended to learn shortcuts to support text edition, as they save significant time over programming activities.
Have you learned some shortcuts for file managers? If you have, many of them work similarly for text editing (that is, provided that your editor is not Nano, Vim or Emacs).
General Shortcuts for Text Editing
The following list assumes programs in English. Programs in other languages may have slightly different shortcuts.
Insert
: toggles between the insertion and substitution modes. In insertion, new characters are added to the document, offsetting existing ones. In substitution, new characters replace overwrite existing ones.Backspace
: deletes the character before the cursor;Delete
: deletes the character after the cursor;- Arrows:
Left
: moves the cursor one position (column) to the left;Right
: moves the cursor one position (column) to the right;Up
: moves the cursor one position (line) up;Down
: moves the cursor one position (line) down.
Page Up
: moves the cursor one page up;Page Down
: move the cursor one page down;Tab
: adds a tabulation or the corresponding number of spaces to indent the code to the next level;Shift Tab
: removes a tabulation of the corresponding number of spaces to deindent the previous level;Ctrl
:Ctrl s
: saves the current file;Ctrl o
: opens a file;Ctrl w
: closes the current file;Ctrl n
: opens a new window;Ctrl q
: closes the program;Ctrl f
: searches for a string in the document;Ctrl r
: replaces a string in the document by another of your choice;Ctrl p
: prints the file contents;Ctrl z
: undoes the last action;Ctrl Shift z
orCtrl y
: redoes the last action that has been undone;Ctrl a
: selects the entire content of the file;Ctrl c
: copies the selected content;Ctrl x
: cut the selected content;Ctrl v
: pastes copied or cut content;Ctrl Backspace
: deletes the last word;Ctrl Delete
: deletes the next word;Ctrl Left
: moves the cursor one word to the left;Ctrl Right
: moves the cursor one word to the right.
Shift
:Ctrl Left
: moves the cursor one word to the left;Ctrl Right
: moves the cursor one word to the right;Ctrl Shift Left
: selects one word to the left;Ctrl Shift Right
: selects one word the right.
Alt
:Alt F4
: closes the program.
Take Care of Your Health and Improve Your Skills
When you are young, bad habits can go unnoticed. As you get older, bad habits that repeated continuously can be harmful to your health.
Before you start programming, try to learn the basics of ergonomics.
Ergonomics
It is fundamental to take care of your health. Before you start long term programming activities, it can be wise to learn some basics of ergonomics to help to preserve your health at the long term.
For instance, if you adopt good habits from the beginning of your activities, you may reduce the risks of problems such as Repetitive Strain Injuries (RSI), Carpal Tunnel Syndrome (CTS) and tendinitis. As I am not educated in areas related to health, ideally you should consult a professional to receive more appropriate help.
For more information, you can search for topics as the following suggestions:
- Good posture for the office;
- Good settings for desks, chairs and keyboards;
- Stretches for the hands, fingers and wrists.
I will probably update the suggestions with resources at some time in the future.
Dactylography and Typing
Although it is not fundamental as ergonomics, it can be useful to learn to type correctly at some point in your life. It is not a prerequisite for programming and it can be low priority, though it is a way to preserve the health of your wrists, reduce writing time and, possibly, increase your satisfaction in any activities involving typing text.