I'm fairly familiar with the default bash shell shortcuts (emacs style). For example, if I want to move my cursor forward by a word I would press Alt+F (same as you would in emacs). I can get to the previous command with Ctrl+P.
Is it even possible in windows powershell to override these shortcuts? If so, does anyone know of a good way to map the default bash shell shortcut configurations to powershell (in a bash shell you can say set -o emacs, for example)?
If it helps, I don't really care about powershell per say, I care about posh-git shell. However, git-shell inherits its properties from powershell from what I can tell.
You can do that with the PSReadLine module which ships with PowerShell 5.0 (Windows 10).
Simply set the EditMode option to Emacs:
Set-PSReadLineOption -EditMode Emacs
In addition to the default Windows mode, it also has a Vi mode.
The project README file mentions that neither are fully implemented so don't expect full feature parity, but I can confirm that it switches tab completion to bash-style and supports the Alt+F and Ctrl+P key bindings for moving forward and jumping to the previous command respectively
(I'm not an experienced emacs user so I'm unable to tell whether this comes "close enough" to what you expect)
Related
If I launch Windows Terminal, which, in turn, launches an instance of PowerShell 7.2.6 it looks different than if I simply launch PowerShell 7.2.6.
The top image is Windows Terminal with a PowerShell tab. Bottom image is PowerShell by itself.
Not only is the Windows Terminal version far more legible, it also renders ANSI escape codes correctly (color, cursor positioning, etc.). The stand-alone PowerShell does not.
I have confirmed, through Task Manager, that both instances are running C:\Program Files\PowerShell\7\pwsh.exe
How do I make them look the same (like under Windows Terminal) and render escape sequences in the stand-alone case?
A bit more madness...
If I take the approach of manually editing the properties of the stand-alone PowerShell to match the settings I see under Windows Terminal it makes an absolute mess. For example, if I set the font to Cascadia Mono 12, which is the setting under Windows Terminal, I get microscopic text that is unusuable:
I have to set the font size to 20 in order to approximate the look of what comes up under Windows Terminal. Also, any changes made to stand-alone PowerShell do not seem to affect PowerShell under Windows Terminal.
EDIT:
This is what Task Manager shows for these two instances. One is PowerShell launched by itself. The other is in the context of Windows Terminal. The latter does not seem to use Console Window Host.
Also, this isn't about legacy Windows PowerShell, which generally lives here:
C:\WINDOWS\system32\WindowsPowerShell\v1.0
This is about modern PowerShell, in this case version 7.2.6, which is installed here:
C:\Program Files\PowerShell\7
Note:
If you launch a console application (such as PowerShell (Core)'s pwsh.exe CLI) directly (either directly by its executable path or via a shortcut file targeting that executable path), you'll invariably (up to Windows 10) / by default (from Windows 11) get a regular (legacy) console window, backed by conhost.exe, the Windows Console Host.
Such windows have their own appearance settings, distinct from Windows Terminal's; the best you can do is to manually match them, as described in the next section.
On Windows 11, you can now configure your system to open console applications with Windows Terminal instead: in the Settings application, search for terminal and select Choose a terminal host app for interactive command-line tools
Alternatively, launch PowerShell via the Windows Terminal CLI, wt.exe, which by definition gives you the desired look and unconditional support for ANSI / VT escape-sequence rendering; e.g.:
wt.exe "C:\Program Files\PowerShell\7\pwsh.exe"
You may alternatively launch with a predefined profile, using the -p option - see this answer for more information.
Note that this invocation method isn't suitable for programmatic use of the PowerShell CLI (in case you want to execute commands unattended and receive their output).
Regular (legacy) console windows (provided by conhost.exe, the Windows Console Host) have their own font and appearance settings, distinct from Windows Terminal's; you can control them via their system menu (click on the icon in the top-left corner of the title bar and select Properties):
You can manually try to emulate the Windows Terminal look, such as by choosing the Cascadia Mono font, and it seems that size 20(!) is required to get the same on-screen size as the size 12 reported via Windows Terminal's settings. However, even then it looks like the font rendering differs slightly. You may also have to tweak the colors to match.
Note that for conhost.exe windows launched via a shortcut file (*.lnk), such as via the Start Menu and the taskbar, any modifications are saved in that shortcut file only.
Thus, to change the settings for an executable launched by direct invocation of the executable path, be sure to launch a session that way before making modifications, e.g. via the Run dialog (WinKey-R).
The modified settings are stored in the registry at [HKEY_CURRENT_USER\Console\<transformed-exe-path>], where <transformed-exe-path> is the full path of the executable with \ characters replaced with _, e.g.
HKEY_CURRENT_USER\Console\C:_Program Files_PowerShell_7_pwsh.exe
As for unconditionally rendering VT / ANSI escape sequences in conhost.exe windows: you can activate support for them in all future conhost.exe windows via the registry, by submitting Set-ItemProperty HKCU:\Console VirtualTerminalLevel -Type DWORD 1, as discussed in more detail in this answer.
I was wondering if there was a way to use windows shortcuts in vim (in particular those used to select lines (with shift, alt, ctrl) ?
Maybe an option to set in the .vimrc ?
Thanks.
You can enable this via the following command in your ~/.vimrc:
source $VIMRUNTIME/mswin.vim
See :help mswin.vim for a detailed explanation.
Alternatively, copy that script into ~/.vim/plugin/mswin.vim. This allows you to gradually comment out or tweak certain mappings. The downside of this plugin is that many Windows shortcuts conflict with Vim commands, so you're losing some features, and the completely different structure may prevent you from learning and using Vim effectively. Having started with a Windows background myself, this is how I proceeded. Now, I only use a few of those Windows mappings in Vim, and have customized several remaining ones so that they provide a true added value.
I am looking for ideas to open files into an existing vim session.
I am working on Windows + Cygwin + Mintty. I usually have 3 to 4 opened terminals (2-3 vim sessions + 1 shell, build environment). I don't use tmux/screen because it's easier to use the native Windows's window manager to switch in between my terminal windows. Because I have 2 wide-screen monitors I can use the 2 half of both screens for my terminals which gives me an awesome working environment. With the help of an AHK script, I can use shortcuts to switch/rotate or even to reposition my terminals in the desired position.
I rather prefer vim over gvim for many reasons. I can achieve almost all the gvim features (scroll, mouse selection, copy, paste, etc. I am one of those who think that using the respectable y/P commands is a bit crippling when you need to use plenty of other softwares that use /. I always get confused to use different shortcuts for each software I am using.
Now the core issue. I would like to open a file from the Windows explorer into an existing vim session. I found a horrible solution using a Perl script with the Win32::API in order to look for an existing mintty terminal with Vim in the title. Then I activate the window and send <esc>:e path/file<cr> to it.
It works pretty well but I am looking for a better solution like gvim --remote that works with my console vim. Unfortunately I don't have such options with my vim even though if I built it with the -with-x configure option.
So, I am looking for some suggestions to achieve a more honorable solution (socket/adding the feature directly to vim/using a smarter ahk script/etc.)
gvim --remote should work with console vim if you start vim with vim --servername GVIM. Alternatively, choose another servername and use vim --servername foo --remote.
I started using vim for my programming projects (mostly Ruby) and mostly everything works just as I want but I have a problem with compiling.
Lets say I am working on a Ruby script and I want to run it. I type :ruby sometging.rb (mapped to some other key). Then vim opens a new cmd.exe window and runs 'ruby something.rb'. Then it waits for me to press ENTER to close the window and continue working on the script.
Is there a way to configure vim on windows so that it always runs the script I'm working on in a separete window (always the same one, if none exists => open one), and not ask me to confirm with enter?
Don't know about gvim, but in normal vim you could put something like
map R <ESC>:tabnew<CR><ESC>:;%!ruby filename.rb<CR>
in your ~/.vimrc which would execute a Ruby file in a newtab when pressing R in command mode.
I've not used Ruby, but for I've found Dr Chip's RunView plugin really useful for running other interpreted languages.
Once it's installed, you can enter:
:RunView! <interpreter>
(where <interpreter> is presumably 'ruby' in your case) and it will open a (vertically if you include the !) split window with the output from passing the contents of the current window to the interpreter. Each time it is run, a new result log is appended to the end of the file (with a date and time stamp separating them).
If you have any issues with it, I'd recommend you contact Dr Chip via the Vim mailing list: he's very helpful (in fact he wrote the original version of RunView in response to a request I made on the mailing list).
This isn't exactly perfect but I use this to launch Python scripts.
command -nargs=* PY3 !start cmd /K Python.exe "%:p" <args>
It starts up a window that stays alive and doesn't interfere with my VIM window. Unfortunately it doesn't load it into an existing window.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Is there a better windows command line shell other than cmd which has better copy paste between Windows' windows and console windows?
Enable QuickEdit mode, under the Options tab of your shortcut to the command shell. Mark with the mouse, right-click to copy, right-click again to paste.
While you're there, enable a hotkey (like CTRL + ALT + C) for lightning fast access to the shell.
And no, you can't have CTRL + C for COPY, because CTRL + C means BREAK.
On a related note, the Microsoftee who changed the default setting of QuickEdit mode between Windows Server 2000 and 2003 is an idiot and I heap curses upon him each workday.
Windows PowerShell is the obvious choice when it comes to "better windows command line shell other than cmd". Its clipboard handling isn't that much of an improvement - mark with the mouse, Enter to copy, or right mouse click to paste.
This probably is not exactly what you want, but you can take a look at Console2
I have it configured so that shift+select auto copies and middle click pastes, really handy, internally it uses same old cmd.exe so you are not really getting a different shell.
By the way, I guess Ctrl+C = copy is not the best idea in a command line context because it usually means interrupt running process.
Take Command does support Copy/Cut/Paste from the keyboard and the mouse. It's pretty handy if you do a lot of work from a command prompt. It also supports:
Command and folder history, with popup windows to select prior commands or folders.
Screen scroll back buffer
Enhanced batch commands
Built in FTP/HTTP file access
A toolbar with programmable buttons
Note: It's a paid tool, with price of $99.95.
Depending on what you're trying to do with the shell, rxvt in cygwin is good.
You'll get the nicety of auto copy on selection and middle click paste. The biggest downside is that some windows console apps don't play nice with cygwin.
PowerCmd is cheaper than TakeCommand and has a lot of powerful features - not the least of which is better handling of Cut/Copy/Paste. I've only been using it a short time but I'm really impressed so far:
Summary from the site:
PowerCmd enhances your command prompt
with an easy-to-use Windows GUI-style
interface and allows you to run
multiple consoles within a single
tabbed window. You can easily organize
multiple consoles in vertical,
horizontal, and grid forms. Auto-log,
auto-completion, keywords highlight,
configurable font and colors,
customizable toolbar for frequently
used commands or tools and minimizing
to tray are easy solutions to daily
needs. With PowerCmd, you can save and
restore your sessions from last time.
Site:
http://www.powercmd.com/
Features:
http://www.powercmd.com/features.php
Not sure what specifically you mean by better copy/paste but try Take Command.
Take Command supports Shift+Ins for paste and Shift+Del for cut, but apparently nothing for copy, will dig some more.
There are two portion to cmd.exe. First there is the window that pops up for dealing with the text console. I would replace that with ConEmu. That program is actually meant as a wrapper for the Far File manager but works just fine without it. It is very similar to Console2 but also is much more stable and has better features.
Second there is the command line interpreter. I would replace that with Powershell if you actually need any of its features.
I currently run using ConEmu with a batch file to setup my preferred environment. This is kept in my Dropbox folder so it remains synchronized between my computers.
Have you thought through what behavior you want to replace the current Ctrl+C functionality?
Console 2
http://sourceforge.net/projects/console/
http://www.hanselman.com/blog/Console2ABetterWindowsCommandPrompt.aspx
#Chirs
I think you need to clarify shell vs host(emulator). To me it sounds like you need another interface to your existing shell that better supports copy and paste, not another shell that supports more/different features.
I second Pat's suggestion of Console2, it is a very good application and OSS to boot.
The Windows cmd shell, Cygwin Bash, and msysgit Bash shells can be run within Emacs. EmacsW32 provides all three separately. You just have to set the bin directory to use either of the Bash shells. EmacsW32 also provides limited interactions between the Windows clipboard and the top item of the kill ring.
MinGW Shell properly set up with:
right click menu entry
~/.profile file
is well above anything else I have tried.
MinTTY on MinGW/MSYS is nice—nicer than on Cygwin because MinGW/MSYS is faster. Also, if you need cmd.exe behaviour, you can run cmd.exe inside of mintty easily.
See http://code.google.com/p/mintty/.
I use the standard CMD.EXE shell but with a twist: an AutoHotKey script to support clipboard copy-paste as posted in: Keyboard shortcut to paste clipboard content into command prompt window (Win XP)