Tux

...making Linux just a little more fun!

2-cent Tip: Editing Perl scripts in Vim

Ben Okopnik [ben at linuxgazette.net]


Sun, 3 Feb 2008 10:50:25 -0500

The longer I use Vim, the more ways I find to make my life easier. This tip comes courtesy of Andy Lester's entry in the "Mechanix" blog (https://perlbuzz.com/mechanix/2008/01/vim-tricks-for-perl.html), where he shows a nifty trick for looking up Perl documentation for both functions and modules. I used to have it set up for just the former, but my lookup method is a little fancier - I open a scratch buffer in another window so you can look at both the docs and your code at the same time. So, combining the two results in the following:

autocmd FileType perl nmap K "zyiw<c-W>n:set buftype=nofile<CR>:r!
    \perldoc -tf '<c-R>z' 2>/dev/null <bar><bar> perldoc '<c-R>z'<cr>gg

(Yes, the 'escape' slash does go on the second line.)

Now, whenever your cursor is on a perl function or a module name, simply hit 'shift-k' (the standard vi/vim "lookup" key), and you'll get the docs.

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * https://LinuxGazette.NET *


Top    Back


Thomas Adam [thomas at edulinux.homeunix.org]


Sun, 3 Feb 2008 16:06:20 +0000

On Sun, Feb 03, 2008 at 10:50:25AM -0500, Ben Okopnik wrote:

> ```
> autocmd FileType perl nmap K "zyiw<c-W>n:set buftype=nofile<CR>:r!
>     \perldoc -tf '<c-R>z' 2>/dev/null <bar><bar> perldoc '<c-R>z'<cr>gg
> '''

That's useful. Something I used to use at work (but don't now -- I do far too much console stuff) is the following:

https://lug.fh-swf.de/vim/vim-perl/screenshots-en.html

-- Thomas Adam

"It was the cruelest game I've ever played and it's played inside my head." -- "Hush The Warmth", Gorky's Zygotic Mynci.


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Sun, 3 Feb 2008 21:12:37 -0500

On Sun, Feb 03, 2008 at 04:06:20PM +0000, Thomas Adam wrote:

> On Sun, Feb 03, 2008 at 10:50:25AM -0500, Ben Okopnik wrote:
> > ```
> > autocmd FileType perl nmap K "zyiw<c-W>n:set buftype=nofile<CR>:r!
> >     \perldoc -tf '<c-R>z' 2>/dev/null <bar><bar> perldoc '<c-R>z'<cr>gg
> > '''
> 
> That's useful.  Something I used to use at work (but don't now -- I do far
> too much console stuff) is the following:
> 
> https://lug.fh-swf.de/vim/vim-perl/screenshots-en.html

My .vimrc covers most of that, actually; pretty amusing, considering that I just put it together as the specific needs came up. It's also rather pleasant to see that I've managed to do a bit better, in places, than a big complex project like that one - e.g., I use a single key to comment and uncomment code, whether it's a single line or a visually-selected block.

One thing I don't have, though, is all that automatic codeblock-generation stuff: AFAIC, anything of that sort is Broken As Designed (BAD), since Perl semantics are not nearly as rigid as the creator of 'perlsupport' seems to think. I'd be spending more time revising the generated bits than it would actually take to write it by hand.

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * https://LinuxGazette.NET *


Top    Back


Faber J. Fedor [faber at linuxnj.com]


Sun, 3 Feb 2008 23:03:23 -0500

On 03/02/08 21:12 -0500, Ben Okopnik wrote:

> My .vimrc covers most of that, actually; pretty amusing, considering
> that I just put it together as the specific needs came up. It's also
> rather pleasant to see that I've managed to do a bit better, in places,
> than a big complex project like that one - e.g., I use a single key to
> comment and uncomment code, whether it's a single line or a
> visually-selected block.

So? Don't keep us in suspense! Let's see your .vimrc.

-- 
 
Regards,
 
Faber Fedor
President
Linux New Jersey, Inc.
908-320-0357
800-706-0701
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.


Top    Back


Ben Okopnik [ben at linuxgazette.net]


Mon, 4 Feb 2008 00:27:16 -0500

On Sun, Feb 03, 2008 at 11:03:23PM -0500, Faber Fedor wrote:

> On 03/02/08 21:12 -0500, Ben Okopnik wrote:
> > My .vimrc covers most of that, actually; pretty amusing, considering
> > that I just put it together as the specific needs came up. It's also
> > rather pleasant to see that I've managed to do a bit better, in places,
> > than a big complex project like that one - e.g., I use a single key to
> > comment and uncomment code, whether it's a single line or a
> > visually-selected block.
> 
> So?  Don't keep us in suspense!  Let's see your .vimrc.

But I like keeping people in suspense, Faber. It often has pleasant results - like getting you to come down out of the rafters. :)

Since you have asked, though, here it is:

https://okopnik.com/temp/vimrc	# Temp location; will be available at
https://linuxgazette.net/148/misc/tag/vimrc	# after 148 comes out

Again, I've chopped out a lot of me-specific stuff - but I've also just spent a bit of time making sure everything is well-commented. Enjoy!

-- 
* Ben Okopnik * Editor-in-Chief, Linux Gazette * https://LinuxGazette.NET *


Top    Back