[Solved] How do I edit text files in the Windows command prompt?

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.

Enquirer: Casebash

||

Solution #1:

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.

Respondent: Mike Fitzpatrick

Solution #2:

The simplest solution on all versions of Windows is:

C:> notepad somefile.txt

And, no extra software required.

Respondent: BillP3rd

Solution #3:

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 CTRLZ 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.

Respondent: Mordorf

Solution #4:

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.

Respondent: squillman

Solution #5:

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

C:Program FilesGitusrin
ano.exe
C:Program FilesGitusrinvim.exe

To run from a command prompt (cmd.exe)

"c:Program FilesGitusrin
ano.exe" <filename>

To run in powershell

& 'C:Program FilesGitusrin
ano.exe' <filename>

They both work great even over ssh.

Respondent: gman

Solution #6:

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

Excuse me while I sob softly to myself…

Respondent: Dennis Williamson

Solution #7:

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 CtrlX.

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.

Respondent: TSJNachos117

Solution #8:

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
Respondent: DDS

Solution #9:

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.)

Respondent: not2qubit

Solution #10:

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.

Respondent: mic

Solution #11:

I’m not 100% sure it will work via SSH as they may use some special Windows API for Console Window management, but on Windows there is a console shell called FAR Manager (similar to Norton Commander or Volkov Commander for MS DOS or Midnight Commander for Linux). You can run the FAR Manager editor using the following command line:

far -E <filename>

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

mcedit <filename>
Respondent: Dmytro Ovdiienko

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.