Nvim:help pages,generated fromsource using thetree-sitter-vimdoc parser.
{stmt}Execute perl statement{stmt}. The current package is"main". A simple check if the:perl command isworking::perl print "Hello":[range]perl << [trim] [
{endmarker}]{script}{endmarker}Execute perl script{script}.The{endmarker} after{script} must NOT be preceded byany white space.function! MyVimMethod()perl << EOFsub my_vim_method{ print "Hello World!\n";}EOFendfunctionTo see what version of perl you have::perl print $^V
{cmd}Execute perl command{cmd} for each line in the[range],with $_ being set to the test of each line in turn,without a trailing<EOL>. In addition to $_, $lineand $linenr is also set to the line content and linenumber respectively. Setting $_ will change the text,but note that it is not possible to add or deletelines using this command.The default for [range] is the whole file: "1,$".:perldo $_ = reverse($_);:perldo $_ = "".$linenr." => $line";One can use
:perldo in conjunction with:perl to filter a range usingperl. For example::perl << EOFsub perl_vim_string_replace{ my $line = shift; my $needle = $vim->eval('@a'); my $replacement = $vim->eval('@b'); $line =~ s/$needle/$replacement/g; return $line;}EOF:let @a='somevalue':let @b='newvalue':'<,'>perldo $_ = perl_vim_string_replace($_){file}Execute the perl script in{file}. The wholeargument is used as a single file name.:perl @ARGV = ("foo", "bar");:perlfile myscript.plHere are some examplesperl-examples:perl print "Hello":perl $current->line (uc ($current->line)):perl my $str = $current->buffer->[42]; print "Set \$str to: $str"Note that changes (such as the "use" statements) persist from one commandto the next.
print "Hello"# displays a messageVIM::Msg("Hello")# displays a messageVIM::SetOption("ai")# sets a vim option$nbuf = VIM::Buffers()# returns the number of buffers@buflist = VIM::Buffers()# returns array of all buffers$mybuf = (VIM::Buffers('a.c'))[0]# returns buffer object for 'a.c'@winlist = VIM::Windows()# returns array of all windows$nwin = VIM::Windows()# returns the number of windows($success, $v) = VIM::Eval('&path')# $v: option 'path', $success: 1($success, $v) = VIM::Eval('&xyz')# $v: '' and $success: 0$v = VIM::Eval('expand("<cfile>")')# expands <cfile>$curwin->SetHeight(10)# sets the window height@pos = $curwin->Cursor()# returns (row, col) array@pos = (10, 10)$curwin->Cursor(@pos)# sets cursor to @pos$curwin->Cursor(10,10)# sets cursor to row 10 col 10$mybuf = $curwin->Buffer()# returns the buffer object for window$curbuf->Name()# returns buffer name$curbuf->Number()# returns buffer number$curbuf->Count()# returns the number of lines$l = $curbuf->Get(10)# returns line 10@l = $curbuf->Get(1 .. 5)# returns lines 1 through 5$curbuf->Delete(10)# deletes line 10$curbuf->Delete(10, 20)# delete lines 10 through 20$curbuf->Append(10, "Line")# appends a line$curbuf->Append(10, "L1", "L2", "L3")# appends 3 lines@l = ("L1", "L2", "L3")$curbuf->Append(10, @l)# appends L1, L2 and L3$curbuf->Set(10, "Line")# replaces line 10$curbuf->Set(10, "Line1", "Line2")# replaces lines 10 and 11$curbuf->Set(10, @l)# replaces 3 linesModule Functions:{arg})Sets a vim option.{arg} can be any argument that the":set" command accepts. Note that this means that nospaces are allowed in the argument! See:set.{bn}...])With no arguments, returns a list of all the buffersin an array context or returns the number of buffersin a scalar context. For a list of buffer names ornumbers{bn}, returns a list of the buffers matching{bn}, using the same rules as Vim's internalbufname() function.WARNING: the list becomes invalid when:bwipe isused.{wn}...])With no arguments, returns a list of all the windowsin an array context or returns the number of windowsin a scalar context. For a list of window numbers{wn}, returns a list of the windows with thosenumbers.WARNING: the list becomes invalid when a window isclosed.{expr})Evaluates{expr} and returns (success, value) in listcontext or just value in scalar context.success=1 indicates that val contains the value of{expr}; success=0 indicates a failure to evaluatethe expression. '@x' returns the contents of registerx, '&x' returns the value of option x, 'x' returns thevalue of internalvariables x, and '$x' is equivalentto perl's $ENV{x}. Allfunctions accessible fromthe command-line are valid for{expr}.AList is turned into a string by joining the itemsand inserting line breaks.{lnum},{lnum}?, ...)Returns a text string of line{lnum} in the Bufferfor each{lnum} specified. An array can be passedwith a list of{lnum}'s specified.{lnum},{lnum}?)Deletes line{lnum} in the Buffer. With the second{lnum}, deletes the range of lines from the first{lnum} to the second{lnum}.{lnum},{line},{line}?, ...)Appends each{line} string after Buffer line{lnum}.The list of{line}s can be an array.{lnum},{line},{line}?, ...)Replaces one or more Buffer lines with specified{lines}s, starting at Buffer line{lnum}. The list of{line}s can be an array. If the arguments areinvalid, replacement does not occur.{height})Sets the Window height to{height}, within screenlimits.{row}?,{col}?)With no arguments, returns a (row, col) array for thecurrent cursor position in the Window. With{row} and{col} arguments, sets the Window's cursor position to{row} and{col}. Note that{col} is numbered from 0,Perl-fashion, and thus is one less than the value inVim's ruler.