2014-11-04 167 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