Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have in my .cvsrc:

cvs -q -e vim

I want to create an alias (like my-vim or something like that):

alias my-vim="vim -S ~/myscript.vim"

And do

cvs -q -e my-vim

Unfortunately, this doesn't work. What do I have to do to make an alias work inside cvs -e parameter?

share|improve this question
1  
The reason the alias doesn't work is that only the shell expands aliases, and likely cvs execs your editor without going through the shell, so it will have to be an actual command. –  glenn jackman Feb 28 '11 at 21:02
1  
@glenn: And even if cvs executes the editor via a shell, under most setups, aliases are only available in interactive shells (the others don't read .bashrc/.zshrc/…). –  Gilles Feb 28 '11 at 21:55
add comment

2 Answers 2

up vote 5 down vote accepted

I don't know how to get the alias to work inside CVS, but what you can do is write a script which invokes vim the way you want.

The script would simply be:

#!/bin/sh
vim -S ~/myscript.vim "$@" 

And then just save it somewhere in your $PATH with the name rvimmy-vim (for example /usr/local/bin/my-vim), and you should be able to use my-vim as a command both on your command-line and from within CVS.

If you don't want to put the script in a global directory on your system or don't have the rights to, just create $HOME/bin, put the script there, and add it to your $PATH.

share|improve this answer
1  
You can also create $HOME/bin and put all your scripts in there (and add it to PATH in your login profile). The CVS isn't going to know about shell aliases. –  Keith Feb 28 '11 at 19:14
1  
You would want to add "$@" as the filename argument to vim in that script. –  glenn jackman Feb 28 '11 at 20:59
1  
Also, rvim is already a command (restricted vim). OP might want to choose a different name. –  glenn jackman Feb 28 '11 at 21:01
    
Thanks for the comments, I improved my answer based on your suggestions –  Cedric Feb 28 '11 at 22:08
    
I'm doing your approach, but using $CVSEDITOR variable as suggested by @Gilles. Thank you both! –  Somebody still uses you MS-DOS Mar 1 '11 at 17:17
add comment

Set the environment variable CVSEDITOR to your favorite editor. This is not expanded by the shell, so the tilde won't work. So write a one-line shell wrapper and call that in CVSEDITOR. Write this as ~/bin/CVSEDITOR and make it executable:

#!/bin/sh
exec vim -S ~/myscript.vim

Then put the following line in your ~/.profile:

export CVSEDITOR=CVSEDITOR

If you want to use the same editor for everything, set the EDITOR and VISUAL variables instead (set the both to the same value).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.