home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / unix / vim-6.2.tar.bz2 / vim-6.2.tar / vim62 / runtime / doc / if_perl.txt < prev    next >
Encoding:
Text File  |  2003-06-01  |  8.9 KB  |  257 lines

  1. *if_perl.txt*   For Vim version 6.2.  Last change: 2001 Oct 25
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Sven Verdoolaege
  5.                      and Matt Gerassimof
  6.  
  7. Perl and Vim                *perl* *Perl*
  8.  
  9. 1. Editing Perl files            |perl-editing|
  10. 2. Compiling VIM with Perl interface    |perl-compiling|
  11. 3. Using the Perl interface        |perl-using|
  12.  
  13. {Vi does not have any of these commands}
  14.  
  15. The Perl interface only works when Vim was compiled with the |+perl| feature.
  16.  
  17. ==============================================================================
  18. 1. Editing Perl files                    *perl-editing*
  19.  
  20. Vim syntax highlighting supports Perl and POD files.  Vim assumes a file is
  21. Perl code if the filename has a .pl or .pm suffix. Vim also examines the first
  22. line of a file, regardless of the filename suffix, to check if a file is a
  23. Perl script (see scripts.vim in Vim's syntax directory).  Vim assumes a file
  24. is POD text if the filename has a .POD suffix.
  25.  
  26. To use tags with Perl, you need a recent version of Exuberant ctags.  Look
  27. here:
  28.     http://ctags.sourceforge.net
  29.  
  30. Alternatively, you can use the Perl script pltags.pl, which is shipped with
  31. Vim in the $VIMRUNTIME/tools directory.  This script has currently more
  32. features than Exuberant ctags' Perl support.
  33.  
  34. ==============================================================================
  35. 2. Compiling VIM with Perl interface            *perl-compiling*
  36.  
  37. To compile Vim with Perl interface, you need Perl 5.004 (or later).  Perl must
  38. be installed before you compile Vim.  Vim's Perl interface does NOT work with
  39. the 5.003 version that has been officially released!  It will probably work
  40. with Perl 5.003_05 and later.
  41.  
  42. The Perl patches for Vim were made by:
  43.     Sven Verdoolaege <skimo@breughel.ufsia.ac.be>
  44.     Matt Gerassimof
  45.  
  46. Perl for MS-Windows can be found at:
  47. http://www.perl.com/CPAN-local/ports/nt/Standard/x86/
  48.  
  49. ==============================================================================
  50. 3. Using the Perl interface                *perl-using*
  51.  
  52.                             *:perl* *:pe*
  53. :pe[rl] {cmd}        Execute Perl command {cmd}. The current package
  54.             is "main".
  55.  
  56. :pe[rl] << {endpattern}
  57. {script}
  58. {endpattern}
  59.             Execute Perl script {script}.
  60.             {endpattern} must NOT be preceded by any white space.
  61.             If {endpattern} is omitted, it defaults to a dot '.'
  62.             like for the |:append| and |:insert| commands.  This
  63.             form of the |:perl| command is mainly useful for
  64.             including perl code in vim scripts.
  65.             Note: This command doesn't work when the Perl feature
  66.             wasn't compiled in.  To avoid errors, see
  67.             |script-here|.
  68.  
  69.  
  70. Example vim script: >
  71.  
  72.     function! WhitePearl()
  73.     perl << EOF
  74.         VIM::Msg("pearls are nice for necklaces");
  75.         VIM::Msg("rubys for rings");
  76.         VIM::Msg("pythons for bags");
  77.         VIM::Msg("tcls????");
  78.     EOF
  79.     endfunction
  80. <
  81.  
  82.                             *:perldo* *:perld*
  83. :[range]perld[o] {cmd}    Execute Perl command {cmd} for each line in the
  84.             [range], with $_ being set to the text of each line in
  85.             turn, without a trailing <EOL>. Setting $_ will change
  86.             the text, but note that it is not possible to add or
  87.             delete lines using this command.
  88.             The default for [range] is the whole file: "1,$".
  89.  
  90. Here are some things you can try: >
  91.  
  92.   :perl $a=1
  93.   :perldo $_ = reverse($_);1
  94.   :perl VIM::Msg("hello")
  95.   :perl $line = $curbuf->Get(42)
  96. <
  97.                             *E299*
  98. Executing Perl commands in the |sandbox| is limited.  ":perldo" will not be
  99. possible at all.  ":perl" will be evaluated in the Safe environment, if
  100. possible.
  101.  
  102.  
  103.                             *perl-overview*
  104. Here is an overview of the functions that are available to Perl: >
  105.  
  106.   :perl VIM::Msg("Text")        # displays a message
  107.   :perl VIM::Msg("Error", "ErrorMsg")    # displays an error message
  108.   :perl VIM::Msg("remark", "Comment")    # displays a highlighted message
  109.   :perl VIM::SetOption("ai")        # sets a vim option
  110.   :perl $nbuf = VIM::Buffers()        # returns the number of buffers
  111.   :perl @buflist = VIM::Buffers()    # returns array of all buffers
  112.   :perl $mybuf = (VIM::Buffers('qq.c'))[0] # returns buffer object for 'qq.c'
  113.   :perl @winlist = VIM::Windows()    # returns array of all windows
  114.   :perl $nwin = VIM::Windows()        # returns the number of windows
  115.   :perl ($success, $v) = VIM::Eval('&path') # $v: option 'path', $success: 1
  116.   :perl ($success, $v) = VIM::Eval('&xyz')  # $v: '' and $success: 0
  117.   :perl $v = VIM::Eval('expand("<cfile>")') # expands <cfile>
  118.   :perl $curwin->SetHeight(10)        # sets the window height
  119.   :perl @pos = $curwin->Cursor()    # returns (row, col) array
  120.   :perl @pos = (10, 10)
  121.   :perl $curwin->Cursor(@pos)        # sets cursor to @pos
  122.   :perl $curwin->Cursor(10,10)        # sets cursor to row 10 col 10
  123.   :perl $mybuf = $curwin->Buffer()    # returns the buffer object for window
  124.   :perl $curbuf->Name()            # returns buffer name
  125.   :perl $curbuf->Number()        # returns buffer number
  126.   :perl $curbuf->Count()        # returns the number of lines
  127.   :perl $l = $curbuf->Get(10)        # returns line 10
  128.   :perl @l = $curbuf->Get(1 .. 5)    # returns lines 1 through 5
  129.   :perl $curbuf->Delete(10)        # deletes line 10
  130.   :perl $curbuf->Delete(10, 20)        # delete lines 10 through 20
  131.   :perl $curbuf->Append(10, "Line")    # appends a line
  132.   :perl $curbuf->Append(10, "Line1", "Line2", "Line3") # appends 3 lines
  133.   :perl @l = ("L1", "L2", "L3")
  134.   :perl $curbuf->Append(10, @l)        # appends L1, L2 and L3
  135.   :perl $curbuf->Set(10, "Line")    # replaces line 10
  136.   :perl $curbuf->Set(10, "Line1", "Line2")    # replaces lines 10 and 11
  137.   :perl $curbuf->Set(10, @l)        # replaces 3 lines
  138. <
  139.                             *perl-Msg*
  140. VIM::Msg({msg}, {group}?)
  141.             Displays the message {msg}.  The optional {group}
  142.             argument specifies a highlight group for Vim to use
  143.             for the message.
  144.  
  145.                             *perl-SetOption*
  146. VIM::SetOption({arg})    Sets a vim option.  {arg} can be any argument that the
  147.             ":set" command accepts.  Note that this means that no
  148.             spaces are allowed in the argument!  See |:set|.
  149.  
  150.                             *perl-Buffers*
  151. VIM::Buffers([{bn}...])    With no arguments, returns a list of all the buffers
  152.             in an array context or returns the number of buffers
  153.             in a scalar context.  For a list of buffer names or
  154.             numbers {bn}, returns a list of the buffers matching
  155.             {bn}, using the same rules as Vim's internal
  156.             |bufname()| function.
  157.  
  158.                             *perl-Windows*
  159. VIM::Windows([{wn}...])    With no arguments, returns a list of all the windows
  160.             in an array context or returns the number of windows
  161.             in a scalar context.  For a list of window numbers
  162.             {wn}, returns a list of the windows with those
  163.             numbers.
  164.  
  165.                             *perl-DoCommand*
  166. VIM::DoCommand({cmd})    Executes Ex command {cmd}.
  167.  
  168.                             *perl-Eval*
  169. VIM::Eval({expr})    Evaluates {expr} and returns (success, val).
  170.             success=1 indicates that val contains the value of
  171.             {expr}; success=0 indicates a failure to evaluate
  172.             the expression.  '@x' returns the contents of register
  173.             x, '&x' returns the value of option x, 'x' returns the
  174.             value of internal |variables| x, and '$x' is equivalent
  175.             to perl's $ENV{x}.  All |functions| accessible from
  176.             the command-line are valid for {expr}.
  177.  
  178.                             *perl-SetHeight*
  179. Window->SetHeight({height})
  180.             Sets the Window height to {height}, within screen
  181.             limits.
  182.  
  183.                             *perl-GetCursor*
  184. Window->Cursor({row}?, {col}?)
  185.             With no arguments, returns a (row, col) array for the
  186.             current cursor position in the Window.  With {row} and
  187.             {col} arguments, sets the Window's cursor position to
  188.             {row} and {col}.  Note that {col} is numbered from 0,
  189.             Perl-fashion, and thus is one less than the value in
  190.             Vim's ruler.
  191.  
  192. Window->Buffer()                    *perl-Buffer*
  193.             Returns the Buffer object corresponding to the given
  194.             Window.
  195.  
  196.                             *perl-Name*
  197. Buffer->Name()        Returns the filename for the Buffer.
  198.  
  199.                             *perl-Number*
  200. Buffer->Number()    Returns the number of the Buffer.
  201.  
  202.                             *perl-Count*
  203. Buffer->Count()        Returns the number of lines in the Buffer.
  204.  
  205.                             *perl-Get*
  206. Buffer->Get({lnum}, {lnum}?, ...)
  207.             Returns a text string of line {lnum} in the Buffer
  208.             for each {lnum} specified. An array can be passed
  209.             with a list of {lnum}'s specified.
  210.  
  211.                             *perl-Delete*
  212. Buffer->Delete({lnum}, {lnum}?)
  213.             Deletes line {lnum} in the Buffer.  With the second
  214.             {lnum}, deletes the range of lines from the first
  215.             {lnum} to the second {lnum}.
  216.  
  217.                             *perl-Append*
  218. Buffer->Append({lnum}, {line}, {line}?, ...)
  219.             Appends each {line} string after Buffer line {lnum}.
  220.             The list of {line}s can be an array.
  221.  
  222.                             *perl-Set*
  223. Buffer->Set({lnum}, {line}, {line}?, ...)
  224.             Replaces one or more Buffer lines with specified
  225.             {lines}s, starting at Buffer line {lnum}.  The list of
  226.             {line}s can be an array.  If the arguments are
  227.             invalid, replacement does not occur.
  228.  
  229. $main::curwin
  230.             The current window object.
  231.  
  232. $main::curbuf
  233.             The current buffer object.
  234.  
  235.  
  236.                             *script-here*
  237. When using a script language in-line, you might want to skip this when the
  238. language isn't supported.  But this mechanism doesn't work: >
  239.    if has('perl')
  240.      perl << EOF
  241.        this will NOT work!
  242.    EOF
  243.    endif
  244. Instead, put the Perl/Python/Ruby/etc. command in a function and call that
  245. function: >
  246.     if has('perl')
  247.       function DefPerl()
  248.     perl << EOF
  249.       this works
  250.     EOF
  251.       endfunction
  252.       call DefPerl()
  253.     endif
  254. Note that "EOF" must be at the start of the line.
  255.  
  256.  vim:tw=78:ts=8:ft=help:norl:
  257.