filo/DigitalVision Vectors via G
Linux text editor tips for cloud admins using Vim and Nano
Vim and Nano are common Linux text editors that can help cloud admins manage cloud-based Linux VMs. While the tools might seem overwhelming, a few basic skills can go a long way.
They say the cloud runs on Linux, and that's pretty much true. However, cloud infrastructure also runs many Linux VMs, and many of these VMs are managed by administrators whose primary experience is with Windows systems. It can be challenging for these admins to understand some of Linux's quirks from a Windows perspective.
One critical aspect of Linux administration is managing the text files used for network, performance and security settings. Cloud-based Linux VMs are primarily command line only, so users must be comfortable with nongraphical text editors.
The two predominant Linux text editors are Vim and Nano. Vim has long been the default editor for many distributions, but Nano's simplicity and intuitiveness has attracted a major following. Understanding both editors is important because cloud vendors support many Linux distributions on their VMs. These editors must be installed on the Linux system so they run over an SSH remote admin session.
This article reviews the basic skills necessary for those who interact with cloud-based Linux systems. It's a good idea to master the simple skills outlined here for both editors, as it's possible to encounter either one in the wild. Remember that you need the appropriate privileges to edit configuration files. While delegating control and setting permissions are outside the scope of this article, they are critical concepts.
Using Vim
The Vim text editor is on most Linux distributions, but I use it on my Mac and have even installed it on Windows systems. Vim is quirky, and many of its functions are not intuitive. But, once users get the hang of a few key components, they realize how efficient it can be. One of Vim's essential concepts is keeping the user's hands on the keyboard for efficiency.
Vim modes
Probably the oddest aspect of Vim is the modes it relies on to switch between entering text and manipulating a document. The two primary modes to know are Command and Insert:
- Command mode. Maps the keyboard to Vim management commands. Pressing keys on the keyboard manipulates the file. This is how you save file contents, for example.
- Insert mode. Maps the keyboard to the document contents. Pressing keys on the keyboard affects the actual file content. This is how you type or delete words from the file.
Some Command mode options affect the contents, such as moving or deleting lines of text.
Vim launches in Command mode, so you must switch to Insert mode before users can enter or change the file contents. Vim provides multiple ways to get into Insert mode. For now, just remember lowercase i for Insert. Use fancier commands as you get more comfortable with the editor.
i puts Vim in Insert mode, enabling you to enter or remove text in the file.
Press the ESC key to leave Insert mode and return to Command mode.
ESC puts Vim back in Command mode. If you're unsure of what mode you're in, press ESC.
Vim also offers a command line as an additional file management method. While in Command mode, press : (colon) to open a prompt. Users can enter commands that save their file or exit the program, among others.
Don't worry if this sounds overwhelming. It only takes a few basic Vim commands to manage files on cloud-based Linux VMs. Any additional tasks only make users more efficient.
Vim basics
The first and simplest Vim skill to master is creating or opening a file. Type the vim command followed by the name of the file you wish to open or create. Vim launches in Command mode and displays the file contents. The file is empty if it is new.
Assuming a blank new file, press lowercase i to enter Insert mode. Notice the indicator in the lower left corner changes to display Insert. Pressing keys at this point enters text into the file.
Navigate within the document using the arrow keys. There are many tricks to move around inside long documents, such as the following:
- gg to jump to the top.
- G to jump to the bottom of the file while in Command mode.
It's best not to get overwhelmed too quickly, however, and focus on using the arrow keys at first.
Once you add the text you need, it's time to save the document. Press ESC to return to Command mode, and then press :w for a command prompt with the w command -- w stands for write, which is another way of saying save. You can go back to Insert mode to continue entering text or exit Vim.
Type :q from Command mode to quit Vim. Note that Vim doesn't let you close an unsaved file without an explicit action. To close a file without saving changes, type :q! from Command mode. Another quick shortcut is to type :wq to save the file and exit Vim simultaneously.
Here's a quick summary of basic Vim actions:
- Type vim {filename} to open the file.
- Press lowercase i to enter Insert mode, and then begin typing text.
- Press ESC to leave Insert mode and return to Command mode.
- Press :w to save the file, and then press :q to exit Vim.
- Press :wq to save the file and exit Vim.
Practice these techniques in your cloud VMs, and you can accomplish minimal text editing for Linux configuration files or other documents. You can establish a secure remote SSH connection to access Vim, assuming it's installed on the target cloud VM.
Using Nano
Many IT pros are used to application menus to guide them through using a program, which might make Nano seem more straightforward than Vim. Nano lists common shortcuts in a menu at the bottom of the interface.
Like Vim, Nano functionality is enabled by keystrokes. Activate the common commands using the Ctrl key and another character.
Nano basics
Open a new or existing file in Nano by typing nano {filename} on your Linux VM. Unlike Vim, Nano does not have modes, so users can begin entering text immediately. Navigate through the file contents using the arrow keys.
When users are ready to save their changes, they can press the Ctrl+O keys. Nano displays a prompt to confirm the file name, so press Enter to do so. This saves any changes to the file. Exit Nano by pressing the Ctrl+X combination.
Many distributions ship with Nano instead of Vim -- or alongside it -- due to its user-friendly and basic approach. Nano is simpler, but it's not as powerful, feature-rich or extensible as Vim. However, Vim's extra capability is only helpful if users need it. Though I prefer Vim, I find myself reaching for Nano when I need to make a simple change to a network or security configuration file. Like Vim, admins can use Nano across SSH connections if it's installed on the remote VM.
Vim is highly customizable and extensible. Users can add plugins to support various programming languages, spell-checking and more. Various other editors exist in the Linux world, but Vim and Nano are the main ones users encounter. Mastering the basic skills of creating, authoring, saving and exiting files with both tools takes users a long way when supporting cloud VMs.
Damon Garn owns Cogspinner Coaction and provides freelance IT writing and editing services. He has written multiple CompTIA study guides, including the Linux+, Cloud Essentials+ and Server+ guides, and contributes extensively to TechTarget Editorial, The New Stack and CompTIA Blogs.