5

I've been trying to find out how to change application executables (I don't know how to call them) so when you do vim file in the console it actually runs nano file.

I don't care if vim is installed or not on the operating system.

How can I achieve this?

kos
  • 35,891
Alex
  • 173
  • 8

2 Answers2

7

You can use an alias, that way you don't have to move vim and the behavior is changed only at the shell's level:

printf 'alias vim=nano\n' >>~/.bashrc
. ~/.bashrc
kos
  • 35,891
  • 1
    This should either be function vim { nano "$@"; }\n (note the quotes around the arguments) or simply alias vim=nano\n. – wchargin Nov 29 '15 at 20:59
  • 2
    (You need the quotes for the word-splitting to work properly; try vim "file name" in each case.) – wchargin Nov 29 '15 at 21:00
  • @WChargin Not sure what I was thinking, I initially proposed an alias in fact (see the revision history) but switched to a function. Really, I don't know what I thought. Thanks, I also added the newline (which I forgot previously). – kos Nov 29 '15 at 21:12
3

With a symbolic link in /usr/local/bin. This works even after the installation of vim, because applications in /usr/local/bin have a higher priority per default PATH settings. To run the native vim installation you would have to run the full path /usr/bin/vim.

sudo ln -s /usr/bin/nano /usr/local/bin/vim

Check the symbolic link with

stat /usr/local/bin/vim

You should see something like this:

  File: ‘/usr/local/bin/vim’ -> ‘/usr/bin/nano’
  Size: 11          Blocks: 0          IO Block: 4096   symbolic link
Device: 801h/2049d  Inode: 5377195     Links: 1
Access: (0777/lrwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2015-11-29 20:22:49.266067541 +0100
Modify: 2015-11-29 20:22:47.566056452 +0100
Change: 2015-11-29 20:22:47.566056452 +0100
 Birth: -
A.B.
  • 90,397