Text editor #
Text file #
A text file stores a sequence of characters. These are typically Unicode characters, encoded in UTF-8 (or sometimes UTF-32 or UTF-64).
Most of the files that programmers edit are text files.
Which of the following are text files?
file type | conventional file name extension |
---|---|
an MP3 file | .mp3 |
a JPEG file | .jpeg |
a PDF document | .pdf |
a Microsoft Excel spreadsheet | .xls or .xlsx |
a CSV file | .csv |
a JSON file | .json |
a Microsoft Word document | .doc or .docx |
an Apple Pages document | .pages |
a LibreOffice Writer document | .odt |
a Python source file | .py |
a Java source file | .java |
a compiled Java class | .class |
a Windows executable file | .exe |
a bash script | .sh |
file type | conventional file name extension | is it a text file? |
---|---|---|
an MP3 file | .mp3 |
no |
a JPEG file | .jpeg |
no |
a PDF document | .pdf |
no |
a Microsoft Excel spreadsheet | .xls or .xlsx |
no |
a CSV file | .csv |
yes |
a JSON file | .json |
yes |
a Microsoft Word document | .doc or .docx |
no |
an Apple Pages document | .pages |
no |
a LibreOffice Writer document | .odt |
no |
a Python source file | .py |
yes |
a Java source file | .java |
yes |
a compiled Java class | .class |
no |
a Windows executable file | .exe |
no |
a bash script | .sh |
yes |
Warning. A space is a character. So is a tab, a line break, etc.
Therefore a file ending with a new line is different from the same file without this new line!
Editor #
A text editor is a program used to edit text files.
As a result, a text editor can open any file produced with another text editor (regardless of the file’s extension).
Most operating systems come with one or several text editor(s) pre-installed, such as Notepad++ (Windows), TextEdit (macOS), gedit (default Ubuntu), etc.
Warning (for Windows). Traditionally, text editors for Windows encode a line separator as two Unicode characters (
\r\n
), against a single character (\n
) on most modern systems. On Windows, this is typically hidden to regular users, because many programs apply line breaks normalization procedures (which may depend on the underlying OS).However, this is a source of bugs for developers, in certain scenarios. For instance:
- when generating code,
- when dealing with virtual environments (e.g. a Docker image),
- when sharing code via unconventional means (i.e. not via git),
- etc.
Usage #
Your IDE is an (enhanced) text editor, so you can use it as such. But it some scenarios, it can be useful to use a lighter program, for instance for:
- editing the configuration file of a program,
- modifying a small script (or even a single command-line instruction) copy-pasted from the web,
- etc.
Among other reasons:
- opening an IDE can take time,
- if your IDE has autosave enabled, you may accidentally add unrelated files to your current project,
Advanced text editors #
For this course, a basic text editor is sufficient. But depending on your workflow, you may want to try a more advanced one.
VSCode #
VSCode is introduced in the section dedicated to IDEs.
vi and Emacs #
These are two keyboard-centric editors. Both were developed in the 70’s (before the mouse became a widespread peripheral) but are still commonly used today (in some form) by developers.
We do not recommend learning vi or Emacs at this (early) stage of your studies, because it requires time (and you arguably have more fundamental thing to learn). But you may give them a try at some point of your career, because they can significantly improve your productivity.
vi/vim/neovim #
vi was initially released 1978, as part of the first BSD distribution. The original program is rarely used today, but vim (for “vi improved”), released in 1991, and neovim, released in 2015 are still popular among developers. For instance, 22% (resp. 12%, non-exclusive) of respondents to the 2023 Stack Overflow developer survey use vim (resp. neovim) as a code editor.
vi/vim/neovim is a so-called modal editor, meaning that users can switch between different modes. In one mode, pressing a standard key inserts the corresponding character, whereas in another mode, pressing the same key has a different functionality (navigation, copy, paste, etc.). These functionalities are referred to as vi keybindings or vi motions, and allow performing a variety of text editing operations in an efficient way.
vi keybindings are commonly used in applications other than vi/vim/neovim, with dedicated plugins. For instance, most code editors/IDEs (VSCode, IntelliJ IDEA, Emacs, etc.), terminal emulators or even web browsers have plugins for vi keybindings.
Note. vim and neovim are very customizable, with comprehensive collections of (community-developed) plugins, which allows using them as IDEs. We do not recommend trying this at this stage of your studies, because configuration may require a significant time investment (more than VSCode for instance).
Warning. The original vi still comes pre-installed on many operating systems (Windows, macOS, Linux, …), and may be the default text editor opened by terminal-based applications (e.g. git) on your system. If this is the case (and if you do not know the vi keybindings), then we recommend changing this setting.
Emacs #
Emacs was initially written in 1976. The most popular version is GNU Emacs, released in 91, was notably co-developed by Richard Stallman.
Emacs is partly responsible for popularizing (sequences of) combinations of keys (e.g. Ctrl+<letter>
), as opposed to modal editors like vi.
GNU Emacs has more than 10 000 built-in commands, and also provides a (limited) mouse interface.
5% of respondents to the 2023 Stack Overflow developer survey use Emacs as a code editor.
Emacs is also very customizable, with a comprehensive collections of (community-developed) plugins (probably more comprehensive than vim), and dedicated software repositories. Notably, Emacs tends to serve as a unique user interface for a variety of tasks (code editing, terminal emulation, email management, web browsing, playing music/videos, etc.).
Note. Emacs can be used as an IDE, but for the same reason as for vim or neovim, we do not recommend trying this at this stage of your studies.