From Basics to Mastery: Exploring the Features of nano and vim Text Editors
Tags: 120dayofdevops, nano, vim
Published: 2023-06-19 17:17:54



## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3um9y27hk46vpu5uv0h6.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8g7g1ebetkr5m83e164y.png)

## 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6t90ccweey37eoby2kbk.png)
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 `insert `we need to press` i` if you have added some text and would like to save these changes then you would hit escape and then` :wq`

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vf2fmvv5hnrmxarn9jrd.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1p45gewkegm2hzt1n8zd.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjim8eng1soxhl0kl2k3.png)
Now we want to replace that word with 120DaysOfDevOps, we can do this by hitting ESC and typing :%s/Day/120DaysOfDevOps

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsvms0nh83icxsb367kk.png)

One of the eye-opening moments I had with `vim` was discovering its unique terminology for copying and pasting. Instead of "`copy`," `vim `uses 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

- [Vim in 100 Seconds](https://www.youtube.com/watch?v=-txKSRn0qeA)

- [Vim tutorial](https://www.youtube.com/watch?v=IiwGbcd8S7I)