Vim supplement and multi-conditional judgment

Source: Internet
Author: User

I. VIM split screen display file (edit mode)

    ctrl+w然后按s 水平分屏    ctrl+w然后按v垂直分屏    ctrl+w按方向键切换屏幕    :qa退出所有窗口

Two, vim edit multiple files

    vim file1 file2  默认显示第一个文件,在末行模式下使用:next,:prev进行下一个上一个切换    也可以加参数 -o 或 -O ,如 vim file1 file2 可以将文件左右或上下显示,使用ctrl+w再按方向键切换屏幕    文件另存为:在末行模式下,使用 :w /path/newfile 将文件另存为/path下的newfile。

Third, some common configuration of vim (in the last line mode)

    显示行号 :set number , 取消行号 :set nonumber    自动缩进 :set ai    注意这些配置只是临时生效,要想永久生效需要写入配置文件,对当前用户生效,可以写入 ~/.vimrc,全局生效可以写入 /etc/virc 或/etc/vimrc

Four, the combination condition judgment

    -a 或 &&:与条件    -o 或 ||:或条件    -not  或 !:非条件    如 [  $A  -a  $B   ] 表示$A和$B同时为真,才为真

Example: Scripting addusers.sh when adding options and parameters--add User1,user2 ... When adding these users when adding options and parameters--del User1,user2 ... Delete these users, enter Q, Q, quit when you exit the script,--help view help information.

    #!bin/bashOPT=$1USERS=$2if [[ $# -lt 1 || $OPT == ‘q‘ || $OPT == ‘Q‘ || $OPT == ‘quit‘ ]];then    echo "exit.."    exit 2fiif [[ $OPT == ‘--add‘  ]];then    for u in `echo $USERS | sed ‘s/,/ /g‘` #将传入的USER1,USER2..去掉逗号转为列表    do        if  id $u &> /dev/null ;then            echo "$u is exist."        else            useradd $u            echo "$u add success."        fi    doneelif [[ $OPT == ‘--del‘  ]];then    for u in `echo $USERS | sed ‘s/,/ /g‘ `  #将传入的USER1,USER2...去掉逗号转为列表    do        if ! id $u &> /dev/null ;then            echo "$u is not exist."        else            userdel -r $u            echo "$u del success."        fi    doneelif [[ $OPT == ‘--help‘  ]];then    echo "usg: addusers --add/--del  user1,user2..."    exit 0else    echo "请输入--help查看帮助。"fi

Vim supplement and multi-conditional judgment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.