簡體   English   中英

Vim Autocmd錯誤

[英]Vim autocmd error

加載Python文件時,我有此腳本來設置變量

au BufNewFile,BufRead *.py
    \ set tabstop=4
    \ set softtabstop=4
    \ set shiftwidth=4
    \ set textwidth=79
    \ set expandtab
    \ set autoindent
    \ set fileformat=unix

加載Python文件時,出現以下錯誤:

Error detected while processing BufRead Auto commands for "*.py":
E518: Unknown option: set

這應該工作:

au BufNewFile,BufRead *.test set tabstop=4 
      \softtabstop=4 
      \shiftwidth=4  
      \textwidth=790  
      \expandtab  
      \autoindent  
      \fileformat=unix

要么

au BufNewFile,BufRead *.test set tabstop=4|set softtabstop=4|set shiftwidth=4|set textwidth=79 |set expandtab|set autoindent|set fileformat=unix

要么

au BufNewFile,BufRead *.test set tabstop=4 softtabstop=4 shiftwidth=4  textwidth=79 expandtab autoindent fileformat=unix

你可以做的 而不是* .test,它對我有用。 (Astrix。Astrix)

示例:au BufNewFile,BufRead 設置tabstop = 4

以下是實現所需目標的兩種方法:

au BufNewFile,BufRead *.py
    \ set tabstop=4 |
    \ set softtabstop=4 |
    \ set shiftwidth=4 |
    \ set textwidth=79 |
    \ set expandtab |
    \ set autoindent |
    \ set fileformat=unix

要么

au BufNewFile,BufRead *.py
    \ set tabstop=4
    \ softtabstop=4
    \ shiftwidth=4
    \ textwidth=79
    \ expandtab
    \ autoindent
    \ fileformat=unix

說明

在自動命令中,您正在調用:set (:h:set)命令,該命令用於設置vim選項。 如果要設置多個選項,則可以使用多個用空格分隔的選項來調用:set ,或者對每個選項調用:set多次,並用|將每個:set命令分開| (:h:bar)。

提示

由於您的目標是專門為python文件定義某些選項,因此您應該使用:autocmd Filetype python ... ,或者最好創建一個ftplugin/python/custom.vim文件,您可以在其中使用:setlocal啟用這些設置使用命令:set來代替:set只為當前緩沖區設置它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM