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

后端 未结 6 1459
终归单人心
终归单人心 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条回答
  •  萌比男神i
    2021-02-02 00:51

    Taking hobbs' answer a step further, you can map that command to a shortcut key:

    command -range=% -nargs=* Tidy ,!perltidy -q
    noremap  :Tidy
    

    And another step further: Only map the command when you're in a Perl buffer (since you probably wouldn't want to run perltidy on any other language):

    autocmd BufRead,BufNewFile *.pl,*.plx,*.pm command! -range=% -nargs=* Tidy ,!perltidy -q
    autocmd BufRead,BufNewFile *.pl,*.plx,*.pm noremap  :Tidy
    

    Now you can press Ctrl-F6 without an active selection to format the whole file, or with an active selection to format just that section.

提交回复
热议问题