How can I script vim to run perltidy on a buffer?

后端 未结 6 1319
终归单人心
终归单人心 2021-02-02 00:42

At my current job, we have coding-style standards that are different from the ones I normally follow. Fortunately, we have a canned RC file for perltidy that I can

6条回答
  •  醉梦人生
    2021-02-02 00:49

    Instead of creating a new keyboard shortcut, how about replacing the meaning of the = command which is already in people's finger memory for indenting stuff? Yes, perlcritic does more than just indent but when you use perlcritic anyways, then you probably don't want to go back to the inferior "just indent" = command. So lets overwrite it!

    filetype plugin indent on
    autocmd FileType perl setlocal equalprg=perltidy
    

    And now we can use = just like before but with the added functionality of perlcritic that goes beyond just indenting lines:

    ==   run perlcritic on the current line
    5==  run perlcritic on five lines
    =i{  Re-indent the 'inner block', i.e. the contents of the block
    =a{  Re-indent 'a block', i.e. block and containing braces
    =2a{ Re-indent '2 blocks', i.e. this block and containing block
    gg=G run perlcritic on the entire buffer
    

    And the best part is, that you don't have to learn any new shortcuts but can continue using the ones you already used with more power. :)

提交回复
热议问题