Nvim :help
頁面,由 產生,來源為 此處,並使用 tree-sitter-vimdoc 解析器。
CTRL-F
(不會插入)「o」如果您在任何地方輸入 <CR>
或使用「o」命令(不在插入模式!)「O」如果您使用「O」命令(不在插入模式!)「e」如果您在行首的「else」輸入第二個「e」CTRL-F
是此功能的預設按鍵。如果您為此定義 CTRL-I
,請小心,因為 CTRL-I
是 <Tab>
的 ASCII 碼。* 當「*」放在按鍵之前時,Vim 會在插入按鍵之前重新縮排該行。如果 'cinkeys' 包含「*<Return>」,Vim 會在開啟新行之前重新縮排目前行。0 當零放在按鍵之前時(但出現在「!」或「*」之後),Vim 只會在按鍵是您在該行中輸入的第一個字元時,才會重新縮排該行。當在「=」之前使用時,Vim 只會在單字之前只有空白時,才會重新縮排該行。CTRL-F
。o 當您使用「o」命令或當 Vim 在目前行下方開啟新行時(例如,當您在插入模式下輸入 <Enter>
時),重新縮排一行。O 當您使用「O」命令時,重新縮排一行。e 當您輸入第二個「e」時,重新縮排以「else」開頭的行。: 當輸入「:」且該「:」位於標籤或 case 語句之後時,重新縮排一行。對於 C++ 中的「class::method」中的「:」,請勿重新縮排。若要重新縮排任何「:」,請使用「<:>」。=word 在輸入「word」的最後一個字元時重新縮排。「word」實際上可能是另一個單字的一部分。因此,當輸入「endif」或「endwhile」中的「d」時,「=end」會導致重新縮排。但當輸入「bend」時則不會。當完成產生以「word」開頭的單字時,也會重新縮排。「0=word」會在單字之前只有空白時重新縮排。=~word 與 =word 類似,但忽略大小寫。<Enter>
時縮排行,而只會在按下 <Tab>
時縮排行,我建議:set cinkeys=0{,0},:,0#,!<Tab>,!^F您可能也想關閉 'autoindent'。
<BS>
、<Tab>
或 <Space>
或使用 CTRL-T
或 CTRL-D
來變更縮排後重新縮排。if (cond) if (cond) if (cond) { { { foo; foo; foo; } } }
if (cond) { if (cond) { if (cond) { foo; foo; foo; } } } else else else { { { bar; bar; bar; } } }
if (cond) if (cond) if (cond) foo; foo; foo; else else else { { { bar; bar; bar; } } }
func() func() func() { { { int foo; int foo; int foo;
if (cond) if (cond) if (cond) { { { foo; foo; foo;
if (cond) if (cond) if (cond) { { { foo; foo; foo; } } }
func() func() func() { { { if (cond) if (cond) if (cond) { { { a = b; a = b; a = b; } } } } } }
func() func() func() { { { { { { stmt; stmt; stmt; LABEL: LABEL: LABEL: } } } } } }
switch (x) switch(x) { { case 1: case 1: a = b; a = b; default: default: } }
case 11: case 11: a = a + 1; a = a + 1; b = b + 1;
switch (a) { switch (a) { case 1: { case 1: { break; break; } }
switch (x) switch(x) { { case 1: case 1: a = b; a = b; break; break; default: default: a = 0; a = 0; break; break; } }
{ { public: public: a = b; a = b; private: private: } }
public: public: a = a + 1; a = a + 1; b = b + 1;
namespace { namespace { void function(); void function(); } } namespace my namespace my { { void function(); void function(); } }
extern "C" { extern "C" { void function(); void function(); } } extern "C" extern "C" { { void function(); void function(); } }
func(a, b) func(a, b) func(a, b) int a; int a; int a; char b; char b; char b;
int int int func() func() func()
class MyClass : class MyClass : public BaseClass public BaseClass {} {} MyClass::MyClass() : MyClass::MyClass() : BaseClass(3) BaseClass(3) {} {}
a = b + 9 * a = b + 9 * c; c;
/* /* text. text. */ */
/******** /******** text. text. ********/ ********/
a = b; a = b; /* comment */ /* comment */ c = d; c = d;
if (c1 && (c2 || if (c1 && (c2 || c3)) c3)) foo; foo; if (c1 && if (c1 && (c2 || c3)) (c2 || c3)) { {
if (c123456789 if (c123456789 && (c22345 && (c22345 || c3)) || c3))
c = c1 && c = c1 && ( ( c2 || c2 || c3 c3 ) && c4; ) && c4;
if ( c1 if ( c1 && ( c2 && ( c2 || c3)) || c3)) foo; foo;
a_long_line( a_long_line( argument, argument, argument); argument); a_short_line(argument, a_short_line(argument, argument); argument);
if (condition1 if (condition1 && condition2) && condition2) action(); action(); function(argument1 function(argument1 && argument2); && argument2);
c = c1 && ( c = c1 && ( c2 || c2 || c3 c3 ) && c4; ) && c4; if ( if ( c1 && c2 c1 && c2 ) ) foo; foo;
if (cond1 && if (cond1 && cond2 cond2 ) )
object.add(new ChangeListener() { public void stateChanged(ChangeEvent e) { do_something(); } });
var bar = { foo: { that: this, some: ok, }, "bar":{ a : 2, b: "123abc", x: 4, "y": 5 } }
cinoptions=>s,e0,n0,f0,{0,}0,^0,L-1,:s,=s,l0,b0,gs,hs,N0,E0,ps,ts,is,+s, c3,C0,/0,(2s,us,U0,w0,W0,k0,m0,j0,J0,)20,*70,#0,P0如果出現以下情況,Vim 會將行放在第 1 欄:
searchpairpos()
的最大掃描距離。當處理非常長的表單時,較大的值會犧牲效能來換取正確性。值為 0 將掃描而不受限制。預設值為 300。(defn bad [] "Incorrect indentation") (defn good [] "Correct indentation")
" Default let g:clojure_fuzzy_indent = 1 let g:clojure_fuzzy_indent_patterns = ['^with', '^def', '^let'] let g:clojure_fuzzy_indent_blacklist = \ ['-fn$', '\v^with-%(meta|out-str|loading-context)$']
"^foo"
的模式將與所有這些候選項比對:foobar
、my.ns/foobar
和 #'foobar
。" Default let g:clojure_special_indent_words = \ 'deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
(def default "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.") (def aligned "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
(foo bar baz)
1
會變更此行為,使所有子表單都對齊到同一欄位,模擬 clojure-mode.el 的預設行為。(foo bar baz)
let fortran_do_enddo=1在這種情況下,do 迴圈將會被縮排。 如果你所有的迴圈都只有 do/enddo 類型,例如在 .f90 檔案中,那麼你應該使用自動指令設定緩衝區標誌,例如
au! BufRead,BufNewFile *.f90 let b:fortran_do_enddo=1以在 .f90 檔案中縮排 do 迴圈,並在其他副檔名(如 .for)的 Fortran 檔案中保持不變。
let fortran_indent_less=1可以透過設定對應的緩衝區局部變數來實現更精細的控制,如下所示
let b:fortran_indent_less=1
<script>
和 <style>
「區塊標籤」後第一行的縮排(預設為「zero」):let g:html_indent_script1 = "inc" :let g:html_indent_style1 = "inc"
:let g:html_indent_attribute = 1
:let g:html_indent_inctags = "html,body,head,tbody"你也可以使用以下方式移除這些標籤
:let g:html_indent_autotags = "th,td,tr,tfoot,thead"兩個變數的預設值都為空。注意:初始的「inctags」只在每個 Vim 會話中定義一次。
:call HtmlIndent_CheckUserSettings()詳細資訊:計算具有「alien」內容的「區塊標籤」內的縮排
<script>
:{可自訂}
如果是區塊的第一行:cindent(v:lnum) 如果屬性為空或包含 "java":-1 否則(vbscript,tcl,...)<style>
:{可自訂}
如果是區塊的第一行:GetCSSIndent() 否則 <!-- -->:-1:let g:MATLAB_function_indent = {0, 1 or 2 (default)}其中 0 代表「傳統」,1 代表「縮排巢狀函數」,2 代表「縮排所有函數」。
:%s /\r$//g或者,你可以簡單地 :let 變數 PHP_removeCRwhenUnix 為 1,並且腳本將在 Vim 載入 PHP 檔案時(在每個 BufRead 時)靜默地移除它們。
:let g:PHP_autoformatcomment = 0否則,'t' 將從 'formatoptions' 字串中移除,並新增 "qrowcb",有關更多資訊,請參閱 fo-table。
# Comment // Comment /* Comment */
:let g:PHP_default_indenting = N例如,當 N = 1 時,這將產生
<?php if (!isset($History_lst_sel)) if (!isset($History_lst_sel)) if (!isset($History_lst_sel)) { $History_lst_sel=0; } else $foo="bar"; $command_hist = TRUE; ?>(注意 PHP 容器標記和程式碼之間的額外縮排)
:let g:PHP_BracesAtCodeLevel = 1這將產生以下結果
if ($foo) { foo(); }而不是
if ($foo) { foo(); }注意:如果使用此選項,縮排速度會稍慢,因為某些最佳化將無法使用。
:let g:PHP_vintage_case_default_indent = 1在 PHP 中,'case/default' 區塊內不需要大括號,因此 'case:' 和 'default:' 的縮排層級與 'switch()' 相同,以避免無意義的縮排。你可以使用以上選項來返回傳統的方式。
:let g:PHP_noArrowMatching = 1
$user_name_very_long->name() ->age() ->info();
let g:PHP_IndentFunctionCallParameters = 1函數呼叫引數將縮排 1 個額外的層級。對於雙空格縮排
function call_the_thing( $with_this, $and_that ) { $this->do_the_thing( $with_this, $and_that ); }
let g:PHP_IndentFunctionDeclarationParameters = 1
function call_the_thing( $with_this, $and_that ) { $this->do_the_thing( $with_this, $and_that ); }
g:python_indent
字典設定,該字典需要在新增項目之前建立let g:python_indent = {}給出的範例是預設值。請注意,字典值設定為運算式,以便你可以稍後變更 'shiftwidth' 的值,而無需更新這些值。
let g:python_indent.open_paren = 'shiftwidth() * 2'在巢狀括號後縮排
let g:python_indent.nested_paren = 'shiftwidth()'用於續行的縮排
let g:python_indent.continue = 'shiftwidth() * 2'預設情況下,多行建構中的右括號與上一行的第一個非空白字元對齊。如果你希望它與開始多行建構的行的第一個字元對齊,請重設此鍵
let g:python_indent.closed_paren_align_last_line = v:false此方法使用 searchpair() 來回溯尋找未關閉的括號。這有時會很慢,因此會在 150 毫秒後逾時。如果你發現縮排不正確,你可以設定更大的逾時時間(以毫秒為單位)
let g:python_indent.searchpair_timeout = 500如果回溯尋找未關閉的括號仍然太慢,尤其是在複製貼上操作期間,或者你不需要在多行括號內縮排,則可以完全停用此功能
let g:python_indent.disable_parentheses_indenting = 1為了向後相容性,也支援這些變數
g:pyindent_open_paren g:pyindent_nested_paren g:pyindent_continue g:pyindent_searchpair_timeout g:pyindent_disable_parentheses_indentingR ft-r-indent
let r_indent_align_args = 0
let r_indent_ess_comments = 1
let r_indent_comment_column = 30
let r_indent_ess_compatible = 1
### r_indent_ess_compatible = 1 ### r_indent_ess_compatible = 0 foo <- foo <- function(x) function(x) { { paste(x) paste(x) } }
'\(&\||\|+\|-\|\*\|/\|=\|\~\|%\|->\)\s*$'
的行之後縮排。如果你希望在符合不同模式的行之後縮排,則應在你的 vimrc 中設定 r_indent_op_pattern
的適當值。let b:verilog_indent_modules = 1然後模組區塊將會縮排。若要停止此行為,請移除變數
:unlet b:verilog_indent_modules若要僅為 Verilog 檔案設定變數。可以使用以下陳述式
au BufReadPost * if exists("b:current_syntax") au BufReadPost * if b:current_syntax == "verilog" au BufReadPost * let b:verilog_indent_modules = 1 au BufReadPost * endif au BufReadPost * endif此外,設定變數 b:verilog_indent_width 來變更縮排寬度(預設為 'shiftwidth')
let b:verilog_indent_width = 4 let b:verilog_indent_width = shiftwidth() * 2此外,你可以開啟除錯問題的詳細模式
let b:verilog_indent_verbose = 1請務必先執行 ":set cmdheight=2" 以允許顯示訊息。
ENTITY sync IS PORT ( clk : IN STD_LOGIC; reset_n : IN STD_LOGIC; data_input : IN STD_LOGIC; data_out : OUT STD_LOGIC ); END ENTITY sync;若要關閉此功能,請新增
let g:vhdl_indent_genportmap = 0到 vimrc 檔案,這會導致先前的對齊範例變更
ENTITY sync IS PORT ( clk : IN STD_LOGIC; reset_n : IN STD_LOGIC; data_input : IN STD_LOGIC; data_out : OUT STD_LOGIC ); END ENTITY sync;預設會執行右側指派 "<=" 陳述式的對齊。這會導致以下對齊範例
sig_out <= (bus_a(1) AND (sig_b OR sig_c)) OR (bus_a(0) AND sig_d);若要關閉此功能,請新增
let g:vhdl_indent_rhsassign = 0到 vimrc 檔案,這會導致先前的對齊範例變更
sig_out <= (bus_a(1) AND (sig_b OR sig_c)) OR (bus_a(0) AND sig_d);全行註解(以 "--" 開頭的行)會縮排以與前一行的註解對齊,前提是 "--" 後面跟著一個空白。
sig_a <= sig_b; -- start of a comment -- continuation of the comment -- more of the same comment在插入模式中,輸入 "-- "(注意空格 " ")後,按下
CTRL-F
會將當前行的 "-- " 與前一行的 "--" 對齊。sig_c <= sig_d; -- comment 0 -- comment 1 -- comment 2 --debug_code: --PROCESS(debug_in) --BEGIN -- FOR i IN 15 DOWNTO 0 LOOP -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i); -- END LOOP; --END PROCESS debug_code; -- comment 3 sig_e <= sig_f; -- comment 4 -- comment 5會產生
sig_c <= sig_d; -- comment 0 -- comment 1 -- comment 2 --debug_code: --PROCESS(debug_in) --BEGIN -- FOR i IN 15 DOWNTO 0 LOOP -- debug_out(8*i+7 DOWNTO 8*i) <= debug_in(15-i); -- END LOOP; --END PROCESS debug_code; -- comment 3 sig_e <= sig_f; -- comment 4 -- comment 5請注意,"--debug_code:" 不會與 "-- comment 2" 對齊,因為 "--debug_code:" 的 "--" 後面沒有空格。
:let g:vim_indent_cont = shiftwidth() * 3預設值為 shiftwidth 的三倍。
let g:yaml_indent_multiline_scalar = 1