Skip to content

vi命令速查表

vi命令如何常用,放于此以备查。

% vi file

:

Last line mode —-> Command mode —-> Insert mode

<—-        <—-

(auto)        Esc

Last line mode:

/exp Go forward to exp

?exp Go backward to exp

:w Write buffer to disk

:w newfile Write buffer to newfile

:w! file Write Absolutely

:q Quit editor

:q! Quit,discarding buffer

:wq Write buffer and quit

:x Write if needed & quit

:f Edit & file status

:r Read file into buffer

:r file Read named file in

:e (Re)edit file

:e! (Re)edit,discard file in

:e file Edit nameed file

:3,8d Delete lines 3-8

:4,9m 12 Move lines 4-9 to 12

:2,5t 13 Copy lines 2-5 to 13

:5,9w file Write lines 5-9 to file

:s/old/new/ Current line,sub first “old” w/ “new”

:s/old/new/g Current line,sub each “old” w/ “new”

:3,9s/old/new Lines 3-9,sub first “old” w/ “new”

:%s/old/new All lines,sub first “old” w/ “new”

:%s/old/new/g All lines,sub each “old” w/ “new”

:s/pat./new A . matches any charcter

:s/pat*/new A * matches 0 or more “t”s

:s/pa[0-9aeioA-Z]/new selection set or range

:s/pa[^aeiou]/new match any non-vowel

:s/^pat/new anchor “par” to beginning of line

:s/pats/new anchor “par” to end of line

:s/old/& and new/ restoe matched pattern on sub

:%s/./ &/ indenta whoie file

:set nu Display line numbers

:set nonu Turn off option

:set all Show all settings

:set list Try to display invisible chars

:set wm=5 Wrap lines 5 sp from R margin

Command mode:

<- | ->

hljk Cursor movement

G Goto last file line

3G Goto line 3

0 Goto line start

$ Goto line end

% Goto matching brace/paren

H Goto screen top

M Goto screen middle

L Goto screen bottom

w Go forward 1 word

3w Go forward 3 word

b Go back 1 word

3b Go back 3 word

n Repeat previous search

N Reverse previous search

x Delete one character

dw Delete one word

dd Delete one line

D Delete to end of line

d0 Delete to beginning of line

dG Delete to end of file

4dd Delete 4 lines

u Undo last change

. Do last chang

Y Yank a copy of a line

5Y Yank a copy of 5 lines

P Put below cursor

p Put above cursor

J Join next line to current

4J Join 4 lines to current

>> Shift a line right

3>> Shift 3 lines right

^d 1/2 scroll forward

^u 1/2 scroll backwards

^f Scroll forward

^b Scroll backwards

n Repeat previous search

N Reverse previous search

ZZ Write if needed & quit vi

Insert mode:

a Append after cursor

A Append at line end

cw Change a word

3cw Change 3 words

C Change line

i Insert before cursor

5i Insert at 5 times

I Insert at beginning of line

o Open a linebelow cursor

O Open a line above cursor

r Replace one character

R Replace/type-cver a line

s Substitute a character

S Substitue a line

vi go to end(1)vi命令下载(1)vi 命令(3)php vi命令(1)vim f – forward(1)vi 替换(2)vim 命令 dd(1)php vi 命令(2)vi dd(1)vim 链接命令(1)mysql vi命令(2)lines(1)vim 命令 速查(1)vim goto(2)tokyo cabinet 说明(1)

Share in Google Reader Share in Google Reader 分享到 FriendFeed 分享到 FriendFeed 推荐到豆瓣 推荐到豆瓣 分享到 Twitter 分享到 Twitter

One Comment

  1. askie

    二、邮件发送远程备份
    首先安装上面下载的文件,然后做下面的配置

    vi /etc/Muttrc

    set sendmail=”/usr/bin/msmtp -a your_account”
    set realname=”your_email”
    set use_from=yes
    set editor=”vim”

    MSMTP

    创建user_home/.msmtprc和 user_home/.msmtp.log,分别为配置和日志文件。

    vi msmtprc

    account default
    host smtp.domain.com
    from your_email_address
    tls on
    auth on
    user user_name@domain.com
    password your_password

    account default : dominic

    由于password是明码,所以我们需要修改此文件的权限。

    chmod 600 .msmtprc

    到这里,你可以使用mutt来发送邮件了,我们测试一下。
    echo “test” |mutt -s “my_first_test” anyone@163.com -c anytwo@163.com

    -s “subject”
    -c “carbon-copy”

    观察.msmtp.log文件,如果有错会在日志文件中被报告出来,当然,成功发送的日志也会出现在此日志文件内。

    编写如下脚本
    #vi autoBakMysql.sh

    #!/bin/bash
    #Auto DB Backup shell
    #Powered by leo

    DBName=mysql
    DBUser=root
    DBPasswd=
    BackupPath=/root/
    LogFile=/root/db.log
    DBPath=/var/lib/mysql/
    #BackupMethod=mysqldump
    #BackupMethod=mysqlhotcopy
    #BackupMethod=tar
    #Setting End

    NewFile=”$BackupPath”db$(date +%y%m%d).tgz
    DumpFile=”$BackupPath”db$(date +%y%m%d)
    OldFile=”$BackupPath”db$(date +%y%m%d –date=’5 days ago’).tgz

    echo “——————————————-” >;>; $LogFile
    echo $(date +”%y-%m-%d %H:%M:%S”) >;>; $LogFile
    echo “————————–” >;>; $LogFile
    #Delete Old File
    if [ -f $OldFile ]
    then
    rm -f $OldFile >;>; $LogFile 2>;&1
    echo “[$OldFile]Delete Old File Success!” >;>; $LogFile
    else
    echo “[$OldFile]No Old Backup File!” >;>; $LogFile
    fi

    if [ -f $NewFile ]
    then
    echo “[$NewFile]The Backup File is exists,Can’t Backup!” >;>; $LogFile
    else
    case $BackupMethod in
    mysqldump)
    if [ -z $DBPasswd ]
    then
    mysqldump -u $DBUser –opt $DBName >; $DumpFile
    else
    mysqldump -u $DBUser -p$DBPasswd –opt $DBName >; $DumpFile
    fi
    tar czvf $NewFile $DumpFile >;>; $LogFile 2>;&1
    echo “[$NewFile]Backup Success!” >;>; $LogFile
    rm -rf $DumpFile
    ;;
    mysqlhotcopy)
    rm -rf $DumpFile
    mkdir $DumpFile
    if [ -z $DBPasswd ]
    then
    mysqlhotcopy -u $DBUser $DBName $DumpFile >;>; $LogFile 2>;&1
    else
    mysqlhotcopy -u $DBUser -p $DBPasswd $DBName $DumpFile >;>;$LogFile 2>;&1
    fi
    tar czvf $NewFile $DumpFile >;>; $LogFile 2>;&1
    echo “[$NewFile]Backup Success!” >;>; $LogFile
    rm -rf $DumpFile
    ;;
    *)
    /etc/init.d/mysqld stop >;/dev/null 2>;&1
    tar czvf $NewFile $DBPath$DBName >;>; $LogFile 2>;&1
    /etc/init.d/mysqld start >;/dev/null 2>;&1
    echo “[$NewFile]Backup Success!” >;>; $LogFile
    ;;
    esac
    fi

    echo “——————————————-” >;>; $LogFile

    echo “start email backup file”

    echo “test” |mutt -s “mysql_backup_file” anyone@163.com -c anytwo@163.com -s $DumpFile

    echo “#################### send success! ##################” >;>; $LogFile

    Posted on 01-Jul-08 at 9:43 pm | Permalink

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*