powershell script to behave like vim or nano? - windows

Does Powershell have the capacity to generate some kind of terminal-based text editor program? I am switching to Windows because it supports a few programs I can't use otherwise; but I am having trouble discovering some sort of way to edit text files directly from Powershell. Is it possible to create a terminal-based text editor with a Powershell script; and if not is there a simple alternative?

Why don't you just install Vim, as it has a Windows version too? Add it to path and you should be all set.

I would suggest micro which is a powershell/ cmd/ terminal based text editor for Windows and other OS
https://micro-editor.github.io/
Because micro is flexible cut/copy/paste same keyboard shortcut as notepad. The best part is, it has color highlighter sensitive to programming language. Here is an image
Note: don't forget the add the micro.exe path to environment variable.
Command to open a file from cmd:
micro ./file.xyz

You use chocolately if it is installed on your powershell if you don’t have it just search for it online
Choco install nano
After this you can use nano
Then just
nano filenam
If it exists it edit it and if it doesn’t it create a new file

Related

How do you make .sh or .bash files open with Windows Terminal Ubuntu?

I really like coding in bash, but there used to be many limitations of bash functionality in Windows. Though now there are many benefits to the bash windows users now rather than how it was pre windows 10. However, with all of the improvements, there is one thing that I feel leaves to be desired for me. The default behavior of the double-click of .sh files never really was able to do anything in windows, the .sh file extension isn't even available in the "choose default apps by file type" section of the settings. I had a desire to be able to change the default action for .sh files but neglected it and shook it off for a while, but this link finally gave me hope.
Before Ubuntu terminal and the addition of Windows subsystem for Linux, there was really no way to access bash terminal on Windows without a VM. Now with the addition of Windows Terminal which combines Microsoft Azure Terminal, Command Prompt, Powershell, and Ubuntu, it is really awesome for people like me, but despite the new awesome additions to windows allowing further integration of Linux terminal into Windows, even being able to edit the C: drive with Ubuntu.
I am sure there is a way to allow double-click of .sh files to open in windows terminal Ubuntu, but I don't know how. This question helped me on my journey to figure out how to do it and helped me make the default .bat file behavior change to Windows terminal, but I still have come to an enpass where I truly believe that it is not possible. So here is where I go when I have given up, the magical land of Stack Overflow :)
Attempts
So far I have looked into the "Choose default apps by file extension" section of settings and could not find .sh in there nor could I find it in any of the default apps sections of normal settings.
After I couldn't find anything about .sh in settings, I looked into the registry and looked for HKEY_CLASSES_ROOT and looked for sh or anything bash file related in HCR alone, HCR\*\shell, HCR\*\shellx, and HCR\*\Openwithlist and could not find anything.
I then tried to do ftype, but I could not find how to use ftype with .sh. I tried doing ftype .sh="C:\Users\asian\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Ubuntu" "%1" %* but i got the error "File type '.sh' not found or no open command associated with it."
I Also tried just clicking the .sh file so it brings up the "How do you want to open this file" menu and went to Windows Terminal but it opened the bash file in powershell with the error [error 0x800700c1 when launching `C:\Users\asian\Desktop\test.sh']
These where everything I could think of and none of it was working. Help and pointers are appreciated. Thank you!
I suggest you install the Git for Windows package, as it comes with a light-weight bash environment. This is likely to be able to be in the list of available apps when right-click -> Properties on a .sh or .bash file and say Open With and click the Change button next to Open With.
Other options are Cygwin or WSL for a 95% pure Linux environment on Windows.

Alternative command for Vi/Cat in Windows 7

In Unix/Linux we are having vi & cat command to view or edit a file. There are any alternative command to view/edit a file in windows command prompt.
Cygwin is a large collection of GNU and Open Source tools which provide functionality similar to a Linux distribution on Windows.
It includes both cat and vi.
It is possible to select which parts of Cygwin to install. See Installing and Updating Cygwin Packages for more instructions.
There is a edit on windows but it doesn't work on 64Bit machine. So alternate solution is given below.
Just download vim for windows from Here (direct download link), on the installation it will ask if you want to create shortcuts for calling it from the command line. Then you can just vim
For Windows, To view the filename use, Type filename

Basic text editor in command prompt? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I know for linux and Unix machines there is emacs and vi text editor and gcc is built in to compile c code? what would be the Windows text editor in cmd and are there any compilers built in?
I made a simple VIM clone from batch to satisfy your needs.
#echo off
title WinVim
color a
cls
echo WinVim 1.02
echo.
echo To save press CTRL+Z then press enter
echo.
echo Make sure to include extension in file name
set /p name=File Name:
copy con %name%
if exist %name% copy %name% + con
Hope this helps :)
There is also a port of nano for windows, which is more more akin to notepad.exe than vim is
https://www.nano-editor.org/dist/win32-support/
Get the WINNT zip. Tested in Windows 7 works as expected
I want to add that it is very strange to introduce Core and Nano servers without native console full-featured editor. Like others I`ll recommend to use vim or nano. But my suggestion is to install it via OneGet (require WMF5)! They both are presented in Chocolatey repository so installation is simple and fast:
PS C:> Find-Package -Name vim | Format-Table -AutoSize
Name Version Status ProviderName Source Summary
---- ------- ------ ------------ ------ -------
vim 7.4.638 Available Chocolatey chocolatey Vim is an advanced text editor...
PS C:> Install-Package vim
MS-DOS Editor (or just edit) is a 16-bit text editor that is still included with 32-bit versions of Windows XP, Vista, 7, 8 and 8.1. It can edit files upto 65,279 lines long and has mouse support. Being an 16-bit DOS editor, it cannot run directly on 64-bit versions of Windows. It can be launched by typing edit at the command prompt.
There is no command based text editors in windows (at least from Windows 7). But you can try the vi windows clone available here : http://www.vim.org/
There is no command based text editors in windows (at least from Windows 7). But you can try the vi windows clone available here : http://www.vim.org/
You are Wrong!
If you are using Windows 7, you can using this command:
copy con [filename.???]
Or if you using Windows XP or lower, use (is have a DOS GUI):
edit
Any comment?
I also wondered what had happened to the text editor in console mode in windows. I remembered the famous mc from Linux. Of course, it's available for Windows!
GNU Midnight Commander is a visual file manager, licensed under GNU
General Public License and therefore qualifies as Free Software. It's
a feature rich full-screen text mode application that allows you to
copy, move and delete files and whole directory trees, search for
files and run commands in the subshell. Internal viewer and editor are
included.
Midnight Commander is based on versatile text interfaces, such as
Ncurses or S-Lang, which allows it to work on a regular console,
inside an X Window terminal, over SSH connections and all kinds of
remote shells.
As mentioned somewhere there are also FAR Manager
vim may be challenging for beginners. For a quick-and-dirty Windows console-mode text editor, I would suggest Kinesics Text Editor.
There actually is a basic text editor on Windows. In the command prompt simply type edit, and it should take you to there. Now, someone already mentioned it, but they said it's XP or lower. Actually it works perfectly fine on my Windows 7.
Wikipedia page
Again, I am running Windows 7, so I've no idea if it's still is present on Windows 8.
And as IInspectable pointed out, there's no built in C compilers, which is a disappointment. Oh, well, back to MinGW.
Also, "here" someone mentioned Far Manager, which has ability to edit files, so that's some alternative.
Hope that helps
You can install vim/vi for windows and set windows PATH variable and open it in command line.
As said by Morne you can use the vi editor for windows
Also you can get CodeBlocks for windows from here
Install it and direct your PATH environment variable of your windows installation to gcc or other binaries in bin folder of codeblocks installation folder.
Now you can use gcc or other compilers from cmd like linux.
There is one built into windows 7 in which you can open by clicking the windows and r keys at the same time and then typing edit.com.
I hope this helped
The standard text editor in windows is notepad. There are no built-in command line editors.
Windows does not ship a C or C++ compiler. The .NET framework comes with several compilers, though: csc.exe (C# compiler), vbc.exe (VB.NET compiler), jsc.exe (JavaScript compiler).
If you want a free alternative you can download Visual Studio Express 2013 for Windows Desktop that comes with an optimizing C/C++ compiler (cl.exe).
In a pinch, just type 'notepad (filename)' and notepad will pop up with the file you want to edit in it. Otherwise Vim or some such will have to be installed.
notepad filename.extension will open notepad editor

How to use vim editor in windows source insight

I am using windows source insight. In this only the basic text editor is available. Is there any vim plugin available to use it in windwos source insight?
According to the docs (search for ShellExecute), you should be able to invoke a ShellExecute with an arbitrary program. If VIM is associated with a certain file as editor, this should work:
ShellExecute edit <yourfile>
If VIM is for some strange reason not the default editor for a certain file, you should try
ShellExecute "" C:/Path/to/vim.exe <yourfile>
Thay way, you should be able to call any external tool from Source Insight.
add customer command in source insight and bind a new short key.
"C:\Program Files (x86)\Vim\vim81\gvim.exe" --remote-silent +%l %f

Running programs easily from a command line on Windows

Linux allows me to have a short system path by placing binaries in just a few locations. I don't have to edit the path because I just installed a new application, and I don't have to hunt for applications I want to run. How can I, with PowerShell as the program I use to launch programs from, accomplish the same thing on Windows (Vista)?
Windows Vista has symlinks now via mklink.
Perhaps you could setup a "C:\bin" folder and generate symlinks to point back to the original binaries. That is assuming that Windows Vista's symlinks work similarly to the ones in Linux. Here's a short tutorial.
Many programs create an application paths entry in the registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths). For those applications, you can start them like so:
PS> Start-Process <application name>
PS> Start-Process excel
If you don't have PowerShell V2, which provides Start-Process, you can use the PowerShell Community Extensions on V1.
It sounds like adding a few directories to your path environmental variable might help. From the command prompt you can view all environmental variables with the set command. Then you can cut and paste your path and use set again to add to it.
If you prefer the GUI route, right click on My Computer → Properties → (in Windows Vista and Windows 7 go to "Advanced System Settings" on the left. In Windows XP, skip this step) → Advanced Tab → At the bottom there is an Environmental Variables button.
When something is invoked from the command line, Windows checks in all the directories marked in the path first. After your application directory is in the path, you can execute it without fully qualifying your path.
You could always add a .cmd file as an alias.
I install applications into C:\bin.
Using specifically PowerShell you can just create aliases for programs you want to start. I doubt that this is actually less work than editing the PATH environment variable, though.

Resources