2

In my laptop, if I type below

$ which vi
alias vi='vim'
    /usr/bin/vim

Now I want to change the vi alias to another bin, e.g. vim_wrapper a script created in /usr/bin/, I type this line:

alias vi="vim_wrapper"

in ~/.bashrc or /etc/bashrc, but take no effects. So How to change the default vi alias vi='vim' to vi='vim_wrapper'? Thanks for help!

3

Aliases added to bashrc don't take effect immediately. You have to restart your terminal session or logout and log back in.

To make the alias take effect immediately, run the alias line you added on a terminal as if it were a command or source your bashrc as Nitrodist explains in the first comment.

| improve this answer | |
  • Not quite the same thing. You have to source the file (instead of running it with ~/bashrc on its own), otherwise the changes will not be reflected in the terminal. So, either do . ~/.bashrc or source ~/.bashrc. – Nitrodist May 25 '11 at 17:40
  • @Nitrodist: Out of curiosity, what is the difference? Obviously your method is better if you add more than one alias or make other changes, but for just adding one alias you'd think both methods would have the same effect. – Patches May 25 '11 at 17:48
  • just executing the file does not make those changes available in your terminal. If I export a variable in the .bashrc and I execute the script instead of sourcing it, then that exported variable disappears after the script finishes executing. See superuser.com/questions/176783/… stackoverflow.com/questions/1107808/… and stackoverflow.com/questions/1880735/… – Nitrodist May 25 '11 at 18:21
  • @Nitrodist: I meant run the alias command, but that wasn't very clear in my post. I've updated it. – Patches May 25 '11 at 19:05
1

You can try to modify the original vi alias set. Here's my grep result:

/etc/profile.d/vim.sh: alias vi >/dev/null 2>&1 || alias vi=vim
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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