May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Using VIM for Perl Scripts Writing and Debugging

Old News ;-) See Also Recommended Links Perl one-liners Vim Buffers and Text-buffer Execution .vimrc VIM Exrc file VIM Multiwindows Support
Piping Vim Buffer VIM visual blocks File managers in VIM Copying and Moving sections of text Vim Regular Expressions Vim Options and Set command Searching and replacing text in VI
Indenting Your Code in VIM Outliner VIM running external commands Searching and replacing text in VI Ctags code browsing framework Vim registers VIM Perl Support
Line Ranges Vim documentation: if_perl Tips VIM Reference Humor History Etc


Vim can be used for Perl editing. Vim is not as great as specialized IDS but still you can achieve quite a lot by careful customarization. It does provides multiwindows support, tags, and syntax highlighting coding for Perl, as well as ability to reconcile differences between two versions of the  script. The latter is done via vimdiff command. For example  “vim -d“ ( or vimdiff

Vim will show both files on the screen in vertical split window mode. When you will scroll in one window, Vim will automatically scroll another window for you. You can patch the individual differences using do and dp commands. do will get the patch from the neighbor window and apply it to the current buffer, while dp will apply the difference from the current buffer to the neighbor window. If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/diff.txt.

Another important thing to for Perl programmers to use in VIM are ctags. When using tags it is nice to have two windows split horizontally. Vim supports both vertical and horizontal window splitting. To split current window horizontally execute “:split” while in the normal mode. To split current window vertically, use “:vsplit” instead. If you don’t provide any filename as argument to split/vsplit then current filename is used. You further split resulting windows as much as you like. Use Ctrl-w w to cycle through the windows. “:close” will close the current windows. “:only” will close all windows except the current one.

NOTE: You can check Perl syntax of each save by adding the following line to your .vimrc:

au BufWritePost *.pl,*.pm !perl -cw %

But the main attraction is ability to use perl to perform operation of the editor buffer.

Reading output of the Perl (or other) script of program into VIM buffer

Most Vim users are already familiar with using the read command (r), which inserts text from a specified file after the current line in the current buffer:

:r textfile 

What is important is that you can read in the output any script of program. For example:

:r ! ll /home/user/directory

This redirect the output of that command into the buffer and it is inserted after the current line.  This feature is useful for example to read the output of the Web page that you're editing, using a text-mode browser:

:r ! w3m -dump

The -dump option tells w3m to simply spit out the Web page as plain text and exit.

It's also possible to execute multiple commands connected via pipes, for example

:r ! df -h | sort -r
:r ! ls -a | egrep -v '^_'

Effectively, we’re putting our shell command directly after the ! character, and when we execute this command, Vim is placed in a background process while the shell command is executed. Once the shell command is finished, the resulting output is placed into our buffer, directly beneath our current cursor position.

The read command might also be useful for creating a report about the incident the you are resolving by allowing you to add to your report fragments from logs and execution of necessary commands:

:r ! grep string /var/log/apache2/site-error.log

Vim also makes it easy to redirect the output of most standard Unix utilities into a file, and to pipe text from the file it's editing into standard Unix filters as well as Perl and AWK interpreters.

Piping all or part of the buffer via external filter

Even more useful feature of Vim is ability to pipe part of the buffer into script and then replace this part with the output of the script. That this feature can be used for example for beatifying your script or for commenting out sections of  your programs.  You can pipe all the buffer, or only your selection.

For example,  to pipe all the buffer you need to specify the filer (which can be written by you Perl script) after ! command:

:1,$ ! perltidy

will beautify your program using perltidy.  Beautifying your script is a classic example of using piping in vi. You can also create a macro using keystroke remapping. Instead of beautifier you can use any other filter. This way for example you can temporary remove all comments from the script as it simplifies understanding  and then reread the file with comments back into the buffer:

To do the same for selection you need to provide boundary of selection to the command. The easiest way to do this is to use visual mode:  v, V, or Ctrl-v commands to select the part of your script that you want to process. In this  case boundary of your selection are defined by two mark '< and '> which represent upper and lower boundary correspondingly. They will be put on the command like automatically as soon as you enter : .  For example:

'<,'>! perl -nle 'print "\#".$_'

(this operation is called "commenting out" and it can also be performed via a plugin, but it is a still a good illustration of using Perl filters with VIM).

You can return to original text is you pipe worked incorrectly

Vim will run pass your selection to the script as STDIN  and insert standard output in place of it. If you incorrectly overwrite your selection or the whole buffer you can restore it using undo command (u). As buffer is an "in-memory" mapping of the file, rereading file from the disk using r command also allows you to restore the original text.

Repeating previous pipe command

To repeat the previous pipe command, you need to type:

! object !

Three important VIM concepts: File, buffers, and windows

It is important to distinguish between file, buffer and window. Those are three key concepts of VIM editor:

The :ls command gives us a listing of all the buffers that have been loaded into memory (:ls). We can switch to the next buffer in the list by running the :bnext (can be abbreviated to bn) command or bprev (can be abbreviated to bp). The %  symbol in this list indicates which of the buffers is visible in the current window, while the #  symbol represents the alternate file. We can quickly toggle between the current and alternate files by pressing <C-^>. Press it once, and we’ll switch to a.txt; press it a second time, and we’ll get back to b.txt.

We can traverse the buffer list using four commands—:bp and :bn (or bprev and bnext)  to move backward and forward one at a time, and :bfirst  and :blast  to jump to the start or end of the list. It’s a good idea to map them to something easier to reach. Some users can benefit from more concile mapping taken from  Tim Pope’s unimpaired.vim plugin:

nnoremap <​silent​> [​b​ :​bprevious​​ 
nnoremap <​silent​> ]​b​ :​bnext​​ 
nnoremap <​silent​> [B :​bfirst​ 
nnoremap <​silent​> ]B :​blast​

NOTE: Vim already uses the [  and ]  keys as prefixes for a series of related commands (see [), so these mappings have a consistent feel to them. The unimpaired.vim plugin provides similar mappings for scrolling through the argument ([a  and ]a), quickfix ([q  and ]q), location ([l  and ]l), and tag lists ([t  and ]t). Check it out.)

The :ls  listing starts with the buffer serial number, which is assigned to each buffer automatically on creation. We can jump directly to a buffer by number, using the :bN  command Alternatively, we can use buffer names instead of numbers :b {bufname}. The {bufname} need only contain enough characters from the filepath to uniquely identify the buffer. If we enter a string that matches more than one of the items in the buffer list, we can use tab-completion

Vim creates a new buffer any time we open a file. If we want to delete a buffer, we can do so using the :bdelete command. This can take one of these forms:

:bdelete N1 N2 N3
:N,M bdelete

Note that deleting a buffer has no effect on its associated file; it simply removes the in-memory representation. If we wanted to delete buffers numbered 5 through 10 inclusive, you need to run the command :5,10bd. But if you wanted to keep buffers number 6, 7 and 8, then run :bd 5 9 10.

Buffer numbers are automatically assigned by Vim, and we have no means of changing them by hand. So if we want to delete one or more buffers, we first have to look them up to find out their numbers. Unless I have a good reason to delete a buffer, I usually don’t bother. As a result, the :ls  listing comes to represent all of the files that I have opened in the course of an editing session.

If we want to arrange buffers in a way that makes more sense for our workflow we can use split windows and tabs. VIM associates each file with a buffer and can have multiple buffers opened. Some people open as much as 300 buffers  in VIM.

Some additional useful command:

Opening files and replacing the  content of the buffer (e command)

Vim allows  to open files both from within Vim and from outside of Vim (by supplying the list of files as parameters). This can also be a single file or multiple files. If we specify multiple files you can use basic regular expression to define a group of files. If we wanted to open multiple files at once, we could manually specify them like so:

vim file1.txt file2.txt

Or if you want simultaneously split your window in  subwindows for each file and view all files on the screen at once use:

vim -o file1.txt file2.txt

Within vim you can open the file using the “edit” command (:e), followed by the path to the file. To open a file within Vim, you’ll have to run the following command (the path can either be absolute or relative to the current working directory):

:e /path/to/your/file.txt

You can always  reload the same file, wiping out you changes

:e! %

Edit command without argument will wipe out your changes and restore the state of the files before the last write to it.

Each loaded files is represented in VIM as a buffer. In other words a buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.

Saving the buffer into the file

It’s best for beginners to always be explicit and to use the word buffer, as it cements the idea of how Vim actually modifies buffers and not files.

Let’s look at a few different options for saving a file (which, as we should now know, really means we want to write our buffer back to the source file). The following command is known as the “write” command (we saw this in the last chapter when discussing how buffers work). It’s fairly straightforward, in that it does what you would expect from its name, and writes the buffer content back to the source file.


You can also choose to “save and close,” by running the following composite command (by that I simply mean that we have combined two commands, the “write” command, :w, and the “quit” command, :q):


Note:  If you prefer something a little more concise (well, one character less), you can use the alternative :x command, which differs only slightly, in that it will only write the buffer when a modification is actually detected.

For example, if we had a file with 10 lines of content and in which every line was modified in some way, we could choose to write only the changes on lines 5–9, by using the following command:


It’s important to realize that if you have one window displayed on the screen, but multiple buffers open, it might not be clear that you have other buffers open at the same time and if some of those hidden buffers have been modified or not. If you were to try and quit Vim while some buffers had unsaved modifications, Vim would complain by throwing an error at you. If this happens, there are a few options available to you.

  1. Quit Vim and ignore any modified buffers (e.g., your changes will be lost). To do this, you would run the “quit all” command, followed by an exclamation mark, :qa!.
  2. Write all modified buffers and then quit (this will still throw an error if some buffers are read-only or can’t be written for some other reason). To do this, you would run the “write and quit all” command, :wqa.
  3. Ask Vim to write all modified buffers but to let you know of any problems before attempting to quit. To do this, you would run the “write and quit all” command but precede it with the “confirm” command, :conf wqa.
  4. Write all modified buffers, and override even those buffers that are read-only. To do this, you would run the “write and quit all” command, followed by an exclamation mark, :wqa!.

Creating new buffers

VIM load each file into its own buffer and that's the most common way of creating buffers in VIM.  But you can create an empty buffer and then load file into it too. A fresh empty buffer is called a [No Name] buffer. Vim provides us with a few ways to create a new empty buffer. Let’s review each of them.

Switching Working Directories

Now that we have a bit of an understanding of what file name modifiers are in Vim, we can look at another way to take advantage of them. In this example, we’ll look at how we can change the working directory of our project while we’re already inside Vim.

Let’s quickly clarify what the problem is that we’re trying to solve. If we are inside the folder ~/Code/ProjectA/ and we open Vim (let’s also assume we have some files from ProjectA open as well at this point), then Vim’s working directory will be ProjectA. Meaning, if we decide that we need to find some content that we know is inside another project directory (e.g., ~/Code/ProjectB/), we won’t be able to do that without either restarting Vim from within the ProjectB folder, finding the file and then jumping back to ProjectA, or opening a new shell and running Vim from the ProjectB folder and finding the file we’re after. (A real-world example for me is that I need to find a snippet of code I know I’ve used in another project, and so I want to copy it over to this project.)

Ideally, we would like to temporarily change the working directory while still inside the ProjectA folder, so we could find the file in ProjectB and then change the working directory back again to ProjectA. Using a combination of file name modifiers and Vim’s built-in cd command, this is not only possible but allows us to implement in a much simpler way. First, take a look at the following command:

:cd ~/Code/ProjectB

Leonid Mamchenkov on using VIM with Perl

Here is an excellent article of Leonid Mamchenkov Vim for Perl developers (May.10, 2004). Although around 15 years ago it is still the best intro into VIM facilities for Perl users. Below is an abbreviated version with some updates:

Text wrapping

As you code, sometimes text flows further than the width of the editor window. Some people like long lines to be wrapped (in other words, continued on the other line), while others prefer them unwrapped. You can configure Vim to behave according to your liking by adding “set wrap” or “set nowrap” to your .vimrc configuration file.

Flexible tabs

Tabulation is one of the hottest topics in programmers discussions when it comes to style. A very nice explanation of what is the problem with tabulations and spaces can be read at I must say though, that I don’t agree with author’s position on the subject. The article does provide you with several options for vi/Vim configuration to control the behavior of the tabs. I will just add/repeat the ones I consider important.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/indent.txt.

Line numbering

While Vim always displays your current position in the status line, you might also want to see all lines numbered. To do that, you will need to add “set number” to your .vimrc.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_03.txt.

Syntax highlighting

The first thing any developer will notice in Vim is excellent syntax highlighting. All popular languages are supported. Syntax files for less popular are available from Vim web site. Perl is supported out of the box.

Vim identifies keywords, comments, variables, strings, in-line POD and other standard parts of the program and highlights them. Vim supports two color modes: one for terminals with dark background color and another one for terminals with light background color. You can control these modes by specifying command “set bg=dark” and “set bg=light” in your .vimrc.

If you still don’t like the appearance of the code, stay tuned until “Color schemes” discussion.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/syntax.txt.

Text completion

One of Vim’s features I cannot live without is text completion. When editing, press Ctrl-n / Ctrl-p to cycle through the current word completion suggestions. Vim generates suggest list based on the words in the current file. If you need key completion to make suggestions from other files, then Vim by default understand the ctags file. Simply run “ctags *.p?” to generate ctags for all Perl files and modules in the current directory (assuming you are using “.pl” extension for Perl scripts and “.pm” extension for Perl modules). This Vim’s feature not only saves a tonne of time on typing, but greatly decreases the error rate, especially with long variable and procedure names in the code.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_24.txt.

File Completion

While you are in the command mode, Vim can complete the names of files and directories in case you want to open or save a file. In order to complete a file or a directory name you should start typing it’s name on the command prompt and then press the completion key. You can change the completion key to be almost anything you want with “set wildchar=” line in your .vimrc file.

Window splitting

Sometimes I need to see two or more files simultaneously. While I can always start another Vim session in a separate terminal, it is not as comfortable at times as Vim’s window splitting feature.

Vim supports both vertical and horizontal window splitting. To split current window horizontally execute “:split” while in the normal mode. To split current window vertically, use “:vsplit” instead. If you don’t provide any filename as argument to split/vsplit then current filename is used. You further split resulting windows as much as you like. Use Ctrl-w w to cycle through the windows. “:close” will close the current windows. “:only” will close all windows except the current one.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_08.txt.

Diff mode

Vim provides excellent facilities for checking and editing differences between two or more files. Execute “vimdiff” (or “vim -d“) from the command line to see difference made to file in file

Vim will show both files in vertical split window mode. When you will scroll in one window, Vim will automatically scroll another window for you. You can patch the individual differences using do and dp commands. do will get the patch from the neighbor window and apply it to the current buffer, while dp will apply the difference from the current buffer to the neighbor window.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/diff.txt.

Text folding

Yet another popular feature found in popular editors and IDEs is text folding. I think that folding is easier shown then explained. Vim supports six folding methods: by indent, by expression, by syntax, by changes in the text, by marker, and manual folding. For the sake of the example, I will show how to configure folding by marker.

In order to tell Vim to use folding by marker add the following lines to your .vimrc:

" Folding configuration
set foldmethod=marker
" Edit and uncomment next line if you want non-default marker
"set foldmarker="{{{,}}}"

If you need more information on this topic, read files /usr/share/doc/vim-common-6.1/docs/usr_28.txt and /usr/share/doc/vim-common-6.1/docs/fold.txt.

vim file1.txt file2.txt
vim fil1.txt file2.txt
vim file1.txt file2.txt
txt file2.txt
vim file1.txt file2.txt
vim file1.txt file2.txt
vim file1.txt file2.txt
<.txt file2.txt

   the text and then quickly jump back to it. You can set several marks. You can set marks in several files and then quickly switch 
   between them. I find myself set mark on the place I am currently working at with mc (m is for “mark”,
   c I use for “current”) and then quickly returning to the same place with 'c.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/motion.txt.

Vertical Indent Display

For some people indenting text horizontally is not enough. They need some kind of vertical indentation to help them see corresponding parts of the code. While I am not one of those people, I’ve seen this feature around so often that I decided to add it codemonkey’s .vimrc.

All you need to do to have vertical indent display with pipe (”|”) character is to add the following two lines to your .vimrc.

" This is for vertical indenting
set list
set listchars=tab:|
" NOTE the space char after last backslash.

:set list” forces Vim to show hidden characters like tabulations, ends of lines, and ends of files. “:set listchars=tab:| ” asks Vim to show only tab characters and use a pipe (”|”) with a space (” “) to do so, instead of usual “^I” thing that Vim likes to show.

Color schemes

Robert (MetaCosm) downloaded all color schemes and put them into a single archive file which he uploaded back to Vim’s web site (

You will most likely notice that some color schemes do not change much colors in your console vim. That is because they are most probably designed for GUI version of Vim, called gvim.

Try executing “gvim +'colorscheme peachpuff'” to see how gvim looks with selected color scheme.

Now you can try all those color schemes one by one with “:colorscheme something” and choose the one you like best. When you are done choosing, add line “colorscheme something” to your .vimrc.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_06.txt.

Block commenting

It is an often need to comment or uncomment blocks of code during the development cycle. While there is a way to do it in Vim without any additional configuration, I try to make life as easy as possible and install the BlockComment plug-in by Chris Russell.

Let’s download BlockComment.vim from and copy it into .vim/plugin/ directory. This plug-in automatically provides us with two mappings: “.c” for commenting code and “.C” for uncommenting code back.

File and buffer browser

Vim supports editing of several files simultaneously. One can start Vim as “vim” and then use “:next” and “:previous” to navigate through open files (called “buffers”). It is also possible to open files for editing without quiting Vim every time. For that, one should use simple “:e” command, where is the name of needed file.

There are, as usual, better (more convenient) ways to work with files and buffers. Vim website lists few plug-ins which can handle only files, or only buffers, or both at the same time. One of those plug-ins is winmanager by Srinath Avadhanula. Let’s grab winmanager from

Vim’s winmanager plug-in can make use of bufexplorer plug-in by jeff lanzarotta availalbe from

Installation is as usual – saving, unziping, and dos2unixing. Since we don’t want to always have file/directory browser turned on, lets add a mapping line to our .vimrc to “:WMToggle” by F2.

" This is for winmanager
map <F2> :WMToggle<CR>

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_23.txt.

Tag explorer

If you ask me, I am almost happy. The last thing that I am missing is something that will ease up my code browsing. I need a fast way of switching between different parts of my code and hierarchical view of it. Once again I go fishing to Vim web site and get myself a nice looking taglist plug-in by Yegappan Lakshmanan from This one is not even an archive! You just need to copy it into your .vim/plug-in directory. Let’s map “:Tlist” command to F3 key.

" This is for taglist
map <F3> :Tlist<CR>

One annoying thing that I find about taglist is that it resizes the terminal window when possible. I prefer to switch this feature off by add modifying my .vimrc in the following way.

" This is for taglist
let Tlist_Inc_Winwidth = 0
map <F3> :Tlist<CR>

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/tagsrch.txt.

Perl syntax checking

..copy perl.vim (developed by Lukas Zapletal) into your .vim/compiler/ directory. Now we need to specify for which files we want Vim to use our new perl compiler scripts. This is easily done by adding the following lines to .vimrc.

" Use perl compiler for all *.pl and *.pm files.
autocmd BufNewFile,BufRead *.p? compiler perl

Now you can use “:make” to check your code for errors. If you do have problems in your code, then Vim will position the cursor on the line with the first problem. You can use “:cnext” and “:cprevious” to go through other error messages. “:clist” will show a list of all errors.

If you need more information on this topic, read file /usr/share/doc/vim-common-6.1/docs/usr_30.txt.

 You can also check perl syntax in VIM on each save

au BufWritePost *.pl,*.pm !perl -c %

With this macro every time you save a .pl or .pm file, it executes perl -c and shows you the output.

Perldoc integration

Yet another feature provided in most IDEs is on-line documentation. Vim helps developers even with that. By default, Vim comes with system manual support on all UNIX boxes. This comes very handy when you use system commands in your scripts and need to check command line parameters. Just position the cursor on the word that you are interested in and press K. Vim will execute “man word“, where “word” is the word under the cursor. This is helpful but not as much as we need it.

Let’s visit Vim site again and download Perldoc plug-in (developed by Colin Keith) from unzip and run all extracted files through dos2unix. It’s a good idea to add a F1 mapping to “:Perldoc” in your .vimrc.

" This is for perldoc.vim
autocmd BufNewFile,BufRead *.p? map <F1> :Perldoc<cword><CR>
autocmd BufNewFile,BufRead *.p? setf perl
autocmd BufNewFile,BufRead *.p? let g:perldoc_program='/usr/bin/perldoc'
autocmd BufNewFile,BufRead *.p? source /home/codemonkey/.vim/ftplugin/perl_doc.vim

If you are using a newer version then I do, then you skip the last line.

Now, whenever you hit F1 while in the perl file, “:Perldoc” will get executed for the word that you have under the cursor, your current window will split horizontally and you’ll see appropriate perldoc page.

After installation of this plug-in I have noticed that syntax highlighting in few of my programs broke. After a quick look, I understood that that happened because of my extensive usage of underscore (”_”) character in procedure names. I had to fix it by simply adding underscore (”_”) character to the list of keyword characters on line 14 in file .vim/ftplugin/perl_doc.vim.

" Adds / and . as used in requires.
" setlocal iskeyword=a-z,A-Z,48-57,:,/,.
" Adds / and . as used in requires. Also adds _ as used in procedure names.
setlocal iskeyword=a-z,A-Z,48-57,:,/,.,_

Top Visited
Past week
Past month


Old News ;-)

[Oct 21, 2018] What are your suggestions for an ideal Vim configuration for Perl development?

Aug 18, 2016 |
There are a lot of threads pertaining to how to configure Vim/GVim for Perl development on .

My purpose in posting this question is to try to create, as much as possible, an ideal configuration for Perl development using Vim/GVim. Please post your suggestions for .vimrc settings as well as useful plugins.

I will try to merge the recommendations into a set of .vimrc settings and to a list of recommended plugins, ftplugins and syntax files.

.vimrc settings
"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"
syntax plugins ftplugins CPAN modules Debugging tools

I just found out about VimDebug . I have not yet been able to install it on Windows, but looks promising from the description.

innaM, Oct 15, 2009 at 19:06

The .vimrc settings should be heavily commented. E.g., what does perl_include_pod do? – innaM Oct 15 '09 at 19:06

Sinan Ünür, Oct 15, 2009 at 20:02

@Manni: You are welcome. I have been using the same .vimrc for many years and a recent bunch of vim related questions got me curious. I was too lazy to wade through everything that was posted on PerlMonks (and see what was current etc.), so I figured we could put together something here. – Sinan Ünür Oct 15 '09 at 20:02

innaM, Oct 16, 2009 at 8:22

I think that that's a great idea. Sorry that my own contribution is that lame. – innaM Oct 16 '09 at 8:22

Telemachus, Jul 8, 2010 at 0:40

Rather than closepairs, I would recommend delimitMate or one of the various autoclose plugins. (There are about three named autoclose, I think.) The closepairs plugin can't handle a single apostrophe inside a string (i.e. print "This isn't so hard, is it?" ), but delimitMate and others can. Jul 8 '10 at 0:40

community wiki 2 revs, 2 users 74% ,Dec 21, 2009 at 20:57

From chromatic's blog (slightly adapted to be able to use the same mapping from all modes).
vmap, pt :!perltidy<CR> 
nmap, pt :%! perltidy<CR>

hit, pt in normal mode to clean up the whole file, or in visual mode to clean up the selection. You could also add:

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

But using commands from input mode is not recommended.

innaM, Oct 21, 2009 at 9:21

I seem to be missing something here: How can I type, ptv without vim running perltidy on the entire file? – innaM Oct 21 '09 at 9:21

innaM, Oct 21, 2009 at 9:23

Ovid's comment (#3) seems offer a much better solution. – innaM Oct 21 '09 at 9:23

innaM, Oct 21, 2009 at 13:22

Three hours later: turns out that the 'p' in that mapping is a really bad idea. It will bite you when vim's got something to paste. – innaM Oct 21 '09 at 13:22

Ether, Oct 21, 2009 at 15:23

@Manni: select a region first: with the mouse if using gvim, or with visual mode ( v and then use motion commands). – Ether Oct 21 '09 at 15:23

Ether, Oct 21, 2009 at 19:44

@Manni: I just gave it a try: if you type, pt, vim waits for you to type something else (e.g. <cr>) as a signal that the command is ended. Hitting, ptv will immediately format the region. So I would expect that vim recognizes that there is overlap between the mappings, and waits for disambiguation before proceeding. – Ether Oct 21 '09 at 19:44

community wiki hobbs, Oct 16, 2009 at 0:35

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

community wiki Fritz G. Mehner, Oct 17, 2009 at 7:44

Look also at perl-support.vim (a Perl IDE for Vim/gVim). Comes with suggestions for customizing Vim (.vimrc), gVim (.gvimrc), ctags, perltidy, and Devel:SmallProf beside many other things.

innaM, Oct 19, 2009 at 12:32

I hate that one. The comments feature alone deserves a thorough 'rm -rf', IMHO. – innaM Oct 19 '09 at 12:32

sundar, Mar 11, 2010 at 20:54

I hate the fact that \$ is changed automatically to a "my $" declaration (same with \@ and \%). Does the author never use references or what?! – sundar Mar 11 '10 at 20:54

chiggsy, Sep 14, 2010 at 13:48

I take pieces of that one. If it were a man, you'd say about him, "He was only good for transplants..." – chiggsy Sep 14 '10 at 13:48

community wiki Permanuno, Oct 20, 2009 at 16:55

Perl Best Practices has an appendix on Editor Configurations . vim is the first editor listed.

community wiki 2 revs, 2 users 67% ,May 10, 2014 at 21:08

Andy Lester and others maintain the official Perl, Perl 6 and Pod support files for Vim on Github:

Sinan Ünür, Jan 26, 2010 at 21:20

Note that that link is already listed in the body of the question (look under syntax ). – Sinan Ünür Jan 26 '10 at 21:20

community wiki 2 revs, 2 users 94% ,Dec 7, 2010 at 19:42

For tidying, I use the following; either \t to tidy the whole file, or I select a few lines in shift+V mode and then do \t
nnoremap <silent> \t :%!perltidy -q<Enter>
vnoremap <silent> \t :!perltidy -q<Enter>

Sometimes it's also useful to deparse code. As the above lines, either for the whole file or for a selection.

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

community wiki 3 revs, 3 users 36% ,Oct 16, 2009 at 14:25

" Allow :make to run 'perl -c' on the current buffer, jumping to 
" errors as appropriate
" My copy of vimparse:

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

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

set tags+=/path/to/tags

innaM, Oct 15, 2009 at 19:34

What is Is it better than ctags? – innaM Oct 15 '09 at 19:34

Sinan Ünür, Oct 15, 2009 at 19:46

I think is based on it. – Sinan Ünür Oct 15 '09 at 19:46

Sinan Ünür, Oct 15, 2009 at 20:00

Could you please explain if there are any advantages to using rather than taglist.vim w/ ctags ? – Sinan Ünür Oct 15 '09 at 20:00

innaM, Oct 16, 2009 at 14:24

And really works for you? Is that really the correct URL? – innaM Oct 16 '09 at 14:24

zigdon, Oct 16, 2009 at 18:51

@sinan it enables quickfix - all it does is reformat the output of perl -c so that vim parses it as compiler errors. The the usual quickfix commands work. – zigdon Oct 16 '09 at 18:51

community wiki
, Oct 19, 2009 at 8:57

Here's an interesting module I found on the weekend: App::EditorTools::Vim . Its most interesting feature seems to be its ability to rename lexical variables. Unfortunately, my tests revealed that it doesn't seem to be ready yet for any production use, but it sure seems worth to keep an eye on.

community wiki 3 revs, 2 users 79%, Oct 19, 2009 at 13:50

Here are a couple of my .vimrc settings. They may not be Perl specific, but I couldn't work without them:
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>

community wiki, J.J., Feb 17, 2010 at 21:35

I have 2.

The first one I know I picked up part of it from someone else, but I can't remember who. Sorry unknown person. Here's how I made "C^N" auto complete work with Perl. Here's my .vimrc commands.

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

Then I set up a cron to create the installed_modules.dat file. Mine is for my mandriva system. Adjust accordingly.

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

The second one allows me to use gf in Perl. Gf is a shortcut to other files. just place your cursor over the file and type gf and it will open that file.

" 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,'\\(.*\\)','\\','i')

community wiki
, Sep 23, 2010 at 9:41

I find the following abbreviations useful
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>

You can make them perl only with

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

mfontani, Dec 7, 2010 at 14:47

there's no my anywhere there; I take it you usually write CGIs with no use strict; ? (just curious if this is so) – mfontani Dec 7 '10 at 14:47

Sean McMillan, Jun 30, 2011 at 0:43

Oh wow, and without as well. It's like a 15 year flashback. – Sean McMillan Jun 30 '11 at 0:43

community wiki Benno, May 3, 2013 at 12:45

By far the most useful are
  1. Perl filetype pluging (ftplugin) - this colour-codes various code elements
  2. Creating a check-syntax-before-saving command "W" preventing you from saving bad code (you can override with the normal 'w').

Installing he plugins are a bit dicky as the version of vim (and linux) put the plugins in different places. Mine are in ~/.vim/after/

my .vimrc below.

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>!
filetype plugin on
augroup JumpCursorOnEdit
 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

Checking perl syntax in VIM on each save

au BufWritePost *.pl,*.pm !perl -c %

Every time you save a .pl or .pm file, it executes perl -c and shows you the output.


taglist.vim - Source code browser (supports C-C++, java, perl, python, tcl, sql, php, etc) vim online

taglist.vim : Source code browser (supports C/C++, java, perl, python, tcl, sql, php, etc)

Yegappan Lakshmanan

The "Tag List" plugin is a source code browser plugin for Vim and
provides an overview of the structure of source code files and allows
you to efficiently browse through source code files for different
programming languages. You can visit the taglist plugin home page for
more information:

You can subscribe to the taglist mailing list to post your questions
or suggestions for improvement or to report bugs. Visit the following
page for subscribing to the mailing list:

For more information about using this plugin, after installing the
taglist plugin, use the ":help taglist" command.install details

1. Download the file and unzip the files to the $HOME/.vim or the
$HOME/vimfiles or the $VIM/vimfiles directory. After this step, you should
have the following two files (the directory structure should be preserved):

plugin/taglist.vim - main taglist plugin file
doc/taglist.txt - documentation (help) file

Refer to the |add-plugin|, |add-global-plugin| and |runtimepath| Vim
help pages for more details about installing Vim plugins.
2. Change to the $HOME/.vim/doc or $HOME/vimfiles/doc or $VIM/vimfiles/doc
directory, start Vim and run the ":helptags ." command to process the
taglist help file. Without this step, you cannot jump to the taglist help
3. If the exuberant ctags utility is not present in your PATH, then set the
Tlist_Ctags_Cmd variable to point to the location of the exuberant ctags
utility (not to the directory) in the .vimrc file.
4. If you are running a terminal/console version of Vim and the terminal
doesn't support changing the window width then set the
'Tlist_Inc_Winwidth' variable to 0 in the .vimrc file.
5. Restart Vim.
6. You can now use the ":TlistToggle" command to open/close the taglist
window. You can use the ":help taglist" command to get more information
about using the taglist plugin.

Blog of Leonid Mamchenkov " Vim for Perl developers

This is my attempt to provide a clear and simple instructions on adopting Vim text editor for programming needs. I am using Perl as the programming language in the examples, but most of this document will apply equally for any other programming language.

Update: This post was translated into Portuguese by Alceu Rodrigues de Freitas Junior.

Tip #94 - Questions & Answers about using tags with Vim vim online

This document gives you a idea about the various facilities available in Vim for using a tags file to browse through program source files. You can read the Vim online help, which explains in detail the tags support, using :help tagsearch.txt. You can also use the help keywords mentioned in this document to read more about a particular command or option. To read more about a particular command or option use,

:help <helpkeyword>

in Vim.

1. How do I create a tags file?

You can create a tags file either using the ctags utility or using
a custom script or utility.

Help keyword(s): tag

2. Where can I download the tools to generate the tags file?

There are several utilities available to generate the tags file.
Depending on the programming language, you can use any one of them.

1. Exuberant ctags generates tags for the following programming
language files:

Assembler, AWK, ASP, BETA, Bourne/Korn/Zsh Shell, C, C++, COBOL,
Eiffel, Fortran, Java, Lisp, Make, Pascal, Perl, PHP, Python,
REXX, Ruby, S-Lang, Scheme, Tcl, and Vim.

You can download exuberant ctags from

2. On Unix, you can use the /usr/bin/ctags utility. This utility
is present in most of the Unix installations.

3. You can use jtags for generating tags file for java programs.
You can download jtags from:

4. You can use ptags for generating tags file for perl programs.
You can download ptags from:

5. You can download scripts from the following links for
generating tags file for verilog files:

6. You can download Hdrtag from the following linke:

This utility generates tags file for the following programming
languages: assembly, c/c++, header files, lex, yacc,LaTeX, vim,
and Maple V.

7. You can also use the following scripts which are part of the Vim
runtime files: - Create tags file for perl code
tcltags - Create tags file for TCL code - Create tags file for shell script

Help keyword(s): ctags

3. How do I generate a tags file using ctags?

You can generate a tags file for all the C files in the current
directory using the following command:

$ ctags *.c

You can generate tags file for all the files in the current
directory and all the sub-directories using (this applies only to
exuberant ctags):

$ ctags -R .

You can generate tags file for all the files listed in a text file
named flist using (this applies only to exuberant ctags)

$ ctags -L flist

4. How do I configure Vim to locate a tags file?

You can set the 'tags' option in Vim to specify a particular tags

set tags=/my/dir/tags

Help keyword(s): 'tags', tags-option

5. How do I configure Vim to use multiple tags files?

The 'tags' option can specify more than one tags file. The tag
filenames are separated using either comma or spaces.

set tags=/my/dir1/tags, /my/dir2/tags

6. How do I configure Vim to locate a tags file in a directory tree?

Note that the following will work only in Vim 6.0 and above. You
can set the 'tags' option to make Vim search for the tags file in a
directory tree. For example, if the 'tags' option is set like

set tags=tags;/

Vim will search for the file named 'tags', starting with the
current directory and then going to the parent directory and then
recursively to the directory one level above, till it either
locates the 'tags' file or reaches the root '/' directory.

Help keyword(s): file-searching

7. How do I jump to a tag?

There are several ways to jump to a tag location.
1. You can use the 'tag' ex command. For example,

:tag <tagname>

will jump to the tag named <tagname>.
2. You can position the cursor over a tag name and then press
3. You can visually select a text and then press Ctrl-] to
jump to the tag matching the selected text.
4. You can click on the tag name using the left mouse button,
while pressing the <Ctrl> key.
5. You can press the g key and then click on the tag name
using the left mouse button.
6. You can use the 'stag' ex command, to open the tag in a new
window. For example,

:stag func1

will open the func1 definition in a new window.
7. You can position the cursor over a tag name and then press
Ctrl-W ]. This will open the tag location in a new window.

Help keyword(s): :tag, Ctrl-], v_CTRL_], <C-LeftMouse>,
g<LeftMouse>, :stag, Ctrl-W_]

8. How do I come back from a tag jump?

There are several ways to come back to the old location from a tag
1. You can use the 'pop' ex command.
2. You can press Ctrl-t.
3. You can click the right mouse button, while pressing the
<Ctrl> key.
4. You can press the g key and then click the right mouse

Help keyword(s): :pop, Ctrl-T, <C-RightMouse>, g<RightMouse>

9. How do I jump again to a previously jumped tag location?

You can use the 'tag' ex command to jump to a previously jumped tag
location, which is stored in the tag stack.

Help keyword(s): tag

10. How do I list the contents of the tag stack?

Vim remembers the location from which you jumped to a tag in the
tag stack. You can list the current tag stack using the 'tags' ex

Help keyword(s): :tags, tagstack

11. How do I jump to a particular tag match, if there are multiple
matching tags?

In some situations, there can be more than one match for a tag.
For example, a C function or definition may be present in more
than one file in a source tree. There are several ways to jump to
a specific tag from a list of matching tags.

1. You can use the 'tselect' ex command to list all the tag
matches. For example,

:tselect func1

will list all the locations where func1 is defined. You can
then enter the number of a tag match to jump to that
2. You can position the cursor over the tag name and press g]
to get a list of matching tags.
3. You can visually select a text and press g] to get a list
of matching tags.
4. You can use the 'stselect' ex command. This will open the
selected tag from the tag list in a new window.
5. You can position the cursor over the tag name and press
Ctrl-W g] to do a :stselect.

Help keyword(s): tag-matchlist, :tselect, g], v_g

Top Visited
Past week
Past month

Recommended Links

Google matched content

Softpanorama Recommended

Top articles


Blog of Leonid Mamchenkov " Vim for Perl developers

Editing features for advanced users

Environments extended with embeded Perl: are they for real? explores Vim and Perl joint usage.



Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy


War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes


Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law


Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D

Copyright © 1996-2021 by Softpanorama Society. was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site


The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Created Jan 1, 1994; Last modified: March 12, 2019