µ±Ç°Î»ÖãºLinux½Ì³Ì - Linux - Îļþ±à¼­Æ÷ vi ֮ʹÓ÷½·¨¼ò½é

Îļþ±à¼­Æ÷ vi ֮ʹÓ÷½·¨¼ò½é



         vi ÊÇ visual editor µÄËõд£¬ÊÇ UNIX ËùÌṩµÄ±à¼­Æ÷Ö®Ò»¡£ËüÌṩʹÓÃÕßÒ»¸öÊÓ´°µÄ±à¼­»·¾³£¬ÔÚ´ËÊÓ´°Ï£¬Ê¹ÓÃÕ߿ɱ༭ËùÒªµÄÎļþ¡£vi¡¢celvis(cvi) ÊÇÔÚ¹¤×÷Õ¾Éϱ»¹ã´óʹÓõÄÖÐÓ¢Îı༭ÈíÌå¡£¶Ô³õѧÕ߶øÑÔ£¬³£ÒòÆäÌØÊâµÄʹÓ÷½·¨£¬¶ø²»µÃÆäÃŶøÈ룻¶ÔÒѾ­ÔÚʹÓà vi µÄʹÓÃÕßÀ´Ëµ£¬Ò²³£¼ûÒò¶Ô vi µÄ²»ÊìϤ»ò²»¹»Á˽⣬¶øÎÞ·¨·¢»Ó³ö vi Ç¿´óµÄ±à¼­ÄÜÁ¦£¬ÒÔϽ«½éÉÜ vi ֮ʹÓ÷½·¨¼ò½é¡£

    ½øÈëvi
    ======
    Ö±½ÓÖ´ÐÐ vi±à¼­³Ìʽ¼´¿É£º
    %vi test
    ´Ë¿ÌÓ©Ä»ÉÏ»á³öÏÖ vi µÄ±à¼­ÊÓ´°£¬Í¬Ê± vi »á½«Îļþ¸´ÖÆÒ»·ÝÖÁ¼ÇÒäÌåÖÐ
    µÄ»º³åÇø (buffer) ¡£ vi»á±£ÁôÔÚ´ÅÅÌÖеÄÎļþ²»±ä£¬¶øÏȶԻº³åÇøµÄµµ
    °¸×÷±à¼­£¬±à¼­Íê³Éºó£¬Ê¹ÓÃÕ߿ɾö¶¨ÊÇ·ñҪȡ´úÔ­À´¾ÉÓеÄÎļþ¡£

    À뿪vi
    ======
    ÈôÔÚÊäÈëģʽÏ£¬ÔòÏÈÀûÓá¶ESC¡·½øÈëÖ¸Áîģʽ£¬¶øºó¼´¿ÉÑ¡ÓÃÏÂÁÐÖ¸Áî
    À뿪vi¡£
    £ºq! À뿪vi£¬²¢·ÅÆú¸ÕÔÚ»º³åÇøÄڱ༭µÄÄÚÈÝ
    £ºwq ½«»º³åÇøÄÚµÄ×ÊÁÏдÈë´ÅÅÌÖУ¬²¢À뿪vi
    £ºZZ ͬwq
    £ºx ͬwq
    £ºw ½«»º³åÇøÄÚµÄ×ÊÁÏдÈë´ÅÅÌÖУ¬µ«²¢²»À뿪vi
    £ºq À뿪vi£¬ÈôÎļþ±»Ð޸Ĺý£¬Ôò»á±»ÒªÇóÈ·ÈÏÊÇ·ñ·ÅÆúÐ޸ĵÄÄÚÈÝ,´ËÖ¸Áî¿ÉÓ룺w ÅäºÏʹÓÃ

    vi µÄ²Ù×÷ģʽ
    =============
    vi ÌṩÁ½ÖÖ²Ù×÷ģʽ£ºÊäÈëģʽ(insert mode)ºÍÖ¸Áîģʽ(command mode)¡£µ±Ê¹ÓÃÕß½øÈë vi ºó£¬¼´´¦ÔÚÖ¸ÁîģʽÏ£¬´Ë¿Ì¼üÈëÖ®ÈκÎ×ÖÔª½Ô±»ÊÓΪָÁî¡£ÔÚ´ËģʽÏ¿ɽøÐÐɾ³ý¡¢Ð޸ĵȶ¯×÷¡£ÈôÒªÊäÈë×ÊÁÏ£¬ÔòÐè½øÈëÊäÈëģʽ¡£

    ÊäÈëģʽ
    ========
    ÈçºÎ½øÈëÊäÈëģʽ
    a (append) ÓÉÓαêÖ®ºó¼ÓÈë×ÊÁÏ¡£
    A ÓɸÃÐÐ֮ĩ¼ÓÈë×ÊÁÏ¡£
    i (insert) ÓÉÓαê֮ǰ¼ÓÈë×ÊÁÏ¡£
    I ÓɸÃÐÐÖ®Ê×¼ÓÈë×ÊÁÏ¡£
    o (open) ÐÂÔöÒ»ÐÐ춸ÃÐÐ֮Ϲ©ÊäÈë×ÊÁÏÖ®Óá£
    O ÐÂÔöÒ»ÐÐ춸ÃÐÐÖ®ÉϹ©ÊäÈë×ÊÁÏÖ®Óá£

    ÈçºÎÀ뿪ÊäÈëģʽ
    ¡¶ESC¡· ½áÊøÊäÈëģʽ¡£

    Ö¸Áîģʽ
    ========
    ÓαêÖ®Òƶ¯
    h Ïò×óÒÆÒ»¸ö×ÖÔª¡£
    j ÏòÉÏÒÆÒ»¸ö×ÖÔª¡£
    k ÏòÏÂÒÆÒ»¸ö×ÖÔª¡£
    l ÏòÓÒÒÆÒ»¸ö×ÖÔª¡£
    0 ÒÆÖÁ¸ÃÐÐÖ®Ê×
    $ ÒÆÖÁ¸ÃÐÐ֮ĩ¡£
    ^ ÒÆÖÁ¸ÃÐеĵÚÒ»¸ö×ÖÔª´¦¡£
    H ÒÆÖÁÊÓ´°µÄµÚÒ»ÁС£
    M ÒÆÖÁÊÓ´°µÄÖмäÄÇÁС£
    L ÒÆÖÁÊÓ´°µÄ×îºóÒ»ÁС£
    G ÒÆÖÁ¸ÃÎļþµÄ×îºóÒ»ÁС£
    + ÒÆÖÁÏÂÒ»ÁеĵÚÒ»¸ö×ÖÔª´¦¡£
    - ÒÆÖÁÉÏÒ»ÁеĵÚÒ»¸ö×ÖÔª´¦¡£
    ( ÒÆÖÁ¸Ã¾äÖ®Êס£ (×¢Ò»)
    ) ÒÆÖÁ¸Ã¾ä֮ĩ¡£
    { ÒÆÖÁ¸Ã¶ÎÂäÖ®Êס£ (×¢¶þ)
    } ÒÆÖÁ¸Ã¶ÎÂä֮ĩ¡£
    nG ÒÆÖÁ¸ÃÎļþµÄµÚ n ÁС£
    n+ ÒÆÖÁÓαêËùÔÚλÖÃÖ®ºóµÄµÚ n ÁС£
    n- ÒÆÖÁÓαêËùÔÚλÖÃ֮ǰµÄµÚ n ÁС£
    <Ctrl><g> »áÏÔʾ¸ÃÐÐÖ®Ðкš¢ÎļþÃû³Æ¡¢ÎļþÖÐ×îÄ©ÐÐÖ®Ðкš¢ÓαêËùÔÚÐкÅÕ¼×ÜÐкÅÖ®°Ù·Ö±È¡£

    ×¢Ò»£º¾ä×Ó(sentence)ÔÚviÖÐÊÇÖ¸ÒÔ¡º£¡¡»¡¢¡º.¡»»ò¡º£¿¡»½áÊøµÄÒ»´®×Ö¡£
    ×¢¶þ£º¶ÎÂä(paragraph)ÔÚviÖÐÊÇÖ¸ÒÔ¿Õ°×Ðиô¿ªµÄÎÄ×Ö¡£

    ÊÓ´°µÄÒƶ¯
    ==========
    <Ctrl><f> ÊÓ´°ÍùϾíÒ»Ò³¡£
    <Ctrl><b> ÊÓ´°ÍùÉϾíÒ»Ò³¡£
    <Ctrl><d> ÊÓ´°ÍùϾí°ëÒ³¡£
    <Ctrl><u> ÊÓ´°ÍùÉϾí°ëÒ³¡£
    <Ctrl><e> ÊÓ´°ÍùϾíÒ»ÐС£
    <Ctrl><y> ÊÓ´°ÍùÉϾíÒ»ÐС£

    ɾ³ý¡¢¸´ÖƼ°ÐÞ¸ÄÖ¸Áî½éÉÜ (´Ëµ¥Ôª½ÏÉÙʹÓÃ)
    =========================
    d(delete)¡¢c(change)ºÍy(yank)ÕâÒ»ÀàµÄÖ¸ÁîÔÚ vi ÖеÄÖ¸Áî¸ñʽΪ£º
    Operator + Scope = command
    (ÔËËã×Ó) (·¶Î§)
    ÔËËã×Ó£º
    d ɾ³ýÖ¸Áɾ³ý×ÊÁÏ£¬µ«»á½«É¾³ý×ÊÁϸ´ÖƵ½¼ÇÒäÌ建³åÇø¡£
    y ½«×ÊÁÏ(×Ö×é¡¢ÐÐÁС¢¾ä×Ó»ò¶ÎÂä)¸´ÖƵ½»º³åÇø¡£
    p ·ÅÖÃ(put)Ö¸ÁÓë d ºÍ y ÅäºÍʹÓ᣿ɽ«×îºódelete»òyankµÄ×Ê
    ÁÏ·ÅÖÃì¶ÓαêËùÔÚλÖÃÖ®ÐÐÁÐÏ¡£
    c ÐÞ¸Ä(change)Ö¸ÁÀàËÆdeleteÓëinsertµÄ×éºÍ¡£É¾³ýÒ»¸ö×Ö×é¡¢¾ä
    ×ÓµÈÖ®×ÊÁÏ£¬²¢²åÈëмü×ÊÁÏ¡£

    ·¶Î§£º
    e ÓÉÓαêËùÔÚλÖÃÖÁ¸Ã×Ö´®µÄ×îºóÒ»¸ö×ÖÔª¡£
    w ÓÉÓαêËùÔÚλÖÃÖÁÏÂÒ»¸ö×Ö´®µÄµÚÒ»¸ö×ÖÔª¡£
    b ÓÉÓαêËùÔÚλÖÃÖÁÇ°Ò»¸ö×Ö´®µÄµÚÒ»¸ö×ÖÔª¡£
    $ ÓÉÓαêËùÔÚλÖÃÖÁ¸ÃÐеÄ×îºóÒ»¸ö×ÖÔª¡£
    0 ÓÉÓαêËùÔÚλÖÃÖÁ¸ÃÐеĵÚÒ»¸ö×ÖÔª¡£
    ) ÓÉÓαêËùÔÚλÖÃÖÁÏÂÒ»¸ö¾ä×ӵĵÚÒ»¸ö×ÖÔª¡£
    ( ÓÉÓαêËùÔÚλÖÃÖÁ¸Ã¾ä×ӵĵÚÒ»¸ö×ÖÔª¡£
    { ÓÉÓαêËùÔÚλÖÃÖÁ¸Ã¶ÎÂäµÄ×îºóÒ»¸ö×ÖÔª¡£
    } ÓÉÓαêËùÔÚλÖÃÖÁ¸Ã¶ÎÂäµÄµÚÒ»¸ö×ÖÔª¡£

    ÕûÐж¯×÷
    dd ɾ³ýÕûÐС£
    D ÒÔÐÐΪµ¥Î»£¬É¾³ýÓαêºóÖ®ËùÓÐ×ÖÔª¡£
    cc ÐÞ¸ÄÕûÐеÄÄÚÈÝ¡£
    yy yankÕûÐУ¬Ê¹ÓαêËùÔÚ¸ÃÐи´ÖƵ½¼ÇÒäÌ建³åÇø¡£

    ɾ³ýÓëÐÞ¸Ä
    ==========
    x ɾ³ýÓαêËùÔÚ¸Ã×ÖÔª¡£
    X ɾ³ýÓαêËùÔÚ֮ǰһ×ÖÔª¡£
    dd ɾ³ýÓαêËùÔÚ¸ÃÐС£
    r ÓýÓ춴ËÖ¸ÁîÖ®ºóµÄ×ÖԪȡ´ú(replace)ÓαêËùÔÚ×ÖÔª¡£
    È磺 ra ½«ÓαêËùÔÚ×ÖÔªÒÔ a È¡´úÖ®¡£
    R ½øÈëÈ¡´ú״̬£¬Ö±µ½¡¶ESC¡·ÎªÖ¹¡£
    s ɾ³ýÓαêËùÔÚÖ®×ÖÔª£¬²¢½øÈëÊäÈëģʽֱµ½¡¶ESC¡·¡£
    S ɾ³ýÓαêËùÔÚÖ®¸ÃÐÐ×ÊÁÏ£¬²¢½øÈëÊäÈëģʽֱµ½¡¶ESC¡·¡£

    °áÒÆÓ븴ÖÆ
    ==========
    ÀûÓà delete ¼° put Ö¸Áî¿ÉÍê³É×ÊÁÏ°áÒÆ֮ĿµÄ¡£
    ÀûÓà yank ¼° put Ö¸Áî¿ÉÍê³É×ÊÁϸ´ÖÆ֮ĿµÄ¡£
    yank ºÍ delete ¿É½«Ö¸¶¨µÄ×ÊÁϸ´ÖƵ½¼ÇÒäÌ建³åÇø£¬¶ø½åÓÉ put Ö¸Áî
    ¿É½«»º³åÇøÄÚµÄ×ÊÁϸ´ÖƵ½Ó©Ä»ÉÏ¡£
    Àý£º
    °áÒÆÒ»ÐÐ £®ÔÚ¸ÃÐÐÖ´ÐÐ dd
    £®ÓαêÒÆÖÁÄ¿µÄµØ
    £®Ö´ÐÐ p
    ¸´ÖÆÒ»ÐÐ £®ÔÚ¸ÃÐÐÖ´ÐÐ yy
    £®ÓαêÒÆÖÁÄ¿µÄµØ
    £®Ö´ÐÐ p

    Ö¸ÁîÖظ´
    ========
    ÔÚÖ¸ÁîģʽÖУ¬¿ÉÔÚÖ¸ÁîÇ°Ãæ¼ÓÈëÒ»Êý×Ö n£¬Ôò´ËÖ¸Á×÷»áÖظ´Ö´ÐÐ n
    ´Î¡£
    Àý£º
    ɾ³ý10ÐÐ £®10dd
    ¸´ÖÆ10ÐÐ £®10yy
    £®ÓαêÒÆÖÁÄ¿µÄµØ
    £®p
    Ö¸±êÍùÏÂÒÆ10ÐÐ £®10j

    È¡ÏûÇ°Ò»¶¯×÷(Undo)
    ==================
    ¼´¸´Ô­Ö´ÐÐÉÏÒ»Ö¸ÁîÇ°µÄÄÚÈÝ¡£

    u »Ö¸´×îºóÒ»¸öÖ¸Áî֮ǰµÄ½á¹û¡£
    U »Ö¸´Óαê¸ÃÐÐÖ®ËùÓиı䡣

    ËÑÑ°
    ====
    ÔÚviÖпÉËÑѰijһ×Ö´®£¬Ê¹ÓαêÒÆÖÁ¸Ã´¦¡£

    /×Ö´® ÍùÓαêÖ®ºóÑ°ÕÒ¸Ã×Ö´®¡£
    ?×Ö´® ÍùÓαê֮ǰѰÕÒ¸Ã×Ö´®¡£
    n ÍùϼÌÐøÑ°ÕÒÏÂÒ»¸öÏàͬµÄ×Ö´®¡£
    N ÍùÉϼÌÐøÑ°ÕÒÏÂÒ»¸öÏàͬµÄ×Ö´®¡£

    ×ÊÁϵÄÁ¬½Ó
    ==========
    J ¾ä×ÓµÄÁ¬½Ó¡£½«ÓαêËùÔÚÖ®ÏÂÒ»ÐÐÁ¬½ÓÖÁÓαê¸ÃÐеĺóÃæ¡£

    ÈôijÐÐ×ÊÁÏÌ«³¤Òà¿É½«Æä·Ö³ÉÁ½ÐУ¬Ö»Òª½«ÓαêÒÆÖÁ·Ö¿ªµã£¬½øÈëÊäÈëģʽ
    (¿ÉÀûÓà a¡¢iµÈÖ¸Áî)ÔÙ°´¡¶Enter¡·¼´¿É¡£

    »·¾³µÄÉ趨
    ==========
    £ºset nu É趨×ÊÁϵÄÐкš£
    £ºset nonu È¡ÏûÐкÅÉ趨¡£
    £ºset ai ×Ô¶¯ÄÚËõ¡£
    £ºset noai È¡Ïû×Ô¶¯ÄÚËõ¡£

    ×Ô¶¯ÄÚËõ(automatic indentation)
    Ôڱ༭Îļþ»ò³Ìʽʱ£¬ÓÐʱ»áÓöµ½ÐèÒªÄÚËõµÄ×´¿ö£¬¡º£ºset ai¡»¼´Ìṩ×Ô
    ¶¯ÄÚËõµÄ¹¦ÄÜ£¬ÓÃÏÂÀý½âÊÍÖ®£º
    £®vi test
    £®(½øÈë±à¼­ÊÓ´°ºó)
    this is the test for auto indent
    ¡¶Tab¡·start indent ¡û £ºset ai (Éè×Ô¶¯ÄÚËõ)
    ¡¶Tab¡·data
    ¡¶Tab¡·data
    ¡¶Tab¡·data ¡û £ºset noai (È¡Ïû×Ô¶¯ÄÚËõ)
    the end of auto indent.
    £®×¢£º<Ctrl><d> ¿Éɾ³ý¡¶Tab¡·×ÖÔª¡£

    exÖ¸Áî
    ======
    ¶Áд×ÊÁÏ
    £ºw ½«»º³åÇøµÄ×ÊÁÏдÈë´ÅÅÌÖС£
    £º10,20w test ½«µÚ10ÐÐÖÁµÚ20ÐеÄ×ÊÁÏдÈëtestÎļþ¡£
    £º10,20w>>test ½«µÚ10ÐÐÖÁµÚ20ÐеÄ×ÊÁϼÓÔÚtestÎļþÖ®ºó¡£
    £ºr test ½«testÎļþµÄ×ÊÁ϶ÁÈë±à¼­»º³åÇøµÄ×îºó¡£

    ɾ³ý¡¢¸´ÖƼ°°áÒÆ
    £º10,20d ɾ³ýµÚ10ÐÐÖÁµÚ20ÐеÄ×ÊÁÏ¡£
    £º10d ɾ³ýµÚ10ÐеÄ×ÊÁÏ¡£
    £º%d ɾ³ýÕû¸ö±à¼­»º³åÇø¡£
    £º10,20co30 ½«µÚ10ÐÐÖÁµÚ20ÐеÄ×ÊÁϸ´ÖÆÖÁµÚ30ÐÐÖ®ºó¡£
    £º10,20mo30 ½«µÚ10ÐÐÖÁµÚ20ÐеÄ×ÊÁÏ°áÒÆÖÁµÚ30ÐÐÖ®ºó¡£

    ×Ö´®ËÑÑ°ÓëÈ¡´ú
    s(substitute)Ö¸Áî¿ÉËÑѰijÐÐÁз¶Î§¡£
    g(global)Ö¸ÁîÔò¿ÉËÑÑ°Õû¸ö±à¼­»º³åÇøµÄ×ÊÁÏ¡£
    sÖ¸ÁîÒÔµÚÒ»¸öÂú×ã¸ÃÌõ¼þµÄ×Ö´®ÎªÆäÈ¡´úµÄ¶ÔÏó£¬Èô¸ÃÐÐÓÐÊý¸öÂú×ã¸ÃÌõ
    ¼þµÄ×Ö´®£¬Ò²½öÄÜÈ¡´úµÚÒ»¸ö£¬ÈôÏëÈ¡´úËùÓеÄ×Ö´®ÔòÐè¼ÓÉÏg²ÎÊý¡£
    £º1,$s/old/new/g ½«ÎļþÖÐËùÓеġºold¡»¸Ä³É¡ºnew¡»¡£
    £º10,20s/^/ / ½«µÚ10ÐÐÖÁµÚ20ÐÐ×ÊÁϵÄ×îÇ°Ãæ²åÈë5¸ö¿Õ°×¡£
    £º%s/old/new/g ½«±à¼­»º³åÇøÖÐËùÓеġºold¡»¸Ä³É¡ºnew¡»¡£

    »Ö¸´±à¼­Ê±±»ÖжϵÄÎļþ
    ======================
    Ôڱ༭¹ý³ÌÖУ¬Èôϵͳµ±µô»òÁ¬ÏßÖжϣ¬¶ø»º³åÇøµÄ×ÊÁϲ¢»¹Î´
    ±»Ð´»Ø´ÅÅÌʱ£¬µ±ÔٶȻص½ÏµÍ³£¬Ö´ÐÐÏÂÁÐÖ¸Áî¼´¿É»Ø¸´ÖжÏÇ°
    µÄÎļþÄÚÈÝ¡£
    %vi -r filename

    ±à¼­¶à¸öÎļþ
    ============
    viÒàÌṩͬʱ±à¼­¶à¸öÎļþµÄ¹¦ÄÜ£¬·½·¨ÈçÏ£º
    %vi file1 file2 ..



    VI ʹÓü¼ÇÉ

    x ɾ³ýÓαêËùÔÚ×ÖÔª¡£
    dd ɾ³ýÓαêËùÔÚµÄÁС£
    s ɾ³ýÓαêËùÔÚ×ÖÔª£¬²¢½øÈëÊäÈëģʽ¡£
    S ɾ³ýÓαêËùÔÚµÄÁУ¬²¢½øÈëÊäÈëģʽ¡£
    r ÐÞ¸ÄÓαêËùÔÚ×ÖÔª£¬r áá½ÓÖøÒªÐÞÕýµÄ×ÖÔª¡£
    R ½øÈëÈ¡´ú״̬£¬ÐÂÔö×ÊÁϻḲ¸ÇÔ­ÏÈ×ÊÁÏ£¬Ö±µ½°´[ESC]»Øµ½Ö¸ÁîģʽÏÂΪֹ¡£
    +$ Ìøµ½ÎļþÄ©
    [home] Ìøµ½ÐÐÊ×
    [end] Ìøµ½ÐÐÄ©
    +n Ìøµ½µÚ n ÐÐ
    nj ÏÂÌø n ÐÐ(hjkl·Ö±ð±íʾ×óÏÂÉÏÓÒ¶¼¿É·ÂÕÕÓÃÖ®)
    yy ¿½±´Ò»ÐÐ
    p Õ³Ìù¿½±´µÄÐÐ
    u ·µ»ØÉϴα༭£¨Ï൱ÓÚWINÖеij·Ïû£©
    /×Ö´® Ñ°ÕÒij¸ö×Ö´®
    /enter ¼ÌÐøÕÒÉϴεÄ×Ö´®
    :w ´æÅÌ
    :q Í˳ö
    :wq ´æÅ̲¢Í˳ö
    :q! Ç¿ÐÐÍ˳ö
    :wq! Ç¿ÐдæÅÌÍ˳ö


    Ìæ»»ÎļþÖеÄ×Ö·û´®
    ¡¡¡¡ÔÚvi½çÃæÏÂʹÓÃÃüÁî
    ¡¡¡¡:%s#/usr/bin#/bin#g
    ¡¡¡¡¿ÉÒÔ°ÑÎļþÖÐËùÓз¾¶/usr/bin»»³É/bin¡£Ò²¿ÉÒÔʹÓÃÃüÁ
    ¡¡¡¡:%s/usr/bin/bin/g
    ¡¡¡¡ÆäÖС°¡±ÊÇתÒå×Ö·û£¬±íÃ÷ÆäºóµÄ¡°/¡±×Ö·ûÊǾßÓÐʵ¼ÊÒâÒåµÄ×Ö·û£¬²»ÊÇ·Ö¸ô·û¡£

    Õû¸öÎļþµÄ¸÷Ðлòij¼¸ÐеÄÐÐÊ×»òÐÐβ¼ÓһЩ×Ö·û´®
    ¡¡¡¡$vi file
    ¡¡¡¡:3,$s/^/some string ÔÚÎļþµÄµÚÒ»ÐÐÖÁ×îºóÒ»ÐеÄÐÐÊײåÈë¡°some string¡±¡£
    ¡¡¡¡:%s/$/some string/g ÔÚÕû¸öÎļþÿһÐеÄÐÐβÌí¼Ó¡°some string¡±¡£
    ¡¡¡¡:%s/string1/string2/g ÔÚÕû¸öÎļþÖÐÌæ»»¡°string1¡±³É¡°string2¡±¡£
    ¡¡¡¡:3,7s/string1/string2/ ½öÌæ»»ÎļþÖеĵÚ3Ðе½µÚ7ÐÐÖеġ°string1¡±³É¡°string2¡±¡£
    ¡¡¡¡×¢Òâ: ÆäÖÐsΪsubstitute£¬%±íʾËùÓÐÐУ¬g±íʾglobal¡£

    ɾ³ý´ó¶ÎµÄÄÚÈÝ
    ¡¡¡¡Ê×ÏÈÀûÓñ༭ÃüÁî¡°vi file¡±´ò¿ªÎļþ£¬È»ºó½«¹â±êÒƵ½ÐèҪɾ³ýµÄÐд¦°´Ctrl+GÏÔʾÐкţ¬ÔÙµ½½áβ´¦ÔÙ°´Ctrl+G£¬ÏÔʾÎļþ½áβµÄÐкš£
    ¡¡¡¡ÀýÈ磺
    ¡¡¡¡:23,1045d
    ¡¡¡¡¼Ù¶¨2´ÎµÃµ½µÄÐкÅΪ23ºÍ1045£¬Ôò°ÑÕâÆÚ¼äµÄÄÚÈÝȫɾ³ý£¬Ò²¿ÉÒÔÔÚҪɾ³ýµÄ¿ªÊ¼ÐкͽáÊøÐÐÖÐÓÃma¡¢mbÃüÁî±ê¼Ç£¬È»ºóÀûÓá°:'a,'bd¡±ÃüÁîɾ³ý¡£

    ¡°Áí´æΪ¡±¹¦ÄÜ
    ¡¡¡¡$vi file
    ¡¡¡¡:w /tmp/1
    ¡¡¡¡±£´æËù×öµÄËùÓÐÐ޸ģ¬Ò²¿ÉÒÔ½«ÆäÖеÄijһ²¿·ÖÐ޸ı£´æµ½ÁÙʱÎļþ¡£
    ¡¡¡¡Èç¹û½ö½ö°ÑµÚ20¡«59ÐÐÖ®¼äµÄÄÚÈÝ´æÅ̳ÉÎļþ/tmp/1£¬ÎÒÃÇ¿ÉÒÔ¼üÈëÈçÏÂÃüÁ
    ¡¡¡¡:20,59w /tmp/1

    ÔÚÒ»¸öÐÂÎļþÖжÁÆäËûÎļþµÄÄÚÈÝ
    ¡¡¡¡$vi file
    ¡¡¡¡:r /etc/passwd ÔÚ´ò¿ªµÄÎļþfileÖйâ±êËùÔÚ´¦¶ÁÈë/etc/passwd
    ¡¡¡¡:%s/:.*//g ɾ³ý/etc/passwdÖÐÓû§ÃûºóÃæµÄ´ÓðºÅ¿ªÊ¼Ö±µ½ÐÐβµÄËùÓв¿·Ö¡£
    ¡¡¡¡ÄúÒ²¿ÉÒÔÔÚÖ¸¶¨µÄÐкźó¶ÁÈëÎļþÄÚÈÝ£¬ÀýÈçʹÓÃÃüÁ
    ¡¡¡¡:3r /etc/passwd
    ¡¡¡¡´ÓÐÂÎļþµÄµÚ3ÐпªÊ¼¶ÁÈë /etc/passwdµÄËùÓÐÄÚÈÝ¡£
    ¡¡¡¡ÎÒÃÇ»¹¿ÉÒÔʹÓÃÒÔÏ·½·¨É¾µôÎļþÖÐËùÓеĿÕÐм°ÒÔ#¿ªÊ¼µÄ×¢ÊÍÐС£
    ¡¡¡¡$cat squid.conf.default | grep -v '^$' | grep -v '^#'
    ·¢²¼ÈË:»áÓÎÓ¾µÄÓã À´×Ô:LinuxByte