This document discusses how Vim can improve productivity for Perl coding. It provides examples of using Vim motions and modes like Normal mode, Insert mode, and Visual mode to efficiently edit code. It also covers Vim features like syntax highlighting, custom syntax files, key mappings, and text objects that are useful for Perl. The document advocates that Vim is a powerful editor rather than an IDE and highlights how it can save significant time compared to less efficient editing methods.
1 of 225
Downloaded 799 times
More Related Content
Perl.Hacks.On.Vim
1. Perl Hacks
on Vim
Lin You-An
c9s / Cornelius
pause id: CORNELIUS
28. #!/usr/bin/env perl
my $happiness = yapcasia->join();
if this costs 4 sec
if x 50 times this kind of situation per day
and you work for more than 300 day per year
= 16.6 hours
29. #!/usr/bin/env perl
my $happiness = yapcasia->join();
if this costs 4 sec
x 50 times this kind of situation per day ?
and you work for more than 300 day per year
= 16.6 hours
30. #!/usr/bin/env perl
my $happiness = yapcasia->join();
if this costs 4 sec
Awful
x 50 times this kind of situation per day ?
and you work for more than 300 day per year
= 16.6 hours
81. Insert Mode
• i : Insert text before the cursor
• I : Insert text before the first non-blank in the
line
82. Insert Mode
• i : Insert text before the cursor
• I : Insert text before the first non-blank in the
line
• a : Append text after the cursor
83. Insert Mode
• i : Insert text before the cursor
• I : Insert text before the first non-blank in the
line
• a : Append text after the cursor
• A : Append text at the end of the line
96. Template::Declare
template simple => sub {
html {
head {}
body {
p {'Hello, world wide web!'}
}
}
};
# ... templates
99. package MyView;
use Markapl;
tempalte '/a/page.html' => sub {
h1("#title") { "Hi" };
p(".first") { "In the begining, lorem ipsum...." };
p(style => "color: red;") { "But...." };
}
100. Jifty::DBI::Schema
package TestApp::Model::Phone;
use Jifty::DBI::Schema;
use Jifty::DBI::Record schema {
column user =>
references TestApp::Model::User by 'id',
is mandatory;
column type => ...;
column value => ...;
};
133. Fold Methods
Syntax Fold
:set foldmethod=syntax
set fold method as syntax , check out more options in:
$VIMRUNTIME/syntax/*.vim
134. Perl built-in syntax
/opt/local/share/vim/vim72/syntax/perl.vim
if exists("perl_want_scope_in_variables")
“ .....
if exists("perl_extended_vars")
“ .....
if exists("perl_fold")
“ .....
you can enablethose features in
your .vimrc
let perl_fold = 1
let perl_extended_vars = 1
“ .... etc
135. for complex things like
@{${"foo"}}.
let perl_include_pod = 1
let perl_extended_vars = 1
let perl_want_scope_in_variables = 1
let perl_fold = 1
let perl_fold_blocks = 1
for something like
$pack::var1
149. *za*
za When on a closed fold: open it. When folds are nested, you
may have to use "za" several times. When a count is given,
that many closed folds are opened.
za When on an open fold: close it and set 'foldenable'. This
will only close one level, since using "za" again will open
zA
the fold. When a count is given that many folds will be
closed (that's not the same as repeating "za" that many
times).
*zA*
zA When on a closed fold: open it recursively.
zm When on an open fold: close it recursively and set
zM
zm Fold more: Subtract one from 'foldlevel'. If 'foldlevel' was
already zero nothing happens.
zr 'foldenable' will be set.
*zM*
zR zM Close all folds: set 'foldlevel' to 0.
'foldenable' will be set.
zj , zk
[z , ]z
173. Case:
use Data::Dumper;
we need to find Data/Dumper.pm in @INC
then type something like
$ vim /opt/local/..../site_perl/Data/Dumper.pm
174. fu! GetCursorModuleName()
let cw = substitute( expand("<cWORD>") , '.{-}((w+)(::w+
)*).*$' , '1' , '' )
return cw
endfunction
fu! TranslateModuleName(n)
return substitute( a:n , '::' , '/' , 'g' ) . '.pm'
endf
fu! GetPerlLibPaths()
let out = system('perl -e ''print join "n",@INC''')
let paths = split( out , "n" )
return paths
endf
175. fu! FindModuleFileInPaths()
let paths = GetPerlLibPaths()
let fname = TranslateModuleName( GetCursorModuleName() )
let methodname = GetMethodName()
if TabGotoFile( 'lib/' . fname , methodname )
return
endif
for p in paths
let fullpath = p . '/' . fname
if TabGotoFile( fullpath , methodname )
break
endif
endfor
endfunction
nmap <leader>fm :call FindModuleFileInPaths()<CR>
type “fm” rather than type $ perldoc ‐m Module::Name
176. Install CPAN Module from <cWORD>
nmap <C-x><C-i> :call InstallCPANModule()<CR>
function! InstallCPANModule()
let l = getline('.')
let cw = substitute( expand('<cWORD>') , ";$" , "" , "g" )
let cw = substitute( cw , "['"]" , "" , "g" )
echo "Installing CPAN Module: " . cw . "n"
silent exec "!cpanp i " . cw . " >& /dev/null"
echo "Donen"
endfunction
177. Skeletons
au bufnewfile *.pl 0r ~/.vim/skeleton/template.pl
au bufnewfile *.pod 0r ~/.vim/skeleton/template.pod
au bufnewfile *.pm 0r ~/.vim/skeleton/template.pm
178. more than one skeleton for perl code
fu! ReadTemplate()
let sname = input( "template type:" )
exec '0r ~/.vim/skeleton/perl/' . sname .
'.pl'
endf
command! NewFromSkeleton :call ReadTemplate()
185. function! WhitePearl()
perl << EOF
VIM::Msg("pearls are nice for necklaces");
VIM::Msg("rubys for rings");
VIM::Msg("pythons for bags");
VIM::Msg("tcls????");
EOF
endfunction
218. $ vimana search xml
rrd.vim - Edit RRD data with Vim.
qt.vim - tiny tool for the uic used in Qt from
Trolltech
syntax-for-xul - Highlighting for XML User interface Language.
maven2.vim - Compiler plugin for maven2
.... skip