0

I have Vim shortcuts which requires me to edit the ~/.bashrc file to stop some terminal shortcuts like <C-S> - which freezes the whole terminal - so I can use them in Vim. when I open a Vim file like vim somefile this works perfectly. However, when trying to edit system files using sudoedit somefile my shortcuts which require the terminal to stop using them while Vim is running are not working and <C-s> still freezes the whole terminal. I tried adding the same function in ~/.bashrc to /etc/bash.bashrc, /etc/profile, /root/.bashrc and /root/bash_profile but non of them work. is there a way I can do that? I know I can use sudo vim somefile but this is doesn't load my ~/.vimrc file so I will lose all my settins.

Here is the function in my ~/.bashrc file if that of any help:

#  No ttyctl, so we need to save and then restore terminal settings
vim()
{
   local STTYOPTS="$(stty --save)"
   stty stop '' -ixoff
   command vim "$@"
   stty "$STTYOPTS"
}

Thanks in advance for your help.

0

Okay!!

I found the answer myself if anyone is interested. It was just so stupid of me. My function calls command vim "$@" which means it's not used when sudoedit is called. So all I had to do is add a second function with the same content but named sudovim and it calles 'sudoedit' instead of vim. so now when I want to edit with sudoedit I just sudovim filename and when I want to edit without sudoedit I just call vim filename Here is my first function:

# stop some terminal shortcuts while using vim
vim()
{
   local STTYOPTS="$(stty --save)"
   stty stop '' -ixoff
   command vim "$@"
   stty "$STTYOPTS"
}

and the one with sudoedit:

# same as above but calls sudoedit which is defined in $SUDO_EDITOR
# use sudovim to write in sudoedit
sudovim()
{
    local STTYOPTS="$(stty --save)"
    stty stop '' -ixoff
    command sudoedit "$@"
    stty "$STTYOPTS"
}

put this in your ~/.bashrc then map in ~/.vimrc

| 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.