developer tip

Perl 개발을위한 이상적인 Vim 구성에 대한 제안은 무엇입니까?

copycodes 2020. 12. 13. 09:49
반응형

Perl 개발을위한 이상적인 Vim 구성에 대한 제안은 무엇입니까?


PerlMonks.org 에서 Perl 개발 위해 Vim / GVim 을 구성하는 방법과 관련된 많은 스레드가 있습니다 . 이 질문을 게시하는 목적은 Vim / GVim을 사용하여 Perl 개발을위한 이상적인 구성을 가능한 한 많이 만드는 것입니다. 설정에 대한 제안 과 유용한 플러그인 을 게시하십시오 ..vimrc

권장 사항을 설정 세트 .vimrc와 권장 플러그인, ftplugins 및 구문 파일 목록에 병합하려고 합니다.

.vimrc 설정

"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>

vmap <tab> >gv    "make tab in v mode indent code"
vmap <s-tab> <gv

nmap <tab> I<tab><esc> "make tab in normal mode indent code"
nmap <s-tab> ^i<bs><esc>

let perl_include_pod   = 1    "include pod.vim syntax file with perl.vim"
let perl_extended_vars = 1    "highlight complex expressions such as @{[$x, $y]}"
let perl_sync_dist     = 250  "use more context for highlighting"

set nocompatible "Use Vim defaults"
set backspace=2  "Allow backspacing over everything in insert mode"

set autoindent   "Always set auto-indenting on"
set expandtab    "Insert spaces instead of tabs in insert mode. Use spaces for indents"
set tabstop=4    "Number of spaces that a <Tab> in the file counts for"
set shiftwidth=4 "Number of spaces to use for each step of (auto)indent"

set showmatch    "When a bracket is inserted, briefly jump to the matching one"

통사론

플러그인

ftplugins

CPAN 모듈

디버깅 도구

방금 VimDebug 에 대해 알게되었습니다 . 아직 Windows에 설치할 수 없었지만 설명에서 유망 해 보입니다.


에서 색채의 블로그 (약간 모든 모드에서 같은 매핑을 사용할 수 있도록 적용).

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

히트 ,pt정상 모드에서 전체 파일을 정리하기 위해, 또는 시각적 모드에서 선택을 정리. 다음을 추가 할 수도 있습니다.

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

그러나 입력 모드에서 명령을 사용하는 것은 권장되지 않습니다.


" 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>

perl-support.vim (Vim / gVim 용 Perl IDE) 도 살펴보십시오 . Vim (.vimrc), gVim (.gvimrc), ctags, perltidy 및 Devel : SmallProf 사용자 지정에 대한 제안 사항이 다른 많은 항목과 함께 제공됩니다.


Perl Best Practices 에는 Editor Configurations 에 대한 부록이 있습니다 . vim은 나열된 첫 번째 편집기입니다.


Andy Lester와 다른 사람들 은 Github에서 Vim에 대한 공식 Perl, Perl 6 및 Pod 지원 파일을 유지 합니다. https://github.com/vim-perl/vim-perl


정리를 위해 다음을 사용합니다. \t전체 파일을 정돈하기 위해, 또는 나는에 몇 줄의 선택 shift+V모드를 다음 할\t

nnoremap <silent> \t :%!perltidy -q<Enter>
vnoremap <silent> \t :!perltidy -q<Enter>

때로는 코드를 분리하는 것도 유용합니다. 위의 줄과 같이 전체 파일 또는 선택 항목에 대해.

nnoremap <silent> \D :.!perl -MO=Deparse 2>/dev/null<CR>
vnoremap <silent> \D :!perl -MO=Deparse 2>/dev/null<CR>

.vimrc :

" Allow :make to run 'perl -c' on the current buffer, jumping to 
" errors as appropriate
" My copy of vimparse: http://irc.peeron.com/~zigdon/misc/vimparse.pl

set makeprg=$HOME/bin/vimparse.pl\ -c\ %\ $*

" point at wherever you keep the output of pltags.pl, allowing use of ^-]
" to jump to function definitions.

set tags+=/path/to/tags

주말에 찾은 흥미로운 모듈이 App::EditorTools::Vim있습니다.. 가장 흥미로운 기능은 어휘 변수의 이름을 바꾸는 기능입니다. 안타깝게도 내 테스트에 따르면 아직 프로덕션 용도로 사용할 준비가되지 않은 것 같지만 주시 할 가치가있는 것 같습니다.


다음은 몇 가지 .vimrc 설정입니다. Perl에 한정되지 않을 수도 있지만, 이것 없이는 작업 할 수 없습니다.

set nocompatible        " Use Vim defaults (much better!) "
set bs=2                " Allow backspacing over everything in insert mode "
set ai                  " Always set auto-indenting on "
set showmatch           " show matching brackets "

" for quick scripts, just open a new buffer and type '_perls' "
iab _perls #!/usr/bin/perl<CR><BS><CR>use strict;<CR>use warnings;<CR>

2 개 있습니다.

내가 아는 첫 번째는 다른 사람에게서 일부를 얻었지만 누군지 기억할 수 없습니다. 알 수없는 사람 죄송합니다. Perl에서 "C ^ N"자동 완성 작업을 수행하는 방법은 다음과 같습니다. 다음은 내 .vimrc 명령입니다.

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

그런 다음 cron을 설정하여 installed_modules.dat 파일을 생성합니다. 내 mandriva 시스템입니다. 그에 따라 조정하십시오.

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

두 번째는 Perl에서 gf를 사용할 수있게 해줍니다. Gf는 다른 파일에 대한 바로 가기입니다. 커서를 파일 위에 놓고 gf를 입력하면 해당 파일이 열립니다.

" 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')

다음 약어가 유용하다고 생각합니다.

iab perlb  print "Content-type: text/html\n\n <p>zdebug + $_ + $' + $`  line ".__LINE__.__FILE__."\n";exit;
iab perlbb print "Content-type: text/html\n\n<p>zdebug  <C-R>a  line ".__LINE__.__FILE__."\n";exit;
iab perlbd do{print "Content-type: text/html\n\n<p>zdebug  <C-R>a  line ".__LINE__."\n";exit} if $_ =~ /\w\w/i;
iab perld print "Content-type: text/html\n\n dumper";use Data::Dumper;$Data::Dumper::Pad="<br>";print Dumper <C-R>a ;exit;

iab perlf foreach $line ( keys %ENV )<CR> {<CR> }<LEFT><LEFT>
iab perle while (($k,$v) = each %ENV) { print "<br>$k = $v\n"; }
iab perli x = (i<4) ? 4 : i;
iab perlif if ($i==1)<CR>{<CR>}<CR>else<CR>{<CR>}
iab perlh $html=<<___HTML___;<CR>___HTML___<CR>

펄로만 만들 수 있습니다.

au bufenter *.pl iab xbug print "<p>zdebug ::: $_ :: $' :: $`  line ".__LINE__."\n";exit;

지금까지 가장 유용한 것은

  1. Perl 파일 유형 연결 (ftplugin)-다양한 코드 요소를 색상으로 구분합니다.
  2. 저장 전 구문 검사 명령 "W"를 생성하여 잘못된 코드를 저장하지 못하도록합니다 (일반적인 'w'로 재정의 할 수 있음).

플러그인을 설치하는 것은 vim (및 Linux) 버전이 다른 위치에 플러그인을 배치하기 때문에 약간 까다 롭습니다. 내 것은 ~ / .vim / after /에 있습니다.

내 .vimrc 아래.

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

참고 URL : https://stackoverflow.com/questions/1573782/what-are-your-suggestions-for-an-ideal-vim-configuration-for-perl-development

반응형