debian and Ubuntu系统解决vi方向键乱跳一条命令版

前言

之前写过github的bash shell,可惜国内机器无法使用,今天出个一条命令版。github的bash命令如下,复制到机器执行就可以解决。(海外机器可正常使用):

bash <(wget -qO- -o- https://raw.githubusercontent.com/htazq/Auto/main/Auto-Vi.sh)

换源

推荐使用SuperManito大佬的一键换源脚本:

bash <(curl -sSL https://linuxmirrors.cn/main.sh)

代码

复制下来到终端直接执行就可以vi编辑器方向键乱跳的问题。其中原理就是debian和ubuntu系统的原生vi是vi-common,本身就是有问题的,可以通过卸载vi-common再安装vim-full,最后再插入几条配置让vi变得听话。因为我最近自己虚拟机整起来都没法上github如上一条命令解决,很难受,而国内的代码托管平台就跟屎一样,所以自己记录个一条命令解决版本。

if command -v vim &> /dev/null; then if ! grep -q "set nocompatible" $HOME/.vimrc; then echo "Vim is already installed. Skipping installation."; else if dpkg -l | grep -q vim-common; then sudo apt-get remove -y vim-common; fi; sudo apt-get install -y vim; fi; if [ -e $HOME/.vimrc ]; then echo "The .vimrc file already exists. Checking and adding missing configurations."; if ! grep -q "set nocompatible\|set backspace=2\|set number\|syntax on" $HOME/.vimrc; then echo "set nocompatible" >> $HOME/.vimrc; echo "set backspace=2" >> $HOME/.vimrc; echo "set number" >> $HOME/.vimrc; echo "syntax on" >> $HOME/.vimrc; fi; else echo "Creating .vimrc file with initial configurations."; echo "set nocompatible" >> $HOME/.vimrc; echo "set backspace=2" >> $HOME/.vimrc; echo "set number" >> $HOME/.vimrc; echo "syntax on" >> $HOME/.vimrc; fi; fi