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!

Nitrodist
  • 1,608
  • 2
  • 13
  • 25
Jason
  • 337
  • 3
  • 8

2 Answers2

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.

Patches
  • 16,136
  • 3
  • 55
  • 61
  • 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 http://superuser.com/questions/176783/what-is-the-difference-between-executing-a-bash-script-and-sourcing-a-bash-script http://stackoverflow.com/questions/1107808/what-happens-when-i-execute-a-unix-shell-script-using-a-command and http://stackoverflow.com/questions/1880735/difference-between-launching-a-script-with-script-sh-and-script-sh – 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
slhck
  • 223,558
  • 70
  • 607
  • 592
Riller
  • 11
  • 1