What are your suggestions for an ideal Vim configuration for Perl development?

后端 未结 12 1017
说谎
说谎 2021-01-29 17:56

There are a lot of threads pertaining to how to configure Vim/GVim for Perl development on PerlMonks.org. My purpose in posting this question is to try to create, as much as pos

相关标签:
12条回答
  • 2021-01-29 18:21

    By far the most useful are

    1. Perl filetype pluging (ftplugin) - this colour-codes various code elements
    2. Creating a check-syntax-before-saving command "W" preventing you from saving bad code (you can override with the normal 'w').

    Installing he plugins are a bit dicky as the version of vim (and linux) put the plugins in different places. Mine are in ~/.vim/after/

    my .vimrc below.

    set vb
    set ts=2
    set sw=2
    set enc=utf-8
    set fileencoding=utf-8
    set fileencodings=ucs-bom,utf8,prc
    set guifont=Monaco:h11
    set guifontwide=NSimsun:h12
    set pastetoggle=<F3>
    command -range=% -nargs=* Tidy <line1>,<line2>!
        \perltidy
    filetype plugin on
    augroup JumpCursorOnEdit
     au!
     autocmd BufReadPost *
     \ if expand("<afile>:p:h") !=? $TEMP |
     \ if line("'\"") > 1 && line("'\"") <= line("$") |
     \ let JumpCursorOnEdit_foo = line("'\"") |
     \ let b:doopenfold = 1 |
     \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
     \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
     \ let b:doopenfold = 2 |
     \ endif |
     \ exe JumpCursorOnEdit_foo |
     \ endif |
     \ endif
     " Need to postpone using "zv" until after reading the modelines.
     autocmd BufWinEnter *
     \ if exists("b:doopenfold") |
     \ exe "normal zv" |
     \ if(b:doopenfold > 1) |
     \ exe "+".1 |
     \ endif |
     \ unlet b:doopenfold |
     \ endif
    augroup END
    
    0 讨论(0)
  • 2021-01-29 18:23

    Andy Lester and others maintain the official Perl, Perl 6 and Pod support files for Vim on Github: https://github.com/vim-perl/vim-perl

    0 讨论(0)
  • 2021-01-29 18:25

    Look also at perl-support.vim (a Perl IDE for Vim/gVim). Comes with suggestions for customizing Vim (.vimrc), gVim (.gvimrc), ctags, perltidy, and Devel:SmallProf beside many other things.

    0 讨论(0)
  • 2021-01-29 18:26

    From chromatic's blog (slightly adapted to be able to use the same mapping from all modes).

    vmap ,pt :!perltidy<CR> 
    nmap ,pt :%! perltidy<CR>
    

    hit ,pt in normal mode to clean up the whole file, or in visual mode to clean up the selection. You could also add:

    imap ,pt <ESC>:%! perltidy<CR>
    

    But using commands from input mode is not recommended.

    0 讨论(0)
  • 2021-01-29 18:27

    I have 2.

    The first one I know I picked up part of it from someone else, but I can't remember who. Sorry unknown person. Here's how I made "C^N" auto complete work with Perl. Here's my .vimrc commands.

    " to use CTRL+N with modules for autocomplete "
    set iskeyword+=:
    set complete+=k~/.vim_extras/installed_modules.dat
    

    Then I set up a cron to create the installed_modules.dat file. Mine is for my mandriva system. Adjust accordingly.

    locate *.pm | grep "perl5" | sed -e "s/\/usr\/lib\/perl5\///" | sed -e "s/5.8.8\///" | sed -e "s/5.8.7\///" | sed -e "s/vendor_perl\///" | sed -e "s/site_perl\///" | sed -e "s/x86_64-linux\///" | sed -e "s/\//::/g" | sed -e "s/\.pm//" >/home/jeremy/.vim_extras/installed_modules.dat
    

    The second one allows me to use gf in Perl. Gf is a shortcut to other files. just place your cursor over the file and type gf and it will open that file.

    " To use gf with perl "
    set path+=$PWD/**,
    set path +=/usr/lib/perl5/*,
    set path+=/CompanyCode/*,   " directory containing work code "
    autocmd BufRead *.p? set include=^use
    autocmd BufRead *.pl set includeexpr=substitute(v:fname,'\\(.*\\)','\\1.pm','i')
    
    0 讨论(0)
  • 2021-01-29 18:29
    " Create a command :Tidy to invoke perltidy.
    " By default it operates on the whole file, but you can give it a
    " range or visual range as well if you know what you're doing.
    command -range=% -nargs=* Tidy <line1>,<line2>!
        \perltidy -your -preferred -default -options <args>
    
    0 讨论(0)
提交回复
热议问题