197

On Unix I'd just use vi, but I don't know what the command is on Windows. I am actually trying to edit files over SSH with Windows Server 2008.

6
  • 2
    I think the accepted answer should be changed to squillman's (as it is the only one that will work on most contemporary PCs - and possibly inside Docker containers). Sep 7, 2018 at 17:11
  • 2
  • 4
    if you do have a graphic desktop but simply want to edit a file directly from cmd then you can use notepad e.g. with notepad myfile.txt
    – ccpizza
    Aug 16, 2019 at 13:25
  • 3
    If you have linux subsystem for windows, you can use 'bash' and then any linux subsystem command (I tried nano and it works). I would post this as answer but I can't for some reason.
    – SajanGohil
    Mar 2, 2020 at 9:32
  • @SajanGohil i get the following error when running 'bash nano' from a windows cmd line: "/usr/bin/nano: /usr/bin/nano: cannot execute binary file"
    – BogBody
    Sep 28, 2020 at 21:37

13 Answers 13

64

edit filename

I won't vouch for its functionality and outdated GUI but it is installed by default, even on Windows 7.

Edit: Except 64 bit versions of Windows.

14
  • 22
    On all versions of Windows? There is no "edit" on Windows 7 apparently.
    – Snark
    Sep 10, 2010 at 3:53
  • 23
    Odd... evidently it's installed by default on Windows 7 32-bit, but not on Windows 7 64-bit. That's sad.
    – nhinkle
    Sep 10, 2010 at 4:12
  • 7
    @nhinkle: I seem to recall reading something about 16-bit apps being unavailable under 64-bit windows installs.
    – intuited
    Sep 10, 2010 at 4:34
  • 33
    Confirmed NOT working in Win 10... I really cant believe Windows is lacking such basic tools and nobody even seems to care
    – Rafael T
    Aug 30, 2017 at 11:59
  • 7
    This is just wrong answer when talking about "Windows" generally. Today, Windows is also Win7-64bit, Win8-64bit, Win8.1-64bit, Win10. "edit" cannot be the correct answer to the question from today's point of view. Nov 9, 2017 at 10:40
118

The simplest solution on all versions of Windows is:

C:\> notepad somefile.txt

And, no extra software required.

9
  • 99
    Nice, but not over SSH
    – Casebash
    Sep 10, 2010 at 4:10
  • 6
    Ah. Right. Windows doesn't have a command-line editor built in. You'll probably need to install the Gnu version of the editor you want to use. Since you've already installed the ssh server, that should be no problem for you.
    – BillP3rd
    Sep 10, 2010 at 4:27
  • 19
    Like OP said... "I am actually trying to edit files over ssh..."
    – daviewales
    Apr 13, 2014 at 3:16
  • 28
    useless answer, both for ssh users and for those who wants to edit files IN cmd window, not outside it
    – vladkras
    Feb 14, 2016 at 7:10
  • 8
    This will not work in a Docker container based on 'windowsservercore' Aug 28, 2018 at 9:17
74

From a Windows command prompt enter copy con followed by the target file name. (copy con c:\file.txt).

Then enter the text you want to put in the file.

End and save the file by pressing CTRL-Z then Enter or F6 then Enter.

If you want to change text in an existing file simply display the text by using the command type followed by the file name and then just copy and paste the text in to the copy con command.

5
  • 24
    Hard core. Try not to make any typos, or you'll have to start over again. Well, backspace does work if you catch the mistake before you press Enter. Dec 3, 2013 at 18:57
  • Doesn't seem to work with psexec. Tried to edit my hosts file with copy con hosts but ^Z doesn't save and ^C doesn't cancel! Had to close the cmd window to get out. The file was unchanged. May 27, 2014 at 11:17
  • Note: F6 can be used instead of [Ctrl]-[Z] Sep 13, 2014 at 9:58
  • 5
    In a Docker container based on 'windowsservercore' (CMD), Ctrl + C worked for the terminating key sequence. Aug 28, 2018 at 9:30
  • I remember this hack from MS-DOS but it doesn't seem to work in Windows Powershell. Probably worth a new Question to clarify.
    – hardmath
    Feb 19, 2023 at 18:42
60

If you have git installed for windows then most likely nano and vim are both available at

C:\Program Files\Git\usr\bin\nano.exe
C:\Program Files\Git\usr\bin\vim.exe

To run from a command prompt (cmd.exe)

"c:\Program Files\Git\usr\bin\nano.exe" <filename>

To run in powershell

& 'C:\Program Files\Git\usr\bin\nano.exe' <filename>

They both work great even over ssh.

5
  • 4
    Thank you! Git imo is a more reasonable dependency that's likely already on the server, as opposed to WSL or other 3rd-party text editors.
    – Konafa
    Jul 12, 2020 at 1:02
  • 3
    This is the perfect answer!
    – Bachi
    Aug 29, 2021 at 8:59
  • 1
    This should be the Accepted Answer. People running ssh will mostly have git installed as well. Otherwise, nano or vim could be installed through gui once, and then be used Mar 15, 2022 at 13:17
  • 1
    I added the directory `c:\Program Files\Git\usr\bin` to the path in Windows, now it feels like having a Linux inside Windows. Nice! Sep 3, 2022 at 17:19
  • this should be marked as answer. 👍
    – Luke
    Aug 23, 2023 at 10:00
31

If you're used to vi and don't want to settle for the built-in editor you can get Vim for Windows. It'll run from a command shell. Or try WinVi.

4
  • 4
    this should me marked as answer because edit has been removed from win 10
    – Luke
    Jun 14, 2018 at 18:36
  • 4
    It is much better than that: It also works inside a Windows Docker container (it is easiest to get the "Win32 console executable", e.g. vim81w32.zip - unzip and copy vim.exe to wherever it is accessible in the Docker container). Sep 15, 2018 at 23:38
  • vi/vim is my go to, can recommend chocolatey package manager - choco install vim
    – Mike Hardy
    May 1, 2023 at 17:23
  • winget install vim.vim also works (assuming you've updated the URL of the source winget to the current https://winget.azureedge.net/cache - I've encountered installations with an old source URL).
    – telcoM
    Dec 31, 2023 at 22:22
16

Believe it or not, EDLIN.EXE is still around <shudder> at least on this Vista system.

Excuse me while I sob softly to myself...

6
  • 8
    It was finally deleted in Windows 7 (at least the 64-bit versions).
    – paradroid
    Sep 10, 2010 at 7:11
  • 2
    @jason404: It's still included in 32-bit Windows 7. Sep 10, 2010 at 15:08
  • 2
    edlin is a 16-bit program, therefore it is not available in 64-bit versions of Windows. However, I won't be surprised if someone here claims it's still present in the 32-bit version of Windows 10. May 12, 2015 at 7:54
  • 1
    @TSJNachos117 It is indeed in x86 Windows 10. Oct 12, 2016 at 1:19
  • 1
    Someone compiled edlin for Windows 10: Native edlin on windows 10 (!). Oct 4, 2021 at 9:12
9

I don't know about SSH, or anything (else?) server-related, so forgive me if this "solution" is useless. If you want to edit files in the command prompt, you can get the Windows version of Nano.

As a side note, those little ^ signs at the bottom of the window are supposed to represent the Ctrl button. For instance, ^X Exit means that you can exit the program using Ctrl-X.

Also, Nano will sometimes add extra newlines when saving files. This seems to be some kind of bug with Nano's word wrapping.

I've also seen ports of vi for Windows, although I've used one that just seem to make command prompt window as small as it can be, leaving only a title bar (which means the rest of the window may as well be invisible, since you can't see what you're doing). However, the Windows version of Vim seems to work quite nicely.

2
  • 2
    Before lookig for those "may work but are useless solutions" i thought for a Windows port of Nano. It's using cygwin.dll and nothing more. I've picket the lightest version i can, from netcologne.dl.sourceforge.net/project/nano/nano/1.0.8/…. Thank you.
    – m3nda
    Jan 26, 2017 at 16:46
  • As @gman pointed out, if you have git installed, then you already have nano.exe. Also, it's pretty easy to install nano via the command line by using chocolatey ( chocolatey.org/install#individual ). After chocolatey is installed, install nano by typing choco install nano.
    – cowlinator
    Jul 17, 2020 at 17:01
7

2020 UPDATE:

On Win10 just enable the linux subsystem then you'll have most of the linux stuff like vim and nano:

c:> bash
$: nano yourfile.txt
4
  • 2
    The linux subsystem? Is that a thing now in W10? Aug 8, 2020 at 10:15
  • 3
    OK, just googled this - good idea, but installing an entire linux distro to enable a terminal editor? It's a stretch. Still might try it tho' ;) Aug 8, 2020 at 10:30
  • Having to fire up a VM solely for the purpose of editing a file isn't a good idea..., well unless one wants to change their shell completely, which is a good idea!
    – aderchox
    Oct 4, 2021 at 7:48
  • Using WSL doesn't necessarily solve the problem conveniently since it can't necessarily access the main Windows partition. May 29, 2022 at 23:44
5

Use vim or nano.

Install vim with with choco install vim using the chocolatey package manager.

(There might be Scoop version available as well, but I haven't checked.)

Although nano also exists as choco package, it is very outdated. Instead manually install this nano. However, when using over SSH, nano control characters get a bit confused, so you may lose some, since windows use it's own API for controlling screen characters, and not POSIX. So although a lot of work is currently in progress for future Win10 compatibility.

Then you can run with: nano -cg some.txt, but the cursor will only show up at the right location when you push CTRL-L. (Which is why vim is preferred.)

4
  • 3
    Of course, this requires having Chocolately installed
    – mic
    May 26, 2020 at 15:38
  • Thanks mic, I added that link.
    – not2qubit
    May 31, 2020 at 7:25
  • UPDATE: Nano now works as expected in Windows-10, just make sure you are using UTF-8 in your terminal have a compatible font.
    – not2qubit
    Nov 21, 2022 at 16:15
  • chocolatey is the way.
    – sorh
    Mar 29, 2023 at 15:02
4

2021 UPDATE

As @phuclv has mentioned in comments, I want to emphasize that there is a tool that actually works great on Windows 64 bit too! It's called Micro and fortunately, it is quite feature-rich, regularly updated and alive.

To install it, you only need to download the latest version's 64bit.zip file from here, and then unzip it somewhere and add its path to your PATH. No dependencies or external files are needed — just the binary and you're done.

enter image description here

Quick Start:

  • Just type micro to create and edit a new text file.
  • Type micro <filename> to start editing an already-made file.
  • To save: ctrl + s
  • To see a list of keybindings: alt + g
  • To quit: ctrl + q

Some Exciting Features:

  • Select text easily (using the shift key, or even using your mouse!), and then copy, cut, paste or delete the selected text using the same keybindings common in your operating system(e.g. ctrl + c for copy on Windows).
  • Supporting so many common keybindings, e.g. ctrl + d to duplicate a line, or activate multiple curser mode and etc.
  • Undo / Redo
  • Syntax Highlighting (for more than 130 programming languages)
  • Plugin System
  • Typed Commands (instead of using keybindings)
  • ...

A tip on using Micro for VSCode users:

Since both VSCode and Micro try to support all common keybindings, you'll probably have a lot of conflicting keybindings between them when using Micro inside the VSCode's embedded CMD/PowerShell terminal. For instance, to quit Micro, you will have to use ctrl + q while it is the VSCode's keybinding for the "Quick Open View" command.

But no worries! Micro also supports "Typed Commands" which allow you to control the editor using commands instead of keybindings. So you can type commands and you're fine to use Micro on VSCode as well. However, there's still a tiny problem. To enable "command mode" on Micro, you have to use ctrl + e, which is also a keybinding of VSCode for the "Go To File..." command. So you have to change the ctrl + e keybinding either on VSCode or on Micro to get rid of this conflict and then you're all set.

Personally, I preferred to change Micro's ctrl + e. Here are the steps from the documentation to change it to ctrl + w (or whatever else non-conflicting keybinding of your own liking) on a Windows machine:

  1. Open %userprofile%/.config/micro/bindings.json with any editor.
  2. Add this line to the end of the JSON: "Ctrl-w": "CommandMode"
  3. Save. Now to enter command mode, press ctrl + w and type your commands (e.g.: quit, save, open, etc).
4
  • This is a nice option BUT it is a 10MB executable. Not exactly a lightweight option. If someone wants to bundle micro with their software, it bloats the download by 4MB (compressed). Would like to see a Notepad-esque CLI (no syntax highlighting, intentionally limited feature set, etc) that is about 200KB in size uncompressed. The main notepad.exe that comes with Windows is 210KB, so it seems like it should be doable. Oct 28, 2021 at 20:17
  • To be honest, I found the screen recording really confusing, not to mention the talk about VSCode keybinding. If it's a command-line editor, why launch it inside VSCode? I literally went to the developer site to check if it's a standalone app. I can't imagine the reason for such a strange edit process. Despite the confusion, it does look pretty good - I might use it instead of VSCode, which is getting annoying
    – LeeM
    Jan 7, 2022 at 6:10
  • It works well from the command line in a Windows Server Core editoin (likely also the Nano edition, but not tested). For a simple standalone tool to edit some config files it is great. The quite big binary doesn't bother me there.
    – Stefan
    Jan 31, 2022 at 22:59
  • 1
    10MB is tiny by modern standards. May 30, 2022 at 0:16
2

If the remote computer has Windows Subsystem for Linux installed, you can type bash to have the next commands interpreted by WSL. From here, you can type nano FILENAME or vim FILENAME or whatever your preferred Linux text editor is. To exit WSL and return to regular Command Prompt, type exit or logout.

This came in handy when I was accessing a Windows Jupyter Notebook server and wanted to edit .gitattributes, a hidden file which isn't shown in the Jupyter GUI. This answer is based on SajanGohil's comment above.

2

There is a console file manager called FAR Manager (similar to Norton Commander or Volkov Commander for MS DOS or Midnight Commander for Linux).

You can run the internal FAR Manager text editor using the following command line:

far -E <filename>

Screenshot

@Joril says it works via SSH. I did not have chance to test it.

Another similar solution is to install Midnight Commander as part of the msys2 distro or the standalone app and run

mcedit <filename>
2
  • 1
    Didn't know about Far and yes it works via SSH, thanks :)
    – Joril
    Jan 30 at 10:17
  • @Joril Thanks for letting me know. Added your note to the post. Jan 30 at 11:47
0

In the latest Windows 10 & 11, you can install Nano/vim/micro directly from Windows Terminal:

winget install Gnu.Nano
winget install vim.vim
winget install zyedidia.micro
1
  • I had the exact problem this question had: needing to edit a config file logged into windows 10 x64 over ssh, and winget install vim.vim worked great for me. All answers involving wsl in any case all failed, due to an issue that results in the 'The file cannot be accessed by the system." error. I could run vim with "c:\Program Files\Vim\vim90\vim.exe" after installing it with winget, and no windows terminal was needed: I was at command line via ssh.
    – RGD2
    Sep 1, 2023 at 5:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .