How to start Gvim from Command Prompt? - vim

I tried to start gvim using start command like this
start gvim.exe
But it doesn't work for gvim, although it does work for firefox.exe. My questions are-
How can I start gvim from command prompt?
Why start command doesn't work for gvim.exe?
Are there any additional parameter that I can use when starting gvim from command prompt?

Completely different, so a separate answer:
Actually, -- I just remembered -- Vim isn't normally added to the path variable, it's run through .bat files in C:\Windows.
From another answer on StackOverflow:
When you install gVim: Please make sure Create .bat files for
command line use is checked. It'll create several .bat files in
C:\Windows\:
C:\>cd %windir%
C:\WINDOWS>dir /b *.bat
evim.bat
gview.bat
gvim.bat
gvimdiff.bat
view.bat
vim.bat
vimdiff.bat
vimtutor.bat

This is because gvim.exe is not in your PATH list. If you know which directory gvim.exe resides, add this directory to your PATH list. This can be done by typing the following in an Explorer address bar:
Control Panel\System and Security\System
Then press Advanced system setings, then Environment Variables. The PATH is a list of directories separated by a ;.

Try typing just "gvim" instead of "start gvim.exe". That works for me. Vim isn't in my path environment variable.

Related

Alacritty: run a startup script?

I'm on Windows 10 and trying to run a startup script (vcvars64.bat) to setup the MSVC compiler before using the Alacritty prompt.
I have tried the -e switch with the command and also with the alacritty.yml shell: option, but both options open Alacritty, run the command, then exit.
How do I run a script on startup as the first command then continue into Alacritty?
Thanks,
Matic
What I ended up with is:
Specify program: cmd.exe in Alacritty alacritty.yml:
shell:
program: cmd.exe
Create a shortcut to Alacritty.exe and place it eg. in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ (so that it shows up in Windows search).
In properties for the shortcut, under target, specify:
"C:\Program Files\Alacritty\alacritty.exe" --command "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat >/NUL" && bash.exe
Modify Visual Studio path to whatever you have, and which varsall.bat you want to use.
The tricky part was how sensitive cmd.exe is regarding quotes. Eg., it does not work for me to specify an absolute path to which bash.exe to use, it would fail on the first whitespace in the path no matter how I tried to quote it. So make sure the correct bash.exe is first in your PATH (open plain cmd.exe and run where bash.exe to see order). Another solution is of course to create a shortcut to the bash.exe of your liking to a place without spaces in its path then specify it's absolute path (tested to work).

iterm broken pipe when running tmux from profile command

Getting Broken Pipe when executing tmux command from profile on iterm2.
When I execute tmux from command line there is no problem.
>echo $PATH
>/Users/myname/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/tmux:/usr/local/MacGPG2/bin
The path seems to be ok.
Any idea how to fix that ?
The solution was adding full path to the command
/usr/local/bin/tmux
TL;DR: You do not have /usr/local/bin/ in path, only /usr/local/bin/tmux.
/usr/local/bin/tmux is not a directory, it is an executable.
$PATH searches all its directories in the order specified for an executable that you're looking for. There is no tmux inside /usr/local/bin/tmux, so it doesn't find anything there.
You need to make your path include /usr/local/bin

Problems opening Vim from the command line? (Windows 8)

How do you install Vim such that it runs in the command line?
I saw a post here and it said to make sure that
[✓] Create .bat files for command line use
was checked. I did make sure that it was checked, but vim won't open in the command line. However,
gvim
will open gvim from the command line, which is a pop-up window. How do I open Vim so that I can edit files directly from the command line? I think that I need to edit the PATH, but I don't know what that is or how to edit it.
EDIT: I also looked at this and followed the directions, tailored to my system. Now vimtutor will briefly open the vimtutor for less than a second and close it! But Vim still doesn't work. Gvim will open Gvim still.
EDIT: I don't think I was clear when I wrote my post. Running
vim
does not open Vim on my computer. Neither does
vim.exe
Use the bottom right Win8 gesture and go as following: Settings > PC Info > Advanced System Settings > Advanced > Environment Variables. Under system variables find Path in the list.
Path is just a semicolon separated list of directories. Append vim.exe to the list and it's now in your path.
You want to run vim.exe, not gvim.exe.
Add this to the Path under system variables "C:\Program Files\Vim\vim82" . Then you are all done.
To Edit Environment Variables:
Click on Start Menu -> Type Environment Variables and Press Enter Supporting Image -> In bottom Right Corner you will find "Environment Variables" Supporting Image -> Under System Variables Search for Path Supporting Image -> Double Click To Edit -> Click on new and Paste the file address given AboveSupporting Image
Now you're done. Test it just by writing vim in Command Prompt or Windows Terminal.

Eclipse doesn't use the path set in .bashrc

whenever I run eclipse from the shortcut I am unable to correctly build some of my projects because the PATH variable that I configured in .bashrc doesn't get used.
When I run eclipse from my terminal, I can build all my projects perfectly fine because it's running through the correct shell.
The problem is that I want to use the PATH variable from my .bashrc without permanently having a terminal open. I tried this before, but every day I accidentally close the terminal that's running eclipse by accident and lose all my unsaved code.
Can anyone help me?
Your tooling probably utilizes the embedded eclipse terminal. This terminal does not start providing your login/user shell. So you need to set the eclipse terminal in your Eclipse preferences to start as --login shell:
Go to:
Preferences -> Terminal -> Local Terminal
and set
"Arguments" to "--login"
restart Eclipse and your users $PATH should be used from now on.
Edit /usr/share/applications/eclipse.desktop with write privileges, i.e. sudo gedit /usr/share/applications/eclipse.desktop
Change the setting Exec=/usr/bin/eclipse to Exec=bash -ic "/usr/bin/eclipse" and save
The underlying issue is that .bashrc is not loaded in a non-interactive shell. When you start Eclipse normally clicking on its symbol, .bashrc quits early. This solution applies to all programs that are defined by a .desktop file.
In contrast, bash -i opens an interactive shell, -c "" runs a command in that shell.
I can think of two options for this problem:
write a small script, export those vars or source your .bashrc before you start your eclipse.
define those variables in /etc/environment. then they are not user-scope any more.
I prefer the 1st option.
Create simple script
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"
2.
Next put your all system variables in file /home/user/.environment_variables (any file you want)
My looks like:
export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
3.
Now you can delete your variables in .bashrc and put line
source /home/user/.environment_variables
Everything works fine :)
Well, this is already answered and the answer has been accepted. But this will also work for running your code using Eclipse. You can edit the Run Configurations and set the environment variable there. Then, Eclipse will pick up the variable from this setting while building.

Running gvim from MSYS --- how to avoid/change MSYS enviroment variables?

When I run gvim from MSYS, things go wrong during initialization. Namely, gvim can't find the initialization files that are in 'C:\Documents and Settings\username\vimfiles.
[Specifically, gvim reports the error E117: Unknown function: pathogen#infect during initialization, so it never found autoload\pathogen.vim. Doing :scriptnames also confirms that none of the setup files from vimfiles\ are run.]
I think I've debugged why it goes wrong. When you start MSYS, the MSYS shell inherits the windows enviroment variables, but changes some of them to it's custom values. C:\Documents and Settings\username is the value of $HOME in Windows, but MSYS sets it to something like C:/msys/user name. And of course, Vim uses $HOME to find the right initialization files.
I also notice set shell? has changed to something like shell=C:/msys/bin/sh instead of shell=C:\WINDOWS\system32\cmd.exe, but I hope this isn't important for fixing the initialization problem.
I need to run gvim with the normal windows environment variables. At least I need to be able to manually override a few important ones like $HOME to something I specify (i.e., I'm not concerned about my windows $HOME changing, so it's fine to use a static value).
I tried to reset $HOME manually in my vimrc, but by then it is too late.
Is there some trick to specifying $HOME early on during initialization, or as an extra command line parameter?
Alternatively, is there some trick with running commands from msys differently? I know almost nothing about how the shell C:/msys/bin/sh works, but I could conceive of some extra arguments that changes the visibile environment for the command (e.g. gvim.exe) you are typing.
---Edit---
Reposting the solution that worked (it achieves the later idea):
Instead of running gvim.exe, run the command HOME="C:\Documents and Settings\username" gvim.exe
In bash and other UNIX shells, you can do:
$ HOME='/path/to/dir' gvim
to temporarily set $HOME to a different value.
I admit I'm not familiar at all with the Windows command line, but it might be worth a try.
I believe you can define $HOME just like any other environment variable.
Try adding this to the start of your .vimrc.
let $HOME="C:\Documents and Settings\username"
I had a similar issue when running Cygwin (which is similar to MSYS).
The easiest solution for me was to simply set the HOME environment variable to an empty string. Otherwise, the Cygwin HOME value would be appended to the Windows USERPROFILE in GVim and it would fail to start correctly. Not explicitly setting the full path of the HOME means that I can use the same start-up files on different systems where the USERNAME may not be the same.
Likewise, the SHELL environment variable should not be inherited from Cygwin Bash. This results in errors when running shell or external programs via !. Again, I set this to be an empty variable since Vim is smart enough to figure out what it should be.
In my .bashrc, I set the following alias for running Windows gvim which starts GVim with the HOME and SHELL variables set to an empty string – just for that command.
gvim="/cygdrive/c/Program Files (x86)/Vim/vim74/gvim"
if [ -x "$gvim" ]; then
alias gvim="HOME= SHELL= \"$gvim\""
fi
unset gvim
I achieved this by making a windows symbol link (Win 7 or higher).
Via a symbol link, you can even make vim and gvim to use the same configuration and plugin.

Resources