Article 5C4HA [SOLVED] Setting Up Alias for Vim in order to use function instead

[SOLVED] Setting Up Alias for Vim in order to use function instead

by
PasBern
from LinuxQuestions.org on (#5C4HA)
Hello all,

I set up a function for having vim automatically create a backup file of the one I am opening. Now I want to set up an alias for vim to execute that function when using vim.

But when I create an alias in .bash_alias like the following, it doesn't work

Code:alias vim ='vimbk'
My function in .bashrc looks like the following and it is working flawlessly. I simply sometimes forget to use the function name but open a file which the traditional vim command instead

Code:function vimbk() {
130 echo "You are making of copy of $1 before you open it. Please press ENTER in order to proceed."
131 read nul
132 cp $1 $1.bak_$(date +%F_%R)
133 vim $1
134 }
The problem is that the alias is accepted but then I run into a never ending loop where my shell keeps displaying the echo message or if I remove the message prompt from the script vim is not opening the file all the same.

Most likely this is due to my incomplete understanding of how to properly set up functions and using them with the bash shell.

Thanks for your tips how I can this running as intendedlatest?d=yIl2AUoC8zA latest?i=7R3TZEeS30w:BlKR-3iaH6U:F7zBnMy latest?i=7R3TZEeS30w:BlKR-3iaH6U:V_sGLiP latest?d=qj6IDK7rITs latest?i=7R3TZEeS30w:BlKR-3iaH6U:gIN9vFw7R3TZEeS30w
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments