2011-06-20 23 views
4

我有一個令人困惑的Vim問題。如果我開始編輯一個新文件,例如vim test.txt,然後輸入單詞「do」並按Enter鍵(仍處於插入模式),則下一行會自動縮進。在快速回答之前,請閱讀整篇文章。即使文件類型未設置,Vim爲什麼使用Bash縮進規則?

兩個問題:

  1. 爲什麼會出現這種情況?
  2. 如何調試啓動過程(讀取〜/ .vimrc和〜/ .vim /中的文件)?

的更多信息:

  • 這裏是我的.vimrc:http://dotfiles.org/~meonkeys/.vimrc
  • 「do」,「if」和「switch」都會導致縮進,但我仍然沒有弄清楚Vim使用縮進規則的語言。
  • 我在〜/ .vim /中有一堆東西。這裏是:http://adammonsen.com/tmp/dot_vim.tgz
  • 即使沒有設置filetype,我也無法在我的〜/ .vimrc或〜/ .vim /中找到任何應​​該打開某種縮進的東西!
  • 如果我用vim -u /dev/null test.txt啓動Vim,問題就會消失。
  • 是的,我知道autoindent設置。我不認爲這是問題,因爲使用空的vimrc「做」中鍵入後未行縮進後打開autoindent
+4

當你看到這種行爲,運行':scriptnames'。這會向您顯示已獲取的腳本列表。另外,你確定文件類型是未設置? :echo&ft找出答案。 –

回答

8
'smartindent' 'si'  boolean (default off) 
         local to buffer 
         {not in Vi} 
         {not available when compiled without the 
         |+smartindent| feature} 
     Do smart autoindenting when starting a new line. Works for C-like 
     programs, but can also be used for other languages. 'cindent' does 
     something like this, works better in most cases, but is more strict, 
     see |C-indenting|. When 'cindent' is on, setting 'si' has no effect. 
     'indentexpr' is a more advanced alternative. 
     Normally 'autoindent' should also be on when using 'smartindent'. 
     An indent is automatically inserted: 
     - After a line ending in '{'. 
     - After a line starting with a keyword from 'cinwords'. 
     - Before a line starting with '}' (only with the "O" command). 

cinwords默認如果,否則,同時,做,因爲,開關

+0

我的朋友,你搖滾。謝謝! –

相關問題