Intro
So I was looking for some lightweight editor as alternative to VS Code, because I often need to quickly edit text files right from Windows Terminal. Luckily I knew nano from linux and in this post I’ll show you how to use it in Windows Terminal.
Editing inside Windows Terminal
In order to use nano in WT, we have to install it first. We have two options, either use nano trough wsl or install only nano separately using chocolatey.
nano in WSL
If you haven’t installed wsl, follow these instructions – https://docs.microsoft.com/en-us/windows/wsl/install-win10. First let’s make sure nano
is installed in your linux distro. Run wsl nano
, if you see message nano: command not found
, run following code to install it(keep in mind that these steps may difer in your linux distro):
1 2 |
wsl sudo apt update wsl sudo apt install nano |
After you successfuly installed nano inside wsl, you can simply use it whenever you need:
1 |
wsl nano Restart-PrintSpooler.ps1 |
Standalone nano
I personaly prefer using standalone nano
. In order to install it, you need to have chocolatey. If you don’t, follow these install instructions – https://chocolatey.org/install. Then, to install nano
itself, run following snipet as administrator:
1 |
choco install nano |
Now you can use nano like in wsl:
1 |
nano .\PowerShell_profile.ps1 |
To exit file press CTRL+X.
Viewing files inside Windows Terminal
Viewing files in PowerShell or Windows Terminal is simple, we can use Get-Content
cmdlet or cat
e.g. cat .\movies.txt
.
Bonus – cat with syntax highlighting
First you need to install python and pip – https://phoenixnap.com/kb/install-pip-windows. Then you can run:
1 |
sudo pip install pygments |
Then we need, to add function to PowerShell profile, as alias for pygmentize
command, run nano $PROFILE
, paste following function:
1 2 3 4 5 6 7 8 |
function scat { param( [Parameter(Mandatory = $true, Position = 0)] [string]$File ) pygmentize -g -O style=colorful,linenos=1 $File } |
hit CTRL+X, Y and Enter. Finally run . $PROFILE
to reload PS profile. Now you can enjoy syntax highlited cat using:
1 |
scat .\PowerShell_profile.ps1 |
Congratulations, you’ve successfuly installed nano editor and you can enjoy editing in Windows Terminal. Happy coding!