DEV Community

Cover image for From Basics to Mastery: Exploring the Features of nano and vim Text Editors
UWABOR KING COLLINS
UWABOR KING COLLINS

Posted on

From Basics to Mastery: Exploring the Features of nano and vim Text Editors

Introduction

In the realm of Linux systems, where GUIs are often absent, the ability to edit configuration files becomes vital for making changes and customizing the system. With a plethora of options available, it's essential to focus on the two most prevalent terminal text editors: nano and vim. Having personally experienced both, I've found that nano serves as the easy button for quick changes, while vim boasts an extensive range of capabilities. Join me on this journey as we delve into the features of these powerful text editors and unlock the potential for mastering your Linux environment.

nano

  • Not available on every system.
  • Great for getting started.

If you run nano 120DaysOfDevOps.txt we will create a new file with nothing in, from here we can add our text and we have our instructions below for what we want to do with that file.

Image description
With the use of a simple command, Control + X, followed by Enter, we can create a new text file. Give it a try and run the command "ls" to view the presence of our newly created file.

Image description

vim

When it comes to text editors, one name stands out as possibly the most ubiquitous choice:vim. It's the sibling of the venerable UNIX text editor vi, dating all the way back to 70s. What makes vim so widely supported is its remarkable functionality, making it a staple on virtually every Linux distribution.

In fact, vim is so powerful that you can easily find comprehensive 7-hour courses dedicated solely to mastering its intricacies. To start using vim, simply enter the command "vim" in your terminal. If you wish to edit our newly created text file, you can run "vim 120DaysOfDevOps.txt." However, you might notice the absence of help menus at the bottom, which can be a bit disorienting at first.

Now, the burning question: How do you exit vim? Well, if you haven't made any changes, all you need to do is press the Escape key and then type ":q". This will gracefully exit vim without saving any modifications.

Image description
You start in normal mode, there are other modes command, normal, visual, insert, if we want to add the text we will need to switch from normal to insertwe need to pressi if you have added some text and would like to save these changes then you would hit escape and then:wq

Image description

Image description
To confirm that you have indeed saved the changes made in vim, you can use the "cat" command to inspect the contents of the file and ensure the modifications are reflected.

One of the remarkable aspects of vim is its ability to perform tasks swiftly through the use of shortcuts. There are numerous shortcuts available, each designed to streamline your editing experience. Let's consider a scenario where we have a configuration file containing repeated words, such as the word "DevOps." Now, let's imagine that the network name has changed, and we need to quickly update all instances of "day" to reflect this modification. Vim provides efficient tools to accomplish this task rapidly, ensuring seamless editing even in complex scenarios.

Image description
Now we want to replace that word with 120DaysOfDevOps, we can do this by hitting ESC and typing :%s/Day/120DaysOfDevOps

Image description

One of the eye-opening moments I had with vim was discovering its unique terminology for copying and pasting. Instead of "copy," vimuses the term "yank." In normal mode, you can yank a line by pressing "yy" on your keyboard. To paste the yanked content, use "p" to paste it on the same line or "P" to paste it on a new line.

Deleting lines is also a breeze in vim. By specifying the number of lines you wish to delete, followed by "dd," you can swiftly remove them from your file.

When it comes to searching within a file, you have options beyond using grep. Vim itself provides a convenient way to search. Simply use the forward slash ("/") followed by the word you want to search for. The first match will be highlighted, and you can navigate to subsequent matches using the "n" key.

These examples only scratch the surface of vim's capabilities. The best advice I can give is to get hands-on experience and use vim whenever possible. Familiarity and practice will enhance your proficiency with this powerful text editor.

Resources

Top comments (1)

Collapse
 
devopsking profile image
UWABOR KING COLLINS

Can't wait to continue tomorrow