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 use Vim a lot, and I know how I can start vim in insert mode. So I have an alias named vii in my .bash_aliases file.

On other hand I use Git a lot too, and I have this line in my .gitconfig:

[core]
    editor = vi

To write a commit message the vi editor is opened every time and I have to go in insert mode. So I thought of replacing vi with vii, and did.

But the problem is when I do git commit, instead of opening the vim in insert mode, it gives this error:

error: cannot run vii: No such file or directory
error: There was a problem with the editor 'vii'.
Please supply the message using either -m or -F option.

This makes clear that git does not looks to .bash_aliases file, even it isn't related to bash in any way. It does directly looks if there is /usr/bin/vii or not. And executes it if it is.

The Question

Can I place the aliased version of vi as vii in /usr/bin/?

(and please don't suggest me to use git commit -m "<commit message>". There are other situation where I need vim in insert mode.)

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

Aliases are internal to each of your current shell environments - they are expanded by the currently running shell (bash in your case), so they only have effect on what you execute by typing/pasting in your terminal.

You have at least two options here:

  • create a wrapper script named vii that will execute vim -c 'startinsert' and put it preferably in /usr/local/bin/. The script only needs to contain

    #!/bin/bash
    exec vim -c 'startinsert' $@
    

    (Make sure to make it executable by running chmod +x /usr/local/bin/vii.) Depending on the PATH configuration of your git/other programs, you may need to specify full path to that wrapper script (i.e. editor = usr/local/bin/vii).

  • If it is ok for you to have vim always start in insert mode, configure it to do so by adding startinsert at the end of .vimrc.

share|improve this answer
add comment

Just set the editor variable to

[core]
editor = vim -c 'startinsert'

For your other answer, yes you can't place aliases in a directory as an alias is a concept from your shell. The normal way is to create an appropriate wrapper script to execute the specified commands, e.g.

#!/bin/sh
vim -c 'startinsert' "$*"

and save the script as vii and make it executable. You can place the script where ever you like but typically such scripts are saved in somewhere in your $HOME folder like $HOME/bin and not in the global directories.

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.