<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Calvin's Tech Space

    成于堅(jiān)忍,毀于浮躁

       :: 首頁(yè) :: 聯(lián)系 :: 聚合  :: 管理
    在VIM下使用gg=G格式化shell代碼時(shí),如果代碼中有heredoc,經(jīng)過(guò)格式化后會(huì)造成代碼運(yùn)行失敗。如下:
    do
    ??? echo "Deploying..."
    ??? ssh $USER@$HOST <<-EOF
    cd clat
    mv client client-bak-`date +%Y%m%d`
    tar zxf `basename $TARGET_DEPLOY_ZIP` -C .
    exit
    EOF

    ??? echo ""


    格式化后會(huì)成這樣:
    do
    ??? echo "Deploying..."
    ??? ssh $USER@$HOST <<-EOF
    ???? cd clat
    ???? mv client client-bak-`date +%Y%m%d`
    ???? tar zxf `basename $TARGET_DEPLOY_ZIP` -C .
    ???? exit

    ??? EOF
    ??? echo ""
    done


    vim對(duì)heredoc的代碼進(jìn)行了縮進(jìn)(四個(gè)空格),這樣會(huì)導(dǎo)執(zhí)行出錯(cuò)。

    解決:修改vim格式化shell腳本的規(guī)則,格式化時(shí)忽略heredoc。

    將如下腳本保存到.vim/indent/sh.vim:
    (來(lái)源:http://vim.1045645.n5.nabble.com/bash-heredoc-in-a-for-loop-indented-incorrectly-td1177006.html)
    " Vim indent file
    " Language:??? Shell Script
    " Maintainer:?????? Nikolai Weibull <[hidden email]>
    " Latest Revision:? 2006-04-19

    if exists("b:did_indent")
    ? finish
    endif
    let b:did_indent = 1

    setlocal indentexpr=GetShIndent()
    setlocal indentkeys+==then,=do,=else,=elif,=esac,=fi,=fin,=fil,=done,=EOF,=END
    setlocal indentkeys-=:,0#

    if exists("*GetShIndent")
    ? finish
    endif

    let s:cpo_save = &cpo
    set cpo&vim

    function GetShIndent()
    ? let lnum = prevnonblank(v:lnum - 1)
    ? if lnum == 0
    ??? return 0
    ? endif

    ? " Add a 'shiftwidth' after if, while, else, case, until, for, function()
    ? " Skip if the line also contains the closure for the above
    ? let ind = indent(lnum)
    ? let line = getline(lnum)
    ? if line =~ '^\s*\(if\|then\|do\|else\|elif\|case\|while\|until\|for\)\>'
    ??????? \ || line =~ '^\s*\<\k\+\>\s*()\s*{'
    ??????? \ || line =~ '^\s*{'
    ??? if line !~ '\(esac\|fi\|done\)\>\s*$' && line !~ '}\s*$'
    ????? let ind = ind + &sw
    ??? endif
    ? endif

    ? if line =~ '^.*<<.*\(EOF\|END\)'
    ??? let ind = 0
    ? endif
    ? if line =~ '^"\?\(EOF\|END\)"\?$'
    ??? let ind = indent(search('>.*EOF', 'b'))
    ? endif
    ? " Subtract a 'shiftwidth' on a then, do, else, esac, fi, done
    ? " Retain the indentation level if line matches fin (for find)
    ? let line = getline(v:lnum)
    ? if (line =~ '^\s*\(then\|do\|else\|elif\|esac\|fi\|done\)\>' || line =~ '^\s*}')
    ??????? \ && line !~ '^\s*fi[ln]\>'
    ??? let ind = ind - &sw
    ? endif

    ? return ind
    endfunction

    let &cpo = s:cpo_save
    unlet s:cpo_save

    不過(guò)delimiter只能是EOF或者END。

    posted on 2011-05-26 18:23 calvin 閱讀(453) 評(píng)論(0)  編輯  收藏 所屬分類: VIM

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产aa免费视频| 亚洲短视频在线观看| 国产自国产自愉自愉免费24区 | 高潮毛片无遮挡高清免费视频| 亚洲熟伦熟女新五十路熟妇| 99免费观看视频| 亚洲av成人片在线观看| 亚洲av无码精品网站| 在线A级毛片无码免费真人| a级毛片免费完整视频| 7777久久亚洲中文字幕| 久久国产成人精品国产成人亚洲| 99xxoo视频在线永久免费观看| 亚洲AV综合永久无码精品天堂| 国产V亚洲V天堂A无码| 日本人的色道www免费一区| 日韩精品无码免费专区午夜不卡| 中文字幕亚洲综合久久综合| 久久伊人亚洲AV无码网站| 成人毛片18女人毛片免费96 | 亚洲变态另类一区二区三区| 亚洲国产精品SSS在线观看AV | 亚洲国产一区在线观看| 亚洲日韩国产精品乱| 国产成在线观看免费视频| a级毛片在线视频免费观看| 久久亚洲中文无码咪咪爱| 亚洲高清视频在线播放| 在线观看亚洲成人| 国产性生交xxxxx免费| 免费不卡视频一卡二卡| 国内精品免费视频精选在线观看 | 亚洲精品美女久久7777777| 78成人精品电影在线播放日韩精品电影一区亚洲 | 爱情岛亚洲论坛在线观看| 亚洲精品网站在线观看你懂的| 色久悠悠婷婷综合在线亚洲| 国产精品国产免费无码专区不卡 | 不卡精品国产_亚洲人成在线 | 中文字幕亚洲综合久久菠萝蜜| 国产成人精品免费直播|