Editorconfig

Nvim 的 :help 頁面,是使用 tree-sitter-vimdoc 解析器,從 原始碼 產生 的。


EditorConfig 整合

Nvim 支援 EditorConfig。當一個檔案被開啟時,在執行完 ftpluginFileType 自動指令後,Nvim 會搜尋該檔案的所有父目錄,尋找 ".editorconfig" 檔案,解析它們,並套用任何符合開啟檔案的屬性。把它想像成整個(遞迴)目錄的 'modeline'。更多資訊請參考 https://editorconfig.org/
EditorConfig 預設是啟用的。要停用它,請在你的設定中加入
vim.g.editorconfig = false
(Vimscript: let g:editorconfig = v:false)。也可以透過將緩衝區本地變數 b:editorconfig 設定為 false 來停用每個緩衝區的 EditorConfig。
如果 b:editorconfig 不是 false,Nvim 會將套用的屬性儲存在其中。
可以透過在 "properties" 表格中加入新的條目來新增屬性。表格的鍵是屬性名稱,而值是一個回呼函式,該函式接受要修改的緩衝區編號、.editorconfig 檔案中屬性的值,以及(可選的)一個包含所有其他屬性及其值的表格(對於依賴其他屬性的屬性很有用)。該值始終是一個字串,必要時必須強制轉換。範例
require('editorconfig').properties.foo = function(bufnr, val, opts)
  if opts.charset and opts.charset ~= "utf-8" then
    error("foo can only be set when charset is utf-8", 0)
  end
  vim.b[bufnr].foo = val
end
預設支援以下屬性
charset editorconfig.charset
"utf-8""utf-8-bom""latin1""utf-16be""utf-16le" 其中之一。設定 'fileencoding''bomb' 選項。
end_of_line editorconfig.end_of_line
"lf""crlf""cr" 其中之一。這些分別對應於將 'fileformat' 設定為 "unix"、"dos" 或 "mac"。
indent_size editorconfig.indent_size
一個數字,表示單個縮排的大小。或者,使用值 "tab" 來使用 tab_width 屬性的值。設定 'shiftwidth''softtabstop' 選項。如果此值不是 "tab" 並且未設定 tab_width 屬性,'tabstop' 也會設定為此值。
indent_style editorconfig.indent_style
"tab""space" 其中之一。設定 'expandtab' 選項。
insert_final_newline editorconfig.insert_final_newline
"true""false",以確保檔案最後一個位元組總是帶有尾隨換行符。設定 'fixendofline''endofline' 選項。
max_line_length editorconfig.max_line_length
一個數字,表示單行的最大長度。設定 'textwidth' 選項。
root editorconfig.root
如果為 "true",則停止在父目錄中搜尋 .editorconfig 檔案。此屬性必須位於 .editorconfig 檔案的頂層(即它不能在 glob 區段內)。
spelling_language editorconfig.spelling_language
格式為 ss 或 ss-TT 的代碼,其中 ss 是 ISO 639 語言代碼,TT 是 ISO 3166 地區識別碼。設定 'spelllang' 選項。
tab_width editorconfig.tab_width
單個 tab 字元的顯示大小。設定 'tabstop' 選項。
trim_trailing_whitespace editorconfig.trim_trailing_whitespace
當為 "true" 時,在寫入緩衝區時會自動移除尾隨空白。
主要
指令索引
快速參考