I am using gvim on Windows. Is it possible to pass my favorite options to gvim while launching it from the "Edit with Vim" entry of the right-clicked pop-up menu?
BR,Ruochen
Following the instructions at Adding Vim to MS-Windows File Explorer Menu, you can add / change the Windows registry to pass arbitrary commands to gvim.exe on startup. Vim takes both --cmd {command} (necessary when setting configuration variables to be considered in your ~/.vimrc) and -c {command} (only evaluated after plugins have been loaded).
You can either directly change the settings (e.g. gvim.exe -c "set list" "%1"), or just set a flag (let g:isPopupLaunch = 1) and check that in your ~/.vimrc.
An alternative solution may be easier, which is adding Vim to the Send To menu. For that you just create a shortcut which passes the desired options, and place it in your shell:sendto folder.
Related
Is there a way I can save current split panel layout and profile for each panel so I don't need to split and open profile one by one again?
This feature does not yet exist as part of Windows Terminal.
However, this feature was suggested, and the suggestion has been accepted and is being tracked in the Windows Terminal github issues backlog:
https://github.com/microsoft/terminal/issues/3759
Work-around:
You can call windows terminal (wt) from the command line and specify starting directories, splits, tabs, profiles, etc.
For example, run this from command line and it will open up 2 Windows Terminal tabs, the first tab will be a split layout with PowerShell profile + your default profile, and the other tab will use the Ubuntu WSL profile:
wt -d "C:\Windows\System32" -p "PowerShell"; sp -V -d "%USERPROFILE%"; nt -p "Ubuntu" --title "wsl" --tabColor "#FF0000"
Better yet, set this command as the file location for a shortcut on your desktop and you can just double click the shortcut to open your favorite Windows Terminal configuration.
See more wt command line options here:
https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows
I am running emacs 25.1 under Windows. It is a standalone binary, not running under cygwin
I have a .emacs file that works on both windows and linux. On Windows, however, the command:
(cd "c:/Users/xxx/git")
does not start emacs in that directory. The command works, because if I evaluate the buffer, it does go to that directory. It is as though something else is executing AFTER my script causing emacs to default to the stupid windows default, wherever the code is.
Any workaround to make emacs start in my desired directory?
Create a Windows shortcut to the Emacs executable, and use that to start Emacs. Create the shortcut by right-clicking the file runemacs.exe in folder bin and choosing Create shortcut.
Then fill out the Properties in the Shortcut tab:
Field Target has the command for starting Emacs: the location and name of the binary (executable) followed by whatever options you want and any file or directory that you want to start editing.
Field Start in has the directory that I want Emacs to start in.
For example:
Target: D:\Emacs-25.1\bin\runemacs.exe --debug-init "d:\usr\some-user-name\some-directory"
Start in: d:\usr\some-user-name\some-directory
Then just double-click your shortcut to start Emacs. Or single-click it, if you pin it to the Task Bar.
You can create as many such shortcuts as you want, either to the same Emacs executable (e.g. with different options or startup directories) or to different executables (e.g. different Emacs releases).
Try using emacs-startup-hook, which runs after processing the commandline and init.el.
(defun jpk/emacs-startup-hook ()
(cd "/some/path"))
(add-hook 'emacs-startup-hook #'jpk/emacs-startup-hook)
If that doesn't work, some package is setting the CWD, and you'll have to track it down.
I am looking for ways to open multiple documents in a single application instance. For example, open multiple documents in a single, new gVim instance.
I had found this code on here before, but it doesn't quite do what I want.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
#="\"C:\\Users\\avt\\Programs\\PortableApps\\gVimPortable\\gVimPortable.exe\" -p --remote-tab-silent \"%1\" \"%*\""
The problem is that it is giving a similar effect, but not the one I want (it opens the selected documents in an existing gVim instance, not all of them in their OWN new gVim instance). What I want is like this:
Highlight 5 documents in Explorer
Open them
A single gVim instance opens with all 5 documents as tabs
I think this would work, if only I could pass multiple arguments!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim]
[HKEY_CLASSES_ROOT\*\Shell\Open with &Vim\command]
#="\"C:\\Users\\avt\\Programs\\PortableApps\\gVimPortable\\gVimPortable.exe\" -p \"%allselecteddocuments\""
Thanks!
EDIT: I just found out I can do this by adding a custom SendTo command (create a shortcut in your SendTo folder to gVim add -p to the Target. Is there any way to do this outside of the SendTo menu?
Create a shortcut in C:\Users\\\<user>\AppData\Roaming\Microsoft\Windows\SendTo folder with ONLY the exe name.
Now you should be able to select random multiple files and use context SendTo\<shortcut> to open them with your designated exe.
I want my Perl scripts to behave just like any other executable (*.exe file).
When I double-click on myscript.pl I want it to execute instead of opening in a text editor.
I want to run myscript.pl instead of perl myscript.pl.
I really want to run myscript instead of myscript.pl.
I want to run program | myscript instead of program | perl myscript.pl.
I want to be able to run my script via drag & drop.
There are a number of changes you have to make on Windows to make all of
these things work. Users typically stumble upon things that don't work one at
a time; leaving them confused whether they've made an error, there's a bug in
Perl, there's a bug in Windows, or the behavior they want just isn't possible.
This question is intended to provide a single point of reference for making
everything work up front; ideally before these problems even occur.
Related questions:
How do I make Perl scripts recognize parameters in the Win32 cmd console?
Running a perl script on windows without extension
Perl execution from command line question
How can I read piped input in Perl on Windows?
Perl on Windows, file associations and I/O redirection
How do I create drag-and-drop Strawberry Perl programs?
Note: The actions below require administrative privileges. For
steps utilizing the command prompt it must be launched via "Run as
administrator" on Windows Vista / Windows 7.
Associate *.pl files with perl
Run the following commands at a shell prompt:
assoc .pl=PerlScript
ftype PerlScript=C:\bin\perl.exe "%1" %*
Replace C:\Perl\bin\perl.exe with the path to your Perl installation. This
enables you to run myscript.pl instead of perl myscript.pl.
Default install locations are:
ActivePerl: C:\Perl
Strawberry Perl: C:\Strawberry
Add .PL to your PATHEXT environment variable.
This makes Windows consider *.pl files to be executable when searching your
PATH. It enables you to run myscript instead of myscript.pl.
You can set it for the current cmd session
set PATHEXT=%PATHEXT%;.PL
To set it permanently (under Windows Vista or Windows 7)
setx PATHEXT %PATHEXT%;.PL
Under Windows XP you have to use the GUI:
Right-click My Computer, and then click Properties.
Click the Advanced tab.
Click Environment variables.
Select PATHEXT, then click Edit.
Append ;.PL to the current value.
Make I/O redirection work
I/O redirection (e.g. program | myscript) doesn't work for programs started
via a file association. There is a registry patch to correct the problem.
Start Registry Editor.
Locate and then click the following key in the registry:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
On the Edit menu, click Add Value, and then add the following registry value:
Value name: InheritConsoleHandles
Data type: REG_DWORD
Radix: Decimal
Value data: 1
Quit Registry Editor.
Warning: In principle, this should only be necessary on Windows XP. In my experience it's also necessary in Windows 7. In Windows 10 this is actively harmful—programs execute but produce nothing on stdout/stderr. The registry key needs to be set to 0 instead of 1.
See also:
STDIN/STDOUT Redirection May Not Work If Started from a File Association
Perl Scripts on Windows 10 run from Explorer but not Command Prompt
If patching the registry isn't an option running program | perl -S myscript.pl
is a less annoying work-around for scripts in your PATH.
Add a drop handler
Adding a drop handler for Perl allows you to run a Perl script via drag & drop;
e.g. dragging a file over the file icon in Windows Explorer and dropping it
there. Run the following script to add the necessary entries to the registry:
use Win32::TieRegistry;
$Registry->Delimiter("/");
$perlKey = $Registry-> {"HKEY_CLASSES_ROOT/Perl/"};
$perlKey-> {"shellex/"} = {
"DropHandler/" => {
"/" => "{86C86720-42A0-1069-A2E8-08002B30309D}"
}};
Convert your perl scripts into batch files using pl2bat once they are ready to be run by users.
The trick works through the perl -x switch which, according to perldoc perlrun, makes Perl search for the first line looking like #!.*perl.
After following the instructions in the accepted answer, a double click still led to .pl files opening with Notepad in Windows 10 — even when perl.exe was set as the default file handler.
After finding Jack Wu's comment at ActivePerl. .pl files no longer execute but open in Notepad instead I was able to run perl scripts on double-click as such:
Select and right-click a .pl file
Use the "Open With" submenu to "Choose another app"
Select "Always use this app to open .pl files" (do this now – you won't get the chance after you have selected a program)
Scroll to the bottom of the "Other options" to find "More apps", and select "Look for another app on this PC"
Navigate to C:/path/to/perl/bin/ and select Perl5.16.3.exe (or the equivalent, depending on which version of Perl you have installed: but not Perl.exe)
Then the Perl icon appears next to .pl files and a double-click leads to them opening in Perl every time, as desired.
I tried the assoc and ftype methods and they didn't work for me.
What worked was editing this registry key:
Computer\HKEY_CURRENT_USER\Software\Classes\Applications\perl.exe\shell\open\command
It was set to:
"C:\Perl64\bin\perl.exe" "%1"
When it should be:
"C:\Perl64\bin\perl.exe" "%1" %*
It is the same content as the ftype, but for arcane windows reasons, I had to set it there too.
Like some others, I had set 'assoc' and 'ftype', but also had set Notepad text editor via the GUI, and when I tried to execute a script via the command line, Windows invoked Notepad to edit the script instead of running my script.
Using the GUI to instead point the .pl file association to the script-running executable was not much of an improvement, since it would invoke the executable on my script, but would pass no command-line arguments (even when I invoked my script from the command line).
I finally found salvation here which advised me to delete some registry keys.
Key quote:
"The problem is that if you have already associated the program with the extension via the Open With dialog then you will have created an application association, instead of a file extension association, between the two. And application associations take precedence."
In my case, following the instructions to use RegEdit to delete
HKEY_CLASSES_ROOT \ Applications \ perl.exe
where perl.exe is the name of my Perl executable, and then also deleting:
HKEY_CLASSES_ROOT \ .pl
seemed to solve my problem, and then (after re-executing 'assoc' and 'ftype' commands as shown in other answers) I could then execute scripts from cmd.exe and have them run with access to their command-line parameters.
Some other related information here.
Is it possible to open a terminal window with 3 tabs. Each tab should have different path.
Example:
Tab1: /etc
Tab2: /bin
Tab3: /www/ tail -f file.txt
This is absolutely possible, but it will take some work on your part. The first thing you need is to set up each window/tab you want in your Settings:
I have 4 tabs that I open automagically every time I open Terminal. DB Shell, Editor, Server, and Shell. These are all within the Sasquatch (don't ask) project, thus the naming. Each of these should then have a unique command associated with them:
In this case, I'm executing vim. If you happen to have a specific directory you'd like to start off in, you can use something like vim ~/projects/main/. Really whatever you want to go in there is the command the shell will execute when it opens. Now you need to open all your windows/tabs:
Close everything.
Open a new window for each of your profiles.
Go to the Shell menu => New Tab/New Window => Select the profile you created above.
Repeat for each window or tab you want.
Once you have all of your windows and/or tabs open, save them as a Window Group.
Go to the Window menu => Save Window As Group....
Give your Window Group a name (this is helpful later).
If you want this group to open every time you open Terminal, check the box at the bottom of this screen, and then hit save.
Close out of all of your Windows/Tabs (time to test it!).
Open your new Window Group.
Go to the Window menu => Open Window Group => Select the group you just made.
This should pop up all the windows you just had, in the same position. Each of the commands you set up in Settings should be launched in their respective tabs.
As of Mac OS X Lion 10.7, Terminal makes this much easier to do, without creating new profiles for each command.
By default, Terminal will remember and restore the current working directory for each terminal in a Window Group. (If the working directory has been communicated to Terminal using an escape sequence. The default shell, bash, will do this at every command prompt. For other shells, you'll need to adapt the code in /etc/bashrc.)
If you create a terminal with Shell > New Command, Terminal will automatically run that command when a Window Group is opened. Terminal will automatically run a limited set of "safe" commands†, and when saving a Window Group there's an option to run all commands in the group.
Terminal also automatically does these for all windows when restarting Terminal with Resume enabled. So, you may not even have to create a Window Group, depending on your circumstances.
For your example case:
Use Shell > New Command to run "tail -f /www/file.txt".
Create a new tab and "cd /etc".
Create a new tab and "cd /bin".
Save them with Window > Save Windows as Group. Be sure to check the "Restore all commands" checkbox.
Each time you open that Window Group, it will recreate those windows and run the commands. If you need to run a command and specify the starting directory, in the New Command dialog check the "Run command inside a shell" checkbox and make the command "cd ; ".
Also note that you can tell Terminal to open your Window Group at startup with Terminal > Preferences > Startup > On startup, open > Window group. There's even a checkbox to set this when saving a new Window Group.
† The "safe" commands include anything listed in /etc/shells, plus: screen, tmux, emacs, vi/vim, nano, pico, and top. You can customize the list with "defaults write com.apple.Terminal RestorableCommands". Set it to an array of strings containing command names or full paths. Some commands have parameters that are "unsafe" to run automatically without user intervention, so by default these commands are only considered "safe" if they do not have any arguments. To make a command safe to run with arguments, add an asterisk, e.g., "top *" is in the default value for this preference.
You can do what you wish from within Terminal.
If in Terminal preferences (Settings tab) you create a new profile (or copy one with Duplicate Settings), you can then set each profile to run a command on startup (the "Shell" subgroup within the profile).
Then setup your tabs by using the Shell > New Tab menu to create the new tabs from each of the specific profiles that you created for the three different executables.
Then do the Save Window Group to save the group of tabs (and it will save their profiles as well).
I suggest the use if iTerm instead of Terminal. If only because it is more configurable. You can script it, but more important to you is that you can create a bookmark folder (one for each tab) and then "open in tabs" which will give you the behavior you seek.
I suspect you can control commands to be executed too. One of the programs I use creates a single-tab terminal window and arranges to execute a profile-setting script before continuing to the command prompt - the same should be feasible for a multi-tab terminal. The file is a MacOS X properties XML file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CommandString</key>
<string>. /Applications/IBM/informix/demo/server/profile_settings</string>
<key>FontAntialias</key>
<false/>
<key>RunCommandAsShell</key>
<false/>
<key>ShowShellCommandInTitle</key>
<true/>
<key>TerminalType</key>
<string>xterm</string>
<key>WindowTitle</key>
<string>IDS Command Window</string>
<key>name</key>
<string>IDS Command Window</string>
<key>type</key>
<string>Window Settings</string>
</dict>
</plist>
You can click on it and the terminal window is launched, the profile settings are set, and then you have a command prompt to type at. Presumably, changing the 'dot' command into the 'tail' command of the question would work; it might be that the 'RunCommandAsShell' key set to '<true\>' would replace the normal shell with the command - which is perhaps more appropriate for the question.
Another way of doing this is by using the Elscripto ruby gem: https://github.com/Achillefs/elscripto. It allows yuo to easily specify terminal tabs using a YAML file
Open the tabs you want and set each one up as you wish, i.e. in tab 1, cd /etc, tab 2 cd /bin and so on. Now go to Window > Save Windows as Group. Click the checkbox 'Use window group when Terminal starts' and hey presto!
http://www.iterm2.com/#/section/features/split_panes
"Divide a tab up into multiple panes, each one of which shows a different session. You can slice vertically and horizontally and create any number of panes in any imaginable arrangement."
How to Create Custom iTerm2 Window Arrangements
Create a custom keyboard shortcut to automatically spawn a set of windows and splits with processes running.
With a shortcut cmd+shift+w transform split your window arrangement into 3 panels
https://www.youtube.com/watch?v=Rg8AT-nds1Q