Reputation: 177
I want gvim to always open in a separate window and return the command prompt immediately. In other words I want
gvim filename
to be the same as
gvim filename &
it seems like I should be able to do this with an alias. Is there a special wildcard character for aliases? Something like:
alias gvim="gvim <wildcard> &"
Where "wildcard" would be replaced by whatever text comes after gvim on the command line.
I also tried:
function gvim()
{
"/cygdrive/c/program files (x86)/vim/vim72/gvim.exe" "$@" "&" ;
}
But it only opens gvim and doesn't return the prompt like I want it to.
If someone could point me in the right direction, it would greatly improve my understanding of how .bashrc works.
Thanks!
-Derek
UPDATE: I got it to work by getting rid of the quotation marks around the & and the semicolon at the end:
function gvim()
{
"/cygdrive/c/program files (x86)/vim/vim72/gvim.exe" "$@" &
}
Upvotes: 2
Views: 2041
Reputation: 2648
The first thing to understand about .bashrc is probably that it only gets read when the shell starts -- in the case of cygwin, when you open the command window. It's not clear from your post whether you are restarting your command window, or what.
You can experiment with the aliases/functions without putting them in the .bashrc, just to find out what works. Just enter the aliases or function definitions directly on the command line, and then try to run them.
I think the problem with the function you provided is you put the &
inside double quotes. Take off the quotes and it should work.
Upvotes: 0
Reputation: 52858
What I do is have a small bash script that I call gvim with and alias that.
==> alias vi
alias vi='~/include/bin/dvim'
==> cat ~/include/bin/dvim
#!/bin/bash.exe
/cygdrive/c/Program\ Files/Vim/vim73/gvim.exe $1 &
Upvotes: 0
Reputation: 53634
The last is almost right. What is wrong is that plain &
tells shell to run process in the background and "&"
adds argument to the gvim command-line (i.e. instructs gvim to open file named &
). By using quotes here you just instruct shell not to treat &
specially and gvim has no reason to do the shell’s job.
Upvotes: 5
Reputation: 3554
instead of using alias, use a shell function. It works the same in general, and you've got more options available to you:
function gvim() {
gvim.bat `cygpath -w $*` &
}
Update Also, there are some hooks in the default .bashrc (on my box anyway) to automatically load functions from a ".bash_functions" file, you just need to uncomment it (about line 117 for me):
# Functions
#
# Some people use a different file for functions
if [ -f "${HOME}/.bash_functions" ]; then
source "${HOME}/.bash_functions"
fi
then add the function definition to .bash_functions to have it auto-loaded when you start a bash shell.
Update 2 added call to cygpath to handle full paths in unix form
Upvotes: 0