Nano, Vim and Emacs editors are used to edit files on the command line. In most cases, only Vim is installed in the system, so it's extremely important to have basic skills in handling it. These editors run directly in the terminal, although Vim and Emacs have a mode where they run as separate applications.
Nano
Nano is a very simple text editor, similar to Notepad in Windows, although it's richer in features and can even highlight the contents of files.
nano .bashrc
After starting the editor, a panel will open at the bottom with hints as to which hotkeys you can use. The symbol ^
stands for the Ctrl key. For example, to exit the editor you have to press Ctrl + x, and then either confirm that you want to save your changes or reject them by pressing y (yes) or n (no). In principle, there's nothing else of interest we can say about nano. It's suitable for simple changes in files, but not exactly comfortable to work with on multi-file projects, or even with code.
Vim
Vim (Vi Improved), however, is a completely different beast, it's a free text editor based on the older vi (visual editor). This is a combined editor, which, in addition, works nothing like any other program.
vim .bashrc
The key difference (and there are many!) between vim and other editors is that vim has modes. In normal editors, once a file is open, you can start editing right away. Vim, once opened, operates in COMMAND mode: pressing any key is perceived as a signal for an action. If you don't know the commands, it's better not to touch anything, otherwise the screen will get a little chaotic. Normal text editing is done in INSERT mode and can be accessed by pressing the i key. To exit to command mode, just press Esc (or Ctrl + [).
The above picture is a joke, but there is some truth to it. Vim is rightly considered the editor with the highest entry threshold. On the other hand, the further you advance in your programming career, the more you will begin to notice that experienced and many well-known programmers prefer to develop entirely in vim. When you are looking at vim without plugins, it's hard to imagine that it can become quite complex almost IDE utility due to extensions.
They say that the hardest thing about vim is exiting, so let's prepare in advance. Make sure that you are in command mode, i.e., press Esc (or Ctrl + [) just in case. Next type :
, this command will take you to command line mode (another mode), then type q!
and press Enter. That way you can exit vim without saving your changes. If you type :wq
, all changes will be saved before you exit. If you just want to save without exiting, then press :w
.
Vim has four basic modes of operation:
- Command mode (normal mode) is the default mode. This mode is for moving around the file, quick editing (with commands and keyboard shortcuts), deleting, and text searching.
- Insert mode (input mode) - for text input from a keyboard. The way you're probably used to doing it in normal editors.
- Visual mode - highlights chosen parts of the text.
- Command Line Mode is its own command line for the text editor, which you can use to execute a wide variety of commands.
By the way, most of Hexlet as a platform and almost all of the text content (courses) are made using vim. Including this line ;)