62

I am looking for software similar to nano for linux bash but for windows powershell. Is there any built in so I do not have to install something?

EDIT Nano is a text editor that runs within the bash. You can open a text like document (.txt, .c etc) in the bash to edit it on the fly or just view it and close it again.

  • I don't know if this works but maybe it's possible to get edit.com off an XP machine and use it in powershell on windows 7. I don't know if Win7 32bit has edit.com but win7 64bit doesn't have edit.com – barlop Jul 08 '15 at 22:14
  • 1
    Assume someone knows everything about PowerShell and could help you, but doesn't know much about Linux or what Nano may be. Maybe you should describe what you want to do. – Peter Hahndorf Jul 09 '15 at 02:45
  • 1
    @PeterHahndorf You were right, I edited it – John Demetriou Jul 09 '15 at 06:25
  • Also have a look: https://superuser.com/questions/186857/how-do-i-edit-text-files-in-the-windows-command-prompt/1679682#1679682 – aderchox Dec 31 '21 at 19:20

8 Answers8

45

Nano is available for powershell. If you have the Chocolatey package manager installed in your system you can install nano with:

choco install nano

You can install Chocolatey through the command line with:

Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

My personal experience is that it nano performs great in Windows 10 but it's really slow to start up the first time in Windows 7.

Albino Cordeiro
  • 551
  • 1
  • 4
  • 4
  • 3
    choco has an old version of nano though (2.x atm). Git for Windows comes with a newer version (4.9.x atm). – tolache Sep 10 '20 at 10:26
  • 1
    or even better, choco package msys2 includes nano 7.2, which is very up to date (it's the latest version as of right now) – aetonsi Mar 22 '23 at 00:59
38

Just install Windows Subsystem for Linux (WSL). Then, type.

wsl nano

or

wsl nano textfilenametoedit.txt

Quotes are not needed.

Daan
  • 481
  • 8
    This may be obvious to some people, but it tripped me up for a bit: if you're supplying a full path to the file, make sure you pass the path that you would use in WSL, not in Windows. For example, if you want to edit C:\text.txt, instead of using wsl nano C:\text.txt, use wsl nano /mnt/c/text.txt – Matt Apr 12 '19 at 18:30
  • to see the content, wsl cat filename. To see top content: wsl head filename . To see tail content> wsl tail filename – L F May 24 '21 at 15:39
26

There is now a way to use nano and vim with powershell by installing "Bash on Windows". More information on Scott Hanselman blog

From command line you can run

bash -c "vi filename.txt"
bash -c "nano filename.txt"

you can also add those functions to your powershell profile

function vi ($File){
    bash -c "vi $File"
}

function nano ($File){
    bash -c "nano $File"
}

The blog source where I got the information from

phuclv
  • 27,773
11

The only built-in editor in Windows is Notepad. It should already be in your path, so you can just type notepad something.txt in the PowerShell console.

If you want console-based editors, there are some here: https://stackoverflow.com/questions/11045077/edit-a-text-file-on-the-console-in-64-bit-windows

A useful thing to do is to make an alias called "edit" (for example) for your favorite text editor. Put something like this in your profile:

set-alias edit "${env:ProgramFiles}\Sublime Text 3\sublime_text.exe"
dangph
  • 4,833
  • 1
    Newer versions of Windows also have powershell_ise.exe built-in and in the path. A pretty good editor for PowerShell scripts. – Peter Hahndorf Jul 09 '15 at 07:24
  • so no built in powershell editor inside the shell? only external programs that run outside of powershell? – John Demetriou Jul 09 '15 at 07:30
  • 1
    @John Demetriou, I'm not sure what you mean by "built in" now. There are two stock text editors that come with Windows: Notepad and PowerShell ISE (thanks Peter). If you want a console-based editor, then the link above has some. There is no stock, console-based editor in recent versions of Windows. – dangph Jul 09 '15 at 07:43
  • that's what I meant, stock console based editor. ok thanks. I will look in the link you provide and choose. thanks – John Demetriou Jul 09 '15 at 07:58
  • 1
    To use the ISE editor: psEdit \path\to\file.txt ... To switch back and forth between the editor and powershell ctrl + s and ctrl + d – Kellen Stuart Jan 17 '17 at 23:54
  • Using notepad readme is the best solution I've found for creating files on windows where you can control the file extension. – mikey Jan 26 '21 at 18:55
5

Git for Windows (choco pkg) has nano, vim (and prob'ly others) built in. Setting a PowerShell alias/function will make them easier to launch. E.g.:

function nano { C:\Progra~1\Git\usr\bin\nano.exe --ignorercfiles $args }

Place this command in your shell startup script by:

  1. Copying the command above
  2. Paste into powershell console
  3. Run "nano $profile"
  4. Paste again into the script file
  5. Ctl-X to save,exit

EDIT: Changed command to ignore syntax highlighting files (which doesn't work by default). Original command:

set-alias nano C:\Progra~1\Git\usr\bin\nano.exe
Peter L
  • 181
  • 1
  • 3
2

Nano editor has a win32 version, you can download it from here https://nano-editor.org/dist/win32-support/

You can download "nano-git-0d9a7347243.exe" file, rename it to "nano.exe", and add the folder you saved the file in to the environment variable "Path".

1

To add to the answers you've already received, you can have a shell editor in Windows, by installing Vim for windows, from Vim's official page.

https://www.vim.org/download.php

0

Using MSYS and MinGW

Copy the produced binary nano.exe to your environment. You can get this:

From source

I installed MYSYS with MinGW and was able to:

$ pacman -S tar gcc ncurses ncurses-devel
$ f='nano-5.8'  # Change this line for a different v5 version
$ curl --proto '=https' --tlsv1.2 -sSf 'https://www.nano-editor.org/dist/v5/'"$f"'.tar.xz'
$ tar xf "$f"'.tar.xz' && cd "$f"
$ ./configure
$ make  # See './src/nano.exe'

From pre-compiled package

$ pacman -S nano

to get it working in that environment:

From source (patched for Windows)

In case you keep getting Error opening terminal: xterm-256color. errors:

$ pacman -S git
$ git clone https://github.com/lhmouse/nano-win
$ cd nano-win  # tested on `38790067`
$ ./build_nano-win.sh

From archive

Or just download the package directly and add it to your PATH:

https://mirror.msys2.org/msys/x86_64/nano-5.8-1-x86_64.pkg.tar.zst (extract with Modern 7-zip + 7-zip, or unzstd) and exes from nano-5.8-1-x86_64.pkg.tar.zst\nano-5.8-1-x86_64.pkg.tar\usr\bin\ to your PATH, along with (from msys64\usr\bin\ or the archives): msys-ncursesw6.dll, msys-2.0.dll, msys-magic-1.dll, msys-intl-8.dll, msys-iconv-2.dll, msys-bz2-1.dll, msys-z.dll


Test, on cmd.exe (Windows Command Prompt)

> nano --version
 GNU nano, version 5.8
 (C) 1999-2011, 2013-2021 Free Software Foundation, Inc.
 (C) 2014-2021 the contributors to nano
 Compiled options: --enable-utf8

If it works, invocation of nano will look like:

  GNU nano 5.8                        New Buffer
           [ Welcome to nano.  For basic help, type Ctrl+G. ]

^G Help ^O Write Out ^W Where Is ^K Cut ^T Execute ^C Location ^X Exit ^R Read File ^\ Replace ^U Paste ^J Justify ^_ Go To Line

A T
  • 791