Enable Perl before compiling Vim;
Use of Perl interface * perl-using *
*: perl * *: pe *
: pe [rl] {cmd} Execute Perl command {cmd}. The current package is "main".
: pe [rl] << {endpattern}
{script}
{endpattern}
Execute Perl script {script}.
{endpattern} cannot have any leading spaces. If {endpattern} is omitted,
You will reach a point '.' By default like the |: append | and |: insert | commands.
|: perl | This form of the command is mainly used to include the perl generation in the vim script
code.
Note: This command does not work when Perl is not compiled into vim. In order to avoid
To avoid errors, please refer to | script-here |.
vim script example:
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
*: perldo * *: perld *
: [range] perld [o] {cmd} Execute the Perl command {cmd} on each line in [range], and $ _ is assigned in turn
For each line of text, excluding <EOL> at the end of the line. Changing $ _ will change every line
Content, but you cannot add or delete lines with this command. [range]
The default is the entire file: "1, $".
You can try the following code:
: perl $ a = 1
: perldo $ _ = reverse ($ _); 1
: perl VIM :: Msg ("hello")
: perl $ line = $ curbuf-> Get (42)
* E299 *
The execution of Perl commands in | sandbox | is restricted. ": perldo" simply cannot be executed. ": Perl" if possible
Will be executed in a secure environment.
* perl-overview *
Here is a summary of the functions available under Perl:
: perl VIM :: Msg ("Text") # display information
: perl VIM :: Msg ("Error", "ErrorMsg") # display error information
: perl VIM :: Msg ("remark", "Comment") # Show highlighted information
: perl VIM :: SetOption ("ai") # Set a vim option
: perl $ nbuf = VIM :: Buffers () # returns the number of buffers
: perl @buflist = VIM :: Buffers () # returns an array of all buffers
: perl $ mybuf = (VIM :: Buffers ('qq.c')) [0] # Returns a buffer object of 'qq.c'
: perl @winlist = VIM :: Windows () # returns an array of all windows
: perl $ nwin = VIM :: Windows () # Returns the number of windows
: perl ($ success, $ v) = VIM :: Eval ('& path') # $ v: option 'path', $ success: 1
: perl ($ success, $ v) = VIM :: Eval ('& xyz') # $ v: '' and $ success: 0
: perl $ v = VIM :: Eval ('expand ("<cfile>")') # expand file <cfile>
: perl $ curwin-> SetHeight (10) # Set window height
: perl @pos = $ curwin-> Cursor () # return coordinates (row, col)
: perl @pos = (10, 10)
: perl $ curwin-> Cursor (@pos) # Set the cursor position to @pos
: perl $ curwin-> Cursor (10,10) # Set the cursor position to the 10th row and 10th column
: perl $ mybuf = $ curwin-> Buffer () # returns the buffer object of the window
: perl $ curbuf-> Name () # returns the buffer name
: perl $ curbuf-> Number () # returns the buffer number
: perl $ curbuf-> Count () # returns the number of rows
: perl $ l = $ curbuf-> Get (10) # returns line 10
: perl @l = $ curbuf-> Get (1 .. 5) # returns lines 1 to 5
: perl $ curbuf-> Delete (10) # delete line 10
: perl $ curbuf-> Delete (10, 20) # delete lines 10-20
: perl $ curbuf-> Append (10, "Line") # add a line after line 10
: perl $ curbuf-> Append (10, "Line1", "Line2", "Line3") # Add three lines after line 10
: perl @l = ("L1", "L2", "L3")
: perl $ curbuf-> Append (10, @l) # add L1, L2 and L3
: perl $ curbuf-> Set (10, "Line") # replace line 10
: perl $ curbuf-> Set (10, "Line1", "Line2") # Replace lines 10 and 11
: perl $ curbuf-> Set (10, @l) # Replace lines 10-12 with L1, L2, and L3 respectively
* perl-Msg *
VIM :: Msg ((msg), (group)?)
The message {msg} is displayed. The optional {group} parameter specifies the
Prominent way.
* perl-SetOption *
VIM :: SetOption ((arg))
Set a vim option. {arg} can be any parameter accepted by the ": set" command.
This means that no spaces are allowed in the parameters! See |: set |.
* perl-Buffers *
VIM :: Buffers ([{bn} ...]) Without parameters, returns a list of all buffers in the list context
Or the number of buffers in a scalar context. For a buffer name
List or quantity {bn}, returns a list of buffers matching {bn}
The number | bufname () | uses the same rules.
* perl-Windows *
VIM :: Windows ([{wn} ...]) returns no list of all windows in the list context or
Returns the number of windows in a scalar context. For a list of window names (wn),
Returns a list of windows matching {wn}.
* perl-DoCommand *
VIM :: DoCommand ((cmd)) executes the Ex command (cmd).
* perl-Eval *
VIM :: Eval ({expr}) evaluates {expr} and returns (success, val). success = 1 means val contains {expr}
Value. success = 0 means the expression failed to evaluate. ‘@X’ returns the contents of register x,
'& x' returns the value of option x, 'x' returns the value of internal variable x, '$ x' is equivalent to that in fish perl
$ ENV {x}. All functions accessible from the command line are valid for {expr}.
* perl-SetHeight *
Window-> SetHeight ((height))
Set the height of the window to {height} if the screen allows it.
* perl-GetCursor *
Window-> Cursor ({row} ?, {col}?)
Without parameters, returns the coordinates (row, col) of the position of the window cursor.
With the parameters {row} and {col}, set the position of the window cursor to {row}
And {col}. Note that {col} is Perl-style, counting from 0, which is better than Vim's scale.
little 1.
Window-> Buffer ()
* perl-Buffer *
Returns the buffer object for the given window.
* perl-Name *
Buffer-> Name () Returns the file name of the buffer.
* perl-Number *
Buffer-> Number () Returns the number of buffers.
* perl-Count *
Buffer-> Count () Returns the number of rows in the buffer.
* perl-Get *
Buffer-> Get ({lnum}, {lnum} ?, ...)
For each specified (lnum), returns the text character at line (lnum) in the buffer
string. An array can be passed by specifying a {lnum} list.
* perl-Delete *
Buffer-> Delete ({lnum}, {lnum}?)
Delete the {lnum} line of the buffer. When there is a second parameter {lnum}, delete
The range specified by the first {lnum} to the second {lnum}.
* perl-Append *
Buffer-> Append ({lnum}, {line}, {line} ?, ...)
Add each {line} string after the {lnum} line of the buffer. {line}
The list can be an array.
* perl-Set *
Buffer-> Set ({lnum}, {line}, {line} ?, ...)
The replacement buffer starts at line {lnum}, one or more lines specified by {lines}.
The {line} list can be an array. If the parameter is invalid, it is not replaced.
$ main :: curwin
The current window object.
$ main :: curbuf
The current buffer object.
* script-here *
When using an embedded scripting language, you may want to skip these if the language is not supported. But this mechanism does not work:
if has ('perl')
perl << EOF
this will NOT work!
EOF
endif
Instead, put commands such as Perl / Python / Ruby / in a function and call him:
if has ('perl')
function DefPerl ()
perl << EOF
this works
EOF
endfunction
call DefPerl ()
endif
Note: "EOF" must be at the beginning of the line (without leading spaces).
Above from http://man.chinaunix.net/newsoft/vi/doc/if_perl.html
Think about how to use these APIs to write your own Vim plug-in.