Nvim :help
頁面,由 原始碼 使用 tree-sitter-vimdoc 解析器產生。
{stmt}
執行 perl 語句 {stmt}
。當前的 package 是 "main"。一個簡單的檢查 :perl
命令是否運作:perl print "Hello":[範圍]perl << [trim] [
{endmarker}
] {script}
{endmarker}
執行 perl 腳本 {script}
。在 {script}
後面的 {endmarker}
前面不能有任何空白。function! MyVimMethod() perl << EOF sub my_vim_method { print "Hello World!\n"; } EOF endfunction要查看您擁有的 perl 版本
:perl print $^V
{cmd}
為 [範圍] 中的每一行執行 perl 命令 {cmd}
,其中 $_ 被設定為每一行的文字,不帶尾隨的 <EOL>
。除了 $_ 之外,還會將 $line 和 $linenr 分別設定為行內容和行號。設定 $_ 將會更改文字,但請注意,無法使用此命令新增或刪除行。[範圍] 的預設值為整個檔案:「1,$」。:perldo $_ = reverse($_); :perldo $_ = "".$linenr." => $line";可以使用
:perldo
與 :perl
結合來使用 perl 過濾一個範圍。例如:perl << EOF sub 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($_)
:perl @ARGV = ("foo", "bar"); :perlfile myscript.pl以下是一些範例 perl-examples
:perl print "Hello" :perl $current->line (uc ($current->line)) :perl my $str = $current->buffer->[42]; print "Set \$str to: $str"請注意,變更(例如「use」語句)會從一個命令持續到下一個命令。
print "Hello" # displays a message VIM::Msg("Hello") # displays a message VIM::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 lines模組函數
{arg}
) 設定 vim 選項。{arg}
可以是 ":set" 命令接受的任何參數。請注意,這表示參數中不允許有空格!請參閱 :set。{bn}
...]) 如果沒有參數,則在陣列上下文中傳回所有緩衝區的列表,或在純量上下文中傳回緩衝區的數量。對於緩衝區名稱或數字 {bn}
的列表,則會使用與 Vim 內部 bufname() 函數相同的規則,傳回符合 {bn}
的緩衝區列表。警告:當使用 :bwipe 時,該列表將會失效。{wn}
...]) 如果沒有參數,則在陣列上下文中傳回所有視窗的列表,或在純量上下文中傳回視窗的數量。對於視窗號碼 {wn}
的列表,則會傳回具有這些號碼的視窗列表。警告:當視窗關閉時,該列表將會失效。{expr}
) 評估 {expr}
並在列表上下文中傳回 (成功, 值),或在純量上下文中僅傳回值。success=1 表示 val 包含 {expr}
的值;success=0 表示評估運算式失敗。'@x' 傳回暫存器 x 的內容,'&x' 傳回選項 x 的值,'x' 傳回內部 變數 x 的值,而 '$x' 等同於 perl 的 $ENV{x}。可以從命令列存取的所有 函數對於 {expr}
都是有效的。列表會透過串聯項目並插入換行符號轉換為字串。{lnum}
, {lnum}
) 刪除緩衝區中的 {lnum}
行。使用第二個 {lnum}
,刪除從第一個 {lnum}
到第二個 {lnum}
的行範圍。{lnum}
, {line}
, {line}
, ...) 將每個 {line}
字串附加在緩衝區的 {lnum}
行之後。{line}
的列表可以是陣列。{lnum}
, {line}
, {line}
, ...) 使用指定的 {lines}
取代一個或多個緩衝區行,從緩衝區的 {lnum}
行開始。{line}
的列表可以是陣列。如果參數無效,則不會發生取代。{row}
, {col}
) 如果沒有參數,則傳回視窗中目前游標位置的 (row, col) 陣列。使用 {row}
和 {col}
參數,將視窗的游標位置設定為 {row}
和 {col}
。請注意,{col}
從 0 開始編號,與 Perl 的方式相同,因此比 Vim 標尺中的值少 1。