2014-11-04 30 views
0

當我嘗試使用vim打開文件進行編輯時,我收到以下消息並檢測到錯誤消息。使用Vim編輯器時檢測到錯誤消息

Jashs-MacBook-Pro:hello jashjacob$ vim hello.rb 

--- Auto-Commands --- 
filetypedetect BufRead 
*if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat | runtime! scripts.vim | endif 
*if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'^I|| getline(4) =~ '^#' || getline(5) =~ '^#') | setf conf | endif 
Error detected while processing /usr/share/vim/vimrc: 
line 18: 
E116: Invalid arguments for function line("'"") > 0 && line ("'"") <= line("$") | 
E15: Invalid expression: line("'"") > 0 && line ("'"") <= line("$") | 
Press ENTER or type command to continue 

我的vim編輯器文件被損壞/修改了嗎?如何解決處理/usr/share/vim/vimrc時檢測到的錯誤?

/usr/share/vim/vimrc配置文件包含以下

" Configuration file for vim 
set modelines=0   " CVE-2007-2438 

" Normally we use vim-extensions. If you want true vi-compatibility 
" remove change the following statements 
set nocompatible  " Use Vim defaults instead of 100% vi compatibility 
set backspace=2   " more powerful backspacing 
set ai     " auto indenting 
set history=100   " keep 100 lines of history 
set ruler    " show the cursor position 
syntax on    " syntax highlighting 
set hlsearch   " highlight the last searched term 
filetype plugin on  " use the file type plugins 

" When editing a file, always jump to the last cursor position 
autocmd BufReadPost * 
if ! exists("g:leave_my_cursor_position_alone") | 
if line("'"") > 0 && line ("'"") <= line("$") | 
exe "normal g'"" | 
endif | 
endif 

" Don't write backup file if vim is being called by "crontab -e" 
au BufWrite /private/tmp/crontab.* set nowritebackup 
" Don't write backup file if vim is being called by "chpass" 
au BufWrite /private/etc/pw.* set nowritebackup 
+0

什麼在您的vimrc?特別是,第18行是什麼,也許是前面的行呢? – 2014-11-04 03:59:21

+0

@JonKiparsky我已經添加了我的vimrc配置文件內容。在第18行 - 'if line(「'」「)> 0 && line(」'「」)<= line(「$」)|' – 2014-11-04 04:03:20

回答

1

您不支持在/ usr/share/vim /中執行任何操作。

你編輯過的文件不是你的,應該不會改變。這些是你可以做的文件和地方任何你想要的:

~/.vim/ <-- put your plugins and colorschemes in this directory 
~/.vimrc <-- add your options and mappings to this file 

至於你的問題:

  • 這些線不是由一個插件添加的,它們是由您或其他人加入誰可以訪問你的機器。

  • 他們拋出一個錯誤,因爲誰粘貼他們總覺得這是一個好主意,刪除續行反斜槓是在the "original"(或this "original",或者that one,或導致後舊鏈接的笨蛋一個404,或簡單的版本在$VIMRUNTIME/vimrc_example.vim)。

  • 千萬不要運行你在互聯網上找到的命令,除非你確定它不會造成麻煩。

1

我不是一個vim腳本大師,所以也許會有人能夠提供更多的修復,但我可以建議,如果你只是想VIM再次工作,您可以評論導致麻煩的功能。在每行前加一個雙引號("),你應該能夠繼續做下去。 像這樣:

" When editing a file, always jump to the last cursor position 
"autocmd BufReadPost * 
" if ! exists("g:leave_my_cursor_position_alone") | 
" if line("'"") > 0 && line ("'"") <= line("$") | 
" exe "normal g'"" | 
" endif | 
" endif 

如果你想保留這個功能,你可能要學習一點vim腳本。 :)

+0

這解決了我的問題。我認爲這些代碼在我安裝了一些vim插件的時候被添加了,並不完全知道什麼時候和什麼。 – 2014-11-04 04:15:00

+0

很高興我能幫到你。對於它的價值,它看起來像試圖記住會話之間的文件夾 - 但正如我所說,這不是我的領域,所以我不確定它的真實含義。 – 2014-11-04 04:31:30

0

我覺得這些錯誤消息也可能來自你錯過或誤放置在你的.vimrc「設置不兼容」的事實。這會導致你的Vim誤解了用來在腳本文件中繼續排隊的反斜槓。最好在你的.vimrc文件的開頭放置「set nocompatible」。

如果您在錯誤消息中看到「if!did_filetype()...」並將其與/usr/share/vim/vim{yourversion}/filetype.vim中的代碼進行比較,您可以判斷應該在「」和「if」之間爲「\」。

see this entry for more details