4

This is an alias defined in my Linux shell:

$ alias vi
alias vi='vim'

This alias is so stupid that I want to delete it definitely.

Is there a command to find where alias vi='vim' might have been defined? Something like Vim's :verbose [option]??


Update:

After hours of search, I found that alias vi=vim is located in /etc/profile.d/vim.sh, which is sourced by /etc/bashrc, which is sourced by .etc/.bashrc, which is sourced by ~/.bash_profile. Such a long journey!

Though I have located alias vi=vim, There is still a question:

Is there an easier way to do this? Is there a way that answer these question: Is alias defined through the command line, a script file, or something else? If defined in a script file, which file it is?

The method used above is "brute-force search". There maybe a dozen files that sourced by ~/.bash_profile. It is so inefficient that it spent me hours to debug.

Feng Yu
  • 175
  • 4
  • 2
    hmmm... is the command you are looking for *not* `alias` then? oh wait, i see - you're talking about in the text editor. i think you want either `: abbrev` or `: map`. no - that's not it either. you want to know where it was *defined*? you could try `grep -l 'alias vi' ~/.*` to start. – mikeserv Dec 19 '15 at 07:39
  • @mikeserv Yes, I want to know where `alias vi='vim'` locate. I want to delete that statement. That alias is really terrible. – Feng Yu Dec 19 '15 at 07:47
  • hahahaha!!! do the `grep` - it's almost definitely in one of your dot files in `$HOME` - probably some `~/.shellrc` or `~/.profile` or `~/.shenv` or something like that. the `grep` will spit out the file name. you could do: `grep -n 'alias vi' ~/.* /dev/null` to ensure you get the whole matched line and the filenames and the line numbers for wherever it is matched. – mikeserv Dec 19 '15 at 07:49
  • @mikeserv I have tried `grep` my home directory, but noting print. And I don't want to grep root directory, that is awkard! – Feng Yu Dec 19 '15 at 07:55
  • true. ok, well, there's `/etc` possibly in `profile` - though that would be weird - or `bash/bashrc` or `zsh/zshrc` or something. another way is to do: `"$0" -vx` to get a printout of all of the commands read in when a new shell starts. – mikeserv Dec 19 '15 at 07:57
  • sorry about the tag... haha. – mikeserv Dec 19 '15 at 08:07
  • By the way which shell are you using? (`echo $SHELL`) – Pandya Dec 19 '15 at 10:08
  • @Pandya bash shell – Feng Yu Dec 19 '15 at 10:10
  • @FengYu And alias isn't defined at `.bashrc` , `.bash_aliases` or at `.bash_profile` right? – Pandya Dec 19 '15 at 10:13
  • 1
    I am not sure that substitution `vi` <-- `vim` have done via **alias**. In deb-distro such operation is provided via **update-alternatives** – Costas Dec 19 '15 at 11:26
  • 1
    Please execute `type -a vi` to find out if there is an alias defined for vi. –  Dec 20 '15 at 00:00

0 Answers0