I have searched and found threads related to this, but not exactly the same case.
I use VIM in Windows7. It's set as the default editor for text files.
The problem is when I click in some text file in order to open it, it is opened in a new VIM window no matter if I already have one or more VIM windows opened.
How to change this behavior?
Thanks!
UPDATE:
This program solved my problem: http://defaultprogramseditor.com/
You should manually set up your file associations in Windows to launch Vim with a custom command. If you're an administrator and don't mind messing with EVERYBODY's config, you can use the ftype and assoc commands in the cmd.exe shell. Otherwise, you can manually create registry entries in HKEY_CURRENT_USER\Software\Classes.
The registry method actually sets up the same structure that you would set up automatically with ftype and assoc. First you must create a file type like "sourcecode" under that Classes key, with shell\open\command key having the exact command you want to open Vim with, using %1 in place of the file name to pass in. Then create a association key like .c with a value of the filetype you created, in this case "sourcecode".
Some details on file associations here: http://vim.wikia.com/wiki/Windows_file_associations
Specifically for setting up "launch in tabs" behavior, you want --remote-tab-silent, as done here: http://vim.wikia.com/wiki/Launch_files_in_new_tabs_under_Windows
vim has a "remote-server" concept, which allows you to open files in single/certain vim instance.
vim's man page (help doc too: :h remote) has the explanation. in short:
vim --serverlist #list names of all found vim servers
vim --servername {name} #current instance becomes as server named {name}
vim --servername {name} --remote file #open file in {name} vim-server
You can still send keys to the remote vim, when the buffer load by --remote-send or with command ... --remote +{cmd} file
For your requirement, you want to open files in a vim server's tab page, you could:
vim --servername FOO --remote-tab yourfile
Related
I am trying to update my .bash_profile but the changes are not being reflected.
When I type ~/.bash_profile in command line, i get the error "zsh: No such file or directory: Users/My.Name/.bash_profile".
Why can't terminal find it? How do I help it locate the file? When I go to Users/My.Name directory and show hidden files, the .bash_profile is there.
If you type
~/.bash_profile
on your command line while using zsh, as it seems you do, if the file exists you'll receive
zsh: permission denied: /Users/username/.bash_profile
because usually the file does not have execute permission set.
You could source the file, but it's not a good idea to load init files from different shells as syntax differs.
The reason why terminal can't find your .bash_profile is because you are using zsh as your default shell, not bash. Zsh is a newer and it has its own configuration file called .zshrc. If you want to update your zsh settings, you need to edit the .zshrc file instead of the .bash_profile file.
To help terminal locate the file, you can use the full path of the file instead of the relative path. The full path starts with a slash (/) and specifies the exact location of the file in the file system. The relative path starts with a tilde (~) and specifies the location of the file relative to your home directory. For example, the full path of your .zshrc file is /Users/My.Name/.zshrc, while the relative path is ~/.zshrc.
To edit the .zshrc file, you can use any text editor of your choice, such as nano, vim, or VS Code. For example, to edit the file using nano, you can type the following command in terminal:
nano /Users/My.Name/.zshrc
This will open the file in nano, where you can make your changes and save them. To exit nano, press Ctrl+X, then Y, then Enter.
Explanation
A shell is a program that interprets your commands and runs them on your computer. There are different types of shells, such as bash, zsh, ksh, and csh. Each shell has its own syntax, features, and configuration files. You can check which shell you are using by typing the following command in terminal:
echo $SHELL
This will print the full path of your current shell. For example, if you are using zsh, it will print /bin/zsh.
A configuration file is a file that contains settings and preferences for your shell. It is usually hidden, meaning that it starts with a dot (.). It is executed every time you open a new terminal session, so it can affect your environment variables, aliases, functions, and other aspects of your shell. For example, you can use a configuration file to change your prompt, set your PATH, or enable some plugins.
The most common configuration file for bash is .bash_profile, while the most common configuration file for zsh is .zshrc. They are usually located in your home directory, which is the directory that contains your personal files and folders. You can access your home directory by typing ~ in terminal.
To edit a configuration file, you need to use a text editor, which is a program that allows you to create and modify text files. There are many text editors available, such as nano, vim, VS Code, Sublime Text, and Atom. Each text editor has its own commands, shortcuts, and features. For example, nano is a simple and easy-to-use text editor that runs in terminal, while VS Code is a powerful and modern text editor that runs in a graphical user interface.
Examples
Here are some examples of how to edit your .zshrc file using different text editors:
To edit the file using vim, type the following command in terminal:
vim /Users/My.Name/.zshrc
This will open the file in vim, where you can make your changes and save them. To exit vim, press Esc, then :, then x, then Enter.
To edit the file using VS Code, type the following command in terminal:
code /Users/My.Name/.zshrc
This will open the file in VS Code, where you can make your changes and save them. To exit VS Code, click on the red X button on the top left corner of the window.
To edit the file using Sublime Text, type the following command in terminal:
subl /Users/My.Name/.zshrc
This will open the file in Sublime Text, where you can make your changes and save them. To exit Sublime Text, click on the red X button on the top right corner of the window.
I am using a oh-my-zsh shell in an Apple terminal (2.11) in full screen, and by default the name of the tabs is the name of the program being run (eg. vim).
Is there an easy way to set the title of the individual terminal tabs to the filename currently opened with vim?
The terminal window title is already set, but not visible in full screen mode. What I'm looking for is to get at a glance the title of all terminal tabs where vim is opened.
Screenshot below:
The solution seems to use vim script shared in https://stackoverflow.com/a/48975505/4756084. It sets the title dynamically based on what file is currently being viewed — which you cannot obtain by going into Terminal Preferences > Tab, and checking "Active process name" and "Arguments" (that would only display the name of the file opened when typing vim file.ext, ignoring any file opened with :e file2.txt, switches between vim panes, etc.)
(With oh-my-zsh, uncommenting DISABLE_AUTO_TITLE="true" in ~/.zshrc might help, as suggested in https://superuser.com/questions/292652/change-iterm2-window-and-tab-titles-in-zsh, although it seems optional after the step above.)
I'm running Geany 1.34.1 under Windows 10. Whenever I click a text file on Windows Explorer Geany opens the file in a new instance.
How can I configure Geany so that it opens all files in a single instance only?
According to a section of the Geany documentation, the behavior you want should occur unless Geany is started with the appropriate command line option. From the table of command line options, that would be either -i or --new-instance.
Check your file type association for text files and delete either of those command line options if they're there.
If no options are found, you might check your Geany configuration file to see if there's something related to starting a new instance. If so, you can try deleting the related stuff and see what happens. Be sure to make a backup copy of the configuration file before editing it so you can recover in case something goes terribly wrong.
If no options are found anywhere, then it may be a bug in the Windows version of Geany.
I made a mistake in my gnome terminal configuration. I entered a command to start with in the preferences, but that command fails, and now all I get is a window that opens and closes right away, and I basically can't use gnome terminal anymore :-( Is there any way I can remove the configuration file and restart fresh??
Thanks!
Open the XTerm (Standard terminal for linux) and enter this command
gnome-terminal -e bash
It opens the gnome-terminal. Open profile preferences and configure your terminal to "Hold the terminal open".
Editing preferences
$HOME/.gconfd/saved_state
the above file might be of interest depending on exactly what configuration you changed. Of course, it holds configuration from other programs as well.
If you are on the newer gnome terminal that uses dconf, it's a little trickier, but still doable:
Profiles are stored with a UUID, you need to find the UUID of the profile to remove:
dconf dump /org/gnome/terminal/ | less
Search for a visible-name='...' entry matching the profile you want to remove. Look above that for the section header like [legacy/profiles:/:...]. The full name of the item you want to delete is thus /org/gnome/terminal/legacy/profiles:/:.... Delete it thus:
dconf reset -f /org/gnome/terminal/legacy/profiles:/:...
Side note: This Q&A probably should be moved to unix.stackexchange.com.
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.