Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Perl Editor Voodoo

by vroom (Pope)
on Feb 19, 2002 at 14:55 UTC ( #146388=perlmeditation: print w/replies, xml ) Need Help??

I've been attempting to beef up my .vimrc. The goal is as always to simplify my life somewhat. I'm curious what types of shortcuts, macros, and other magic people have in their vimrc's. If you *gasp* use another editor perhaps you can contribute other editor-specific tips for other users out there too. Here are some of the things I've added so far:
iab _cb ############################################################<C +R> iab _cl # #<C +R> iab _ds <C-R>=strftime("%Y-%b-%d")<CR> iab _fn <C-R>=bufname("%")<CR> iab _lm <C-R>="Last Modified: " . strftime("%a %b %d %H:%M:%S %Y") <C +R> iab _href <a href="" alt=""></a> iab _img <img src=""> iab <TABLE> <TABLE></TABLE> iab <TR> <TR></TR> iab <TD> <TD></TD>

Replies are listed 'Best First'.
Re: Perl Editor Voodoo
by gmax (Abbot) on Feb 19, 2002 at 16:25 UTC
    You might find info in this snippet, this script and this more descriptive node useful.

    My personal contribution is:
    :map \# ^[I#!/usr/bin/perl -w^Muse strict;^M
    I have been using Vim with embedded Perl for a while.
    I don't think I am exploiting all the possibilities, but it is really helpful to have perl regular expressions at your disposal, so you don't have to think about the differences between the two RegEx dialects. Once you are used to Perl's syntax, capturing parentheses in Vim  \(.*\) look painfully unfamiliar.
    I often use Perl's sort to manipulate my lines of text.

    A nice feature is that you can test one or more lines of code, while you are writing them. Here is just one example:
    # line 10 of your code $a = sqrt(64);
    If you want to see the result of that assignment (provided that your internal CPU can't calculate it :) this command
    :10perldo s/$/$_/ee
    will append the result at the end of the line.
    I mapped this command, referring to the current line.
    :map _ee ^[:.,.perldo s/$/$_/ee^M
    I am sure that there is a lot more than these few tricks. Having Perl embedded in your editor can trigger your imagination!
     _  _ _  _  
    (_|| | |(_|><
Re: Perl Editor Voodoo
by toadi (Chaplain) on Feb 20, 2002 at 09:24 UTC
    I have so much in my vimrc that I sometimes forget what nice features I have :)
    " add mapping for insert-mode completion (looks up keyword in dictiona +ry) imap <C-F> <C-X><C-K> " list files in current directory. map ,ls :!ls<CR> "Inserting date and Updates iab YDATE <C-R>=strftime("%A %d %b %Y %H:%M")<CR> map ,L 1G/Last update:\s*/e+1<CR>CYDATE<ESC> map ,,L 1G/Last change:\s*/e+1<CR>CYDATE<ESC> "Resize windows map <S-e> :resize +2<CR> map <S-b> :resize -2<CR> " Jumping to function with tags "nmap <S-n> ?[^a-zA-z0-9_]<CR>lvt(<C-]> "nmap <S-p> :pop<CR> " deleting those fecking ^M map <C-n> :%s/^M//g^M map <F4> :!bash^M map <F4> :q!^M map <F5> :w^M " replace bunch of WS with one blank Ctrl-x nmap ^X dwi ^[ " Commenting a whole paragraph with # style comments " pcp = Perl Comment Paragraph map ,pcp vip:s%^%# %<CR> vmap ,pcp :s%^%# %<CR> " Removing the # comment of a commented paragraph " rpc = Remove Perl Comment map ,rpc vip:s%^# %%<CR> vmap ,rpc :s%^# %%<CR> " F2 close current window (commonly used with my F1/F3 functions) noremap <f2> <Esc>:close<CR><Esc> " perl -cw buffer, using a temp file, into a new window function! PerlCW() let l:tmpfile1 = tempname() let l:tmpfile2 = tempname() execute "normal:w!" . l:tmpfile1 . "\<CR>" execute "normal:! perl -cw ".l:tmpfile1." \> ".l:tmpfile2." 2\>\&1 + \<CR>" execute "normal:new\<CR>" execute "normal:edit " . l:tmpfile2 . "\<CR>" endfunction " perl buffer, using a temp file, into a new window function! PerlOutput() let l:tmpfile1 = tempname() let l:tmpfile2 = tempname() execute "normal:w!" . l:tmpfile1 . "\<CR>" execute "normal:! perl ".l:tmpfile1." \> ".l:tmpfile2." 2\>\&1 \<C +R>" execute "normal:new\<CR>" execute "normal:edit " . l:tmpfile2 . "\<CR>" endfunction " Settings for editing perl source (plus bind the above two functions) function! MyPerlSettings() if !did_filetype() set filetype=perl endif set textwidth=78 set expandtab set tabstop=2 set shiftwidth=2 set cindent set comments=:# set formatoptions=croql set keywordprg=man\ -S\ 3 noremap <f1> <Esc>:call PerlCW()<CR><Esc> noremap <f3> <Esc>:call PerlOutput()<CR><Esc> endfunction if has("eval") augroup SetEditOpts au! " Perl autocmds autocmd BufNewFile *.pl,*.cgi 0r ~/vim/skeletons +/ autocmd BufWrite *.pl,*.cgi !chmod +x % autocmd FileType perl :call MyPerlSettings() augroup END endif
    In the file you can put -w and strict

    My opinions may have changed,
    but not the fact that I am right

Re: Perl Editor Voodoo
by screamingeagle (Curate) on Feb 20, 2002 at 04:34 UTC
    one particular shortcut i use all the time is when i need to comment out certain lines (which are not contiguous)
    map @ I# ^[j
    This makes it possible to add the # sign at the beginning of the line,regardless of where the cursor is on the line) using the @ sign
    Since I need to write database-related code, these shortcuts also come in handy
    ab sd $sth = $dbh->prepare($sql); ab se $sth->execute ab sa $sth->fetchrow_hashref; ab ss $sth->finish;
Re: Perl Editor Voodoo
by lemming (Priest) on Feb 20, 2002 at 01:54 UTC

    On a somewhat related note:
    Has anyone else compiled vim with the perl interface enabled? Last night I decided I wanted to bring my vim up to date and applied all the patches up to 6.0.225. Since I was doing that, I thought I'd compile in the perl support. Haven't had much time to play with it yet, but it looks promising.

      And as a compiler-ignorant Win32 user... does anyone have a pre-compiled binary of Vim with Perl support, or can someone point me in the right direction? (using Perl 5.6.1)


enter invokes insert mode
by wrvhage (Sexton) on Feb 25, 2002 at 13:13 UTC
    The shortest and handiest line in my .vimrc is:
    map <return> i

    apart from that I like
    map <anykey> :!make<return> imap <anykey> <esc>:!make<return>i
    -- |

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://146388]
Approved by root
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2017-05-25 03:08 GMT
Find Nodes?
    Voting Booth?