Last Modified:
Vimでperllocal.podを折り畳んで表示する #Perl #Vim
perllocal.podが見難く編集し難いので、vimで開いた時に自動的にfoldingされるようにしました。
結果↓のように見れるようになります。編集も楽チン。
+-- 22 行:=head2 Mon Feb 4 11:45:23 2013: C<Module> L<App::cpanminus|App::cpanminus>----------------------------------------
+-- 22 行:=head2 Mon Feb 4 12:06:30 2013: C<Module> L<App::cpanoutdated|App::cpanoutdated>----------------------------------
+-- 22 行:=head2 Mon Feb 4 12:12:45 2013: C<Module> L<App::pmuninstall|App::pmuninstall>------------------------------------
~/.vimrcに以下のコードを追加すると動くと思います。=head2~=backをひとまとめにしているだけです。
function! s:fold_perllocal()
function! l:foldexpr(lnum)
if getline(v:lnum) =~ '^=head2'
return '1'
elseif getline(v:lnum - 1) =~ '^=back'
return '<1'
endif
return '='
endfunction
setlocal foldmethod=expr foldexpr=l:foldexpr(v:lnum)
endfunction
autocmd BufRead perllocal.pod call s:fold_perllocal()
ちなみに例で挙げた3行は普通にperldoc
で見るとこんな感じです。
Mon Feb 4 11:45:23 2013: "Module" App::cpanminus
* "installed into: ./local/lib/perl5"
* "LINKTYPE: dynamic"
* "VERSION: 1.5021"
* "EXE_FILES: bin/cpanm"
Mon Feb 4 12:06:30 2013: "Module" App::cpanoutdated
* "installed into: ./local/lib/perl5"
* "LINKTYPE: dynamic"
* "VERSION: 0.24"
* "EXE_FILES: bin/cpan-outdated"
Tue Mon Feb 4 12:12:45 2013: "Module" App::pmuninstall
* "installed into: ./local/lib/perl5"
* "LINKTYPE: dynamic"
* "VERSION: 0.29"
* "EXE_FILES: bin/pm-uninstall"
折り畳まれてる方が断然見やすいですよね。
更にperldoc -m
でソースを見るともう何が何やら。folding偉大です。
=head2 Mon Feb 4 11:45:23 2013: C<Module> L<App::cpanminus|App::cpanminus>
=over 4
=item *
C<installed into: ./local/lib/perl5>
=item *
C<LINKTYPE: dynamic>
=item *
C<VERSION: 1.5021>
=item *
C<EXE_FILES: bin/cpanm>
=back
=head2 Mon Feb 4 12:06:30 2013: C<Module> L<App::cpanoutdated|App::cpanoutdated>
=over 4
=item *
C<installed into: ./local/lib/perl5>
=item *
C<LINKTYPE: dynamic>
=item *
C<VERSION: 0.24>
=item *
C<EXE_FILES: bin/cpan-outdated>
=back
=head2 Mon Feb 4 12:12:45 2013: C<Module> L<App::pmuninstall|App::pmuninstall>
=over 4
=item *
C<installed into: ./local/lib/perl5>
=item *
C<LINKTYPE: dynamic>
=item *
C<VERSION: 0.29>
=item *
C<EXE_FILES: bin/pm-uninstall>
=back