Editing Files

in Windows

📝 Using Notepad

So far we've discussed how to read and modify files, but we haven't covered how to edit file contents yet. Spoiler alert, you're about to learn, you can edit text-based files in Notepad, which we used earlier to view a text file. Notepad is great for basic editing.

💻 Using Notepad++

But when making changes to configuration files, scripts, or other complex text files, you might want to use something with more features. There are lots of good editors out there for the Windows GUI. For this demonstration, we'll use one called Notepad++.

Notepad++, which you can access from the next supplemental reading, is an excellent open-source text editor with support for lots of different file types. Notepad++ can open multiple files and tabs, and it also does syntax highlighting for known file types, and has a whole bunch of advanced text editing features.

Syntax highlighting is a feature that a lot of text editors provide. It displays text in different colors and fonts to help you categorize things differently. We've already installed Notepad++ on our machine, so you can check out their website and do the same.

Now you can edit any file using Notepad++ by right-clicking it and selecting "Edit with Notepad++".

🖋️ Editing Files from the CLI

What if you wanted to edit a file from the CLI? Unfortunately, there's no good default editor in the PowerShell terminal, but we can launch our Notepad++ text editor from the CLI and begin modifying text that way. So start Notepad++, and then just a file name. As you can see, it opened up Notepad++, and asked if I wanted to create this file.

🐧 Editing Files in Linux

📝 Using Nano

In Linux, there are many popular text editors that we can use to modify files. We won't have enough time to cover them all, so let's just focus on one editor that can be found on virtually any distribution: Nano.

Nano is an extremely lightweight but useful text editor. To edit a file in Nano, just type nano followed by the filename. Once we do that, we'll be launched into the Nano program.

From here, we can start editing the content as we normally would with any other text editor. At the bottom of the screen, you'll notice a few options like ^G and ^K. The ^ means to use Control + the corresponding key.

We won't talk about all these options, but a few that might be useful are ^G, which helps open up a help page, and ^X, which is used when you want to save your work or exit from Nano.

💾 Saving Changes

Let's go ahead and edit this file, then save our changes. It's asking me if I want to save the file or exit and discard my changes. I'm just going to hit Y because I want to save them. Once I do that, I'll be exited from Nano.

🔍 Verifying Changes

Let's verify we actually changed that file. 🥳 There it is! Nano is a super useful tool if you need a quick text editor in Linux.

Last updated