---
title: "How to Edit Files with a Real PowerShell Text Editor"
description: "Tired of switching between PowerShell and the text editor windows? Why not use a PowerShell text editor instead? Learn how in this step-by-step tutorial"
canonical: "https://adamtheautomator.com/powershell-text-editor/"
---

# How to Edit Files with a Real PowerShell Text Editor

> Tired of switching between PowerShell and the text editor windows? Why not use a PowerShell text editor instead? Learn how in this step-by-step tutorial

Source: https://adamtheautomator.com/powershell-text-editor/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/wp-content/uploads/2021/10/How-to-Edit-Files-with-a-Real-PowerShell-Text-Editor.jpg)

# How to Edit Files with a Real PowerShell Text Editor

[![](https://secure.gravatar.com/avatar/30af83d8e9a0cf63ad11cbd348c7fdbcb01d92ac46d70d18c96585b7304f3ced?s=192&d=mm&r=g)Amanda Punch](https://adamtheautomator.com/author/amanda-punch/)27 October 20219 min. read

Categories: [DevOps](/category/devops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Using Nano as a PowerShell Text Editor](#using-nano-as-a-powershell-text-editor)
*   [Installing Nano](#installing-nano)
*   [Editing and Saving a File](#editing-and-saving-a-file)
*   [Searching and Replacing Text](#searching-and-replacing-text)
*   [Using Vim as a PowerShell Text Editor](#using-vim-as-a-powershell-text-editor)
*   [Installing Vim](#installing-vim)
*   [Editing and Saving a File](#editing-and-saving-a-file-1)
*   [Searching and Replacing Text](#searching-and-replacing-text-1)
*   [Using Emacs as a PowerShell Text Editor](#using-emacs-as-a-powershell-text-editor)
*   [Installing Emacs](#installing-emacs)
*   [Editing and Saving a File](#editing-and-saving-a-file-2)
*   [Searching and Replacing Text](#searching-and-replacing-text-2)
*   [Conclusion](#conclusion)

Did you run a script that read a text file and discover that the file had several wrong entries? A PowerShell text editor may come in handy in such situations. You wouldn’t need to fire up an external editor. Instead, you can edit the file without leaving PowerShell. How cool is that?

Keep reading, and you will learn how to install and use three text editors ([Nano](https://www.nano-editor.org/), [Vim](https://www.vim.org/), and [Emacs](https://www.gnu.org/software/emacs/)) to edit your text files within PowerShell. This tutorial will also cover the benefits of each to help you choose which one is ideal for you.

Let’s get started!

## Prerequisites

This tutorial will be a hands-on demonstration. If you’d like to follow along, be sure you have the following:

*   A computer running on Windows 7 or higher. The examples in this tutorial will use Windows 10 version 21H1.
*   Windows PowerShell v3+ or [PowerShell Core v6+](https://github.com/PowerShell/PowerShell#get-powershell). This tutorial will use Windows PowerShell version 5.1.
*   The latest version of [Chocolatey](https://chocolatey.org/install) (v0.11.2 as of the writing of this tutorial).

Related:[The 10 Basic PowerShell Commands You Need to Know](https://adamtheautomator.com/basic-powershell-commands/)

## Using Nano as a PowerShell Text Editor

If you are new to terminal-based text editors or only need to make a quick edit to a file, _Nano_ is ideal for you. Nano is lightweight, intuitive, and more suited for light text editing tasks compared to the other more advanced editors in this tutorial.

### Installing Nano

To install Nano, follow the steps below.

1\. [Open PowerShell as an Administrator](https://adamtheautomator.com/powershell-run-as-administrator/).

2\. In PowerShell, execute the following [`choco install`](https://docs.chocolatey.org/en-us/choco/commands/install) command to install the Nano text editor. The (`-y`) switch will bypass the confirmation prompt and proceed with installing the package.

```powershell
choco install nano -y
```

The installation process would look similar to the screenshot below. As you can see, in this example, the Nano installation was successful.

![Installing Nano](https://adamtheautomator.com/wp-content/uploads/2021/10/image-259.png)

Installing Nano

3\. After installing Nano, run the following command to verify the installation was successful and display the current version.

```powershell
nano --version
```

As you can see below, the command was successful and displayed the Nano version on your computer.

![Verifying the Nano version](https://adamtheautomator.com/wp-content/uploads/2021/10/image-260.png)

Verifying the Nano version

### Editing and Saving a File

Now that you have Nano installed, it’s time to take it for a spin!

1\. To create a new file or open an existing one, run the `nano` command and follow it with the filename to create or open. For the examples in this tutorial, you will be creating and editing a Windows PowerShell script, which uses the _[.ps1](https://fileinfo.com/extension/ps1)_ file extension. The command below will create a new file called _myPowerShellScript.ps1_ on the current directory.

```powershell
nano myPowerShellScript.ps1
```

The Nano text editor will open within PowerShell. As you can see on the image below, near the bottom says **\[New File\]**, indicating the Nano has opened a new empty file.

![The Nano editor screen ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-261.png)

The Nano editor screen

> _To view all available shortcut commands, press `CTRL+G` on your keyboard to display the help documentation. Commands that start with `^` means that you have to press the `CTRL` key. On the other hand, if the command starts with `M`, you need to press the `ALT` key._

2\. Next, start writing your script using the arrow keys on your keyboard to move the cursor. For example, type in the Windows PowerShell command `Write-Host "Hello World!"` as shown in the following image. When executed, this command will print out the text _“Hello World!”_ to the console.

Notice that once you modify the file’s content, the word **Modified** appears on the top-right corner of the editor. After editing, press `CTRL+O` to tell Nano that you want to save the file.

![Using the Write-Out shortcut ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-262.png)

Using the Write-Out shortcut

3\. Nano prompts you to enter the file name to write the changes. Press Enter to confirm.

![Saving the file](https://adamtheautomator.com/wp-content/uploads/2021/10/image-263.png)

Saving the file

4\. Finally, to exit Nano, press `CTRL+X`.

> _If you try to exit the editor while there are pending changes, Nano will ask you to save or ignore the changes. If you choose to save, press `Y` and specify the filename to write as you did in step 3. Otherwise, press `N` to discard the changes._

![Exiting Nano](https://adamtheautomator.com/wp-content/uploads/2021/10/image-264.png)

Exiting Nano

5\. Now run your script by executing the following command. The following command assumes your file is in the C:\\ folder.

```javascript
& C:\myPowerShellScript.ps1
```

The script will print the message _‘Hello World!’_ to the terminal, as shown in the following image.

![Output of the script](https://adamtheautomator.com/wp-content/uploads/2021/10/image-265.png)

Output of the script

### Searching and Replacing Text

Now that you know how to edit and save a file, it’s time to learn to do something slightly more advanced: searching for and replacing strings!

To search for a string, follow these steps.

1\. First, open the text file in the Nano editor, if not open yet.

2\. Once you’ve opened the text file, press `CTRL+W` on your keyboard to invoke the **`Where Is`** command.

3\. Next, type the string to search for next to the Search prompt and press Enter. The example below will search for the word _Hello_.

![Searching for a string](https://adamtheautomator.com/wp-content/uploads/2021/10/image-266.png)

Searching for a string

If the string exists in the file, your cursor will move next to it, as shown below.

![Finding the string](https://adamtheautomator.com/wp-content/uploads/2021/10/image-267.png)

Finding the string

To search and replace a string, proceed as follows.

1\. Press `CTRL+\` on your keyboard to open the search and replace menu. Next to the **Search (to replace)** prompt, type the string you wish to replace, and press Enter.

![Searching for the word 'Hello'](https://adamtheautomator.com/wp-content/uploads/2021/10/image-268.png)

Searching for the word ‘Hello’

2\. Next, at the **Replace with** prompt, type the new word and press Enter. In the example below, the replacement word will be _Goodbye._

![Replacing the word](https://adamtheautomator.com/wp-content/uploads/2021/10/image-269.png)

Replacing the word

3\. Lastly, choose to replace only the current instance or all instances of the matching word in the file. The choices are:

*   To replace the single instance, press `Y`.
*   To replace all instances, press `A`.
*   To skip this instance, press `N`.
*   To cancel the replace operation, press `CTRL+C`.

In this example, press `Y` to replace the current instance.

![Confirming the search and replace operation ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-270.png)

Confirming the search and replace operation

Nano will state the number of occurrences replaced if the replace operation is successful, as shown in the following image.

![Replace occurrence count](https://adamtheautomator.com/wp-content/uploads/2021/10/image-271.png)

Replace occurrence count

4\. Press `CTRL+X` on your keyboard to exit Nano and press `Y` to save the buffer. Re-run your script. The new message _‘Goodbye World!’_ will be printed in your terminal.

![The script output](https://adamtheautomator.com/wp-content/uploads/2021/10/image-272.png)

The script output

## Using Vim as a PowerShell Text Editor

Vim offers more features than Nano, such as session recovery, syntax coloring, window splitting, and auto-completion. Nano is meant for quick file edits, while Vim is also a lightweight alternative to an IDE.

But, the extra features Vim offers come at the cost of a steeper learning curve. Don’t get discouraged, though. Vim is an excellent editor to learn.

### Installing Vim

Now it’s time to get started by installing Vim.

[1\. Open PowerShell as an Administrator](https://adamtheautomator.com/powershell-run-as-administrator/).

2\. In the PowerShell terminal, execute the following command to install the Vim editor.

```powershell
choco install vim -y
```

3, To verify the Vim version, run the following command. `vim --v`

```powershell
vim --version
```

![ Verifying the Vim version ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-273.png)

Verifying the Vim version

### Editing and Saving a File

Now that you have Vim installed, it’s time to get your hands dirty and learn to edit a file. Before you go any further, you should know that there are different modes in Vim. Each mode behaves differently and affects which actions you can do inside the editor.

The three commonly-used modes are:

*   **Normal** – The default mode as soon as you open Vim. This mode allows you to navigate the text file but not add new texts.
*   **Insert** – This mode is where Vim allows you to edit the file. To enter this mode, press `i` (case insensitive) on the keyboard. To exit and go back to the normal mode, press `ESC`.
*   **Command** – In this mode, Vim lets you invoke commands such as save the file, quit Vim, or view the [help document](https://vimhelp.org/), among others.

Moving on to editing a file in Vim, follow the steps below.

1\. To open a file in Vim, run the `vim` command followed by the filename to open. The command below opens the _myPowerShellScript.ps1_ file.

```powershell
vim myPowerShellScript.ps1
```

The vim text editor will open, as displayed in the following image. Note that the PowerShell command _‘Write-Host’_ and the message _‘Hello World!’_ display in different colors, as Vim supports syntax coloring.

![The Vim opening view in normal mode](https://adamtheautomator.com/wp-content/uploads/2021/10/image-274.png)

The Vim opening view in normal mode

> _If you need to view the Vim help document, type `:h` and press Enter. Pressing the `:` character while in normal mode switches Vim to command mode, while `h` means to open the help file. To exit the help document, type `:q` and press Enter to return to normal mode._

Next, enter the _insert_ mode by pressing `i`. As you enter the _insert_ mode, the text `-- INSERT --` appears at the bottom of the editor, as shown in the following image.

![Vim in insert mode](https://adamtheautomator.com/wp-content/uploads/2021/10/image-275.png)

Vim in insert mode

3\. Now that you are in insert mode edit the file as you wish. The arrow keys will let you move the cursor inside the editor.

4\. After editing, press `Esc` to return to normal mode.

5\. Type the command `:wq` and press Enter to save and close the file. The command `w` saves the files while `q` exits Vim.

![Saving the file and existing Vim](https://adamtheautomator.com/wp-content/uploads/2021/10/image-276.png)

Saving the file and existing Vim

### Searching and Replacing Text

Follow the steps below to search for strings in Vim.

1\. Open the file you want to edit in Vim.

2\. On the Vim editor, to search for a string, run the command below, where `<string>` is the string you want to search.

```powershell
:/<string>
```

For example, to search for the word Hello, type:

```powershell
:/Hello
```

Vim will highlight the matching words, as shown in the following image.

> _To iterate through multiple instances of the matching texts, press `n` to move to the next occurrence or the `N` key for the previous occurrence._

![Vim highlighting the matching words](https://adamtheautomator.com/wp-content/uploads/2021/10/image-277.png)

Vim highlighting the matching words

3\. Lastly, to replace every instance of a string in the entire file, run the command below, where `<old>` is the text to replace and `<new>` is the replacement text.

```powershell
:%s/<old>/<new>/g
```

For example, the command below will replace the word _Hello_ with the word _Goodbye_.

```powershell
:%s/Hello/Goodbye/g
```

![Performing a search and replace in Vim ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-278.png)

Performing a search and replace in Vim

As a result, Vim replaces the text as you can see below.

![Vim showing the search and replace results](https://adamtheautomator.com/wp-content/uploads/2021/10/image-279.png)

Vim showing the search and replace results

4\. Type the command `:wq` and press Enter to save and close the file. Re-run the script. The output will display your new message.

![The script output](https://adamtheautomator.com/wp-content/uploads/2021/10/image-280.png)

The script output

## Using Emacs as a PowerShell Text Editor

Like Vim, Emacs offers more features than Nano. Moreover, Emacs is also an [Integrated Development Environment (IDE)](https://www.codecademy.com/articles/what-is-an-ide). Some of Emacs’ features include syntax coloring, editing multiple files simultaneously, and auto-indentation.

Another benefit of Emacs over the other editors in this tutorial is Emacs is modeless. Emacs is also fully customizable. If there is something that Emacs does not offer, you can add support for it yourself using [Emacs Lisp](https://www.gnu.org/software/emacs/manual/html_node/elisp/).

### Installing Emacs

Follow the steps below to install Emacs.

1\. [Open PowerShell as an Administrator](https://adamtheautomator.com/powershell-run-as-administrator/), if you haven’t yet.

2\. In the PowerShell terminal, run the following command to install Emacs using Chocolatey. `choco install emacs -y`

```powershell
choco install emacs -y
```

3\. Run the following command to verify the Emacs version that you installed. `emacs --version`

```powershell
choco install emacs -y
```

You should see an output similar to the image below showing the Emacs version on your computer.

![Displaying Emacs version](https://adamtheautomator.com/wp-content/uploads/2021/10/image-281.png)

Displaying Emacs version

### Editing and Saving a File

So you’ve installed Emacs. What next? Dive in and start editing a text file to see Emacs in action. Follow the steps below to edit and save a text file.

1\. To open a file in Emacs, run the `emacs` command followed by the filename in PowerShell. The command below opens the file myPowerShellScript.ps1 for editing. The `-nw` switch tells `emacs` to open the editor within the current terminal window (PowerShell) and not in a separate GUI. `emacs -nw myPowerShellScript.ps1`

```javascript
emacs -nw myPowerShellScript.ps1
```

> _Several dropdown menus will be available at the top of the editor. To view the Emacs help documentation, click the Help dropdown menu._

![Opening a file in Emacs](https://adamtheautomator.com/wp-content/uploads/2021/10/image-283.png)

Opening a file in Emacs

2\. Edit the file as you wish and once you’ve completed your edits, save the changes by pressing `CTRL+X` and `CTRL+S` consecutively. You will see the file save confirmation at the bottom of the editor, as shown below.

![Saving the file](https://adamtheautomator.com/wp-content/uploads/2021/10/image-284.png)

Saving the file

3\. To exit the editor, press `CTRL+X` on your keyboard, followed by `CTRL+C`.

### Searching and Replacing Text

Now that you know the basics of Emacs, how running a search and replace operation? Follow the steps below to do so.

1\. Press `CTRL+S` and type in the text to search next to the `I-search` prompt to search for a text. The example below searches for the word _Hello_.

![Searching for text](https://adamtheautomator.com/wp-content/uploads/2021/10/image-285.png)

Searching for text

2\. To initiate the search and replace option, press `ALT+%` on your keyboard (the same as `ALT+SHIFT+5`).

3\. Next, type the text to search next to the **Query replace:** prompt and press Enter.

![Searching for the text to replace](https://adamtheautomator.com/wp-content/uploads/2021/10/image-286.png)

Searching for the text to replace

4\. Next, type the replacement text next to the prompt and press Enter.

![Entering the replacement text ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-287.png)

Entering the replacement text

5\. Finally, at the **Query replacing <old text> with <new text>:** prompt, press **`!`** to confirm and replace all occurrences of the text.

![Replacing all instances of the matching text ](https://adamtheautomator.com/wp-content/uploads/2021/10/image-288.png)

Replacing all instances of the matching text

As a result, Emacs replaced the text, as you can see below. Additionally, Emacs shows the number of occurrences of the text it replaced at the bottom of the editor.

![Emacs replaced the search text](https://adamtheautomator.com/wp-content/uploads/2021/10/image-289.png)

Emacs replaced the search text

6\. Exit the editor by pressing `CTRL+X` on your keyboard, followed by `CTRL+C`. Re-run the script. The output will display your new message.

![The script output](https://adamtheautomator.com/wp-content/uploads/2021/10/image-290.png)

The script output

Related:[5 PowerShell Script Examples To Inspire You to Get Scripting](https://adamtheautomator.com/powershell-script-examples/)

## Conclusion

Throughout this tutorial, you have learned the basics of using three PowerShell text editors and the benefits of each. Next time you have to edit a file from the terminal, do not waste time setting up an external text editor. Simply open Nano, Vim, or Emacs and make your changes in a few keystrokes!

Which PowerShell text editor did you like best? Do you know of other text editors that weren’t in this tutorial?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-text-editor%2F&text=How%20to%20Edit%20Files%20with%20a%20Real%20PowerShell%20Text%20Editor)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-text-editor%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-text-editor%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/featured_image-20.png)

### [Deploy Enterprise PowerShell Modules Using Azure Artifacts](/deploy-enterprise-powershell-modules-using-azure/)

Build a private PowerShell repository using Azure Artifacts with automated CI/CD publishing, semantic versioning, code signing, and JEA integration for secure enterprise module distribution.

![](https://adamtheautomator.com/wp-content/uploads/2025/01/featured-image-5.webp)

### [Build a Scalable PowerShell Pester Testing Framework](/powershell-pester-testing-framework/)

Learn how to create a maintainable and organized Pester testing framework for PowerShell that scales with your needs. Perfect for large test suites.

![](https://adamtheautomator.com/wp-content/uploads/2021/10/The-10-Basic-PowerShell-Commands-You-Need-to-Know.jpg)

### [The 10 Basic PowerShell Commands You Need to Know](/basic-powershell-commands/)

If you’re new to PowerShell and don’t know where to start, then look no further. Learn these 10 handy basic PowerShell commands in this tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
