我如何验证我的 .vimrc?

我如何验证我的 .vimrc?

我的 .vimrc 文件似乎可以正常工作,并且在正常运行期间不会产生任何可见的错误。我最近开始使用 Knife,发现我无法使用 Vim 作为编辑器来编辑 Chef 内容,因为某些原因导致它以错误代码退出。删除 .vimrc 文件后 Knife 就恢复正常了,所以我假设我的 .vimrc 中存在问题。

是否有任何命令或工具可以用来检查 .vimrc 本身是否有错误?

这是有问题的 vimrc:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle, required
Bundle 'gmarik/vundle'
Bundle 'scrooloose/syntastic'
Bundle 'scrooloose/nerdtree'
Bundle 'michalbachowski/vim-wombat256mod'
Bundle 'spf13/vim-autoclose'
Bundle 'leshill/vim-json'
Bundle 'pangloss/vim-javascript'
Bundle 'hail2u/vim-css3-syntax'
Bundle 'tpope/vim-markdown'
Bundle 'beyondwords/vim-twig'
Bundle 'spf13/PIV'
Bundle 'othree/html5-syntax.vim'
Bundle 'vim-scripts/HTML-AutoCloseTag'
Bundle 'vim-scripts/indenthtml.vim'
Bundle 'Lokaltog/powerline'
" Keep bundle commands between here and filetype plugin indent on.



filetype plugin indent on     " required

" Brief help
" :BundleList          - list configured bundles
" :BundleInstall(!)    - install (update) bundles
" :BundleSearch(!) foo - search (or refresh cache first) for foo
" :BundleClean(!)      - confirm (or auto-approve) removal of unused bundles
"
" see :h vundle for more details or wiki for FAQ
" NOTE: comments after Bundle commands are not allowed.

" NERDTree config
map <C-n> :NERDTreeToggle<CR>
autocmd vimenter * if !argc() | NERDTree | endif

" enable paste mode
nnoremap <F2> :set invpaste paste?<CR>
set pastetoggle=<F2>
set showmode

" Set PHP debugger port to 9001
let g:debuggerPort = 9001

set t_Co=256
colorscheme wombat256mod
:syntax enable

python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
set rtp+=/Users/shane/.vim/bundle/powerline/powerline/bindings/vim

set number              " Enables line numbers
set cindent             " autoindent
set tabstop=4           " set tab distance
set shiftwidth=4
set expandtab           " force tabs into spaces
set ruler

let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"

autocmd BufNewFile,BufRead Gemfile set filetype=ruby
autocmd BufNewFile,BufRead Vagrantfile set filetype=ruby

答案1

你不能。与大多数(所有?)解释型语言一样,唯一能做的就是检查语法有效性,但你写下的函数调用等是否有任何意义,只有在实际命中特定代码路径时才会显示出来。

你唯一能做的就是通过检查来缩小问题范围什么是 »坏代码« 以及它试图告诉您的内容。例如,您可以尝试通过注释所有您不能完全确定它们不会导致问题的内容来调试问题,尝试 Knife 是否能在此配置下工作,并反复启用之前注释掉的代码,直到再次出现错误。

答案2

你确定这是 vim 的退出代码,而不是你正在编辑的文件的状态吗?下面:help 'backupcopy'有一段关于使用 vim 编辑 crontab 文件的段落。你可以直接使用以下命令(但会丢失上下文)到达那里:help crontab

                 *crontab*
One situation where "no" and "auto" will cause problems: A program
that opens a file, invokes Vim to edit that file, and then tests if
the open file was changed (through the file descriptor) will check the
backup file instead of the newly created file.  "crontab -e" is an
example.

如果这可能是 Knife 的问题,请尝试将其添加:set bkc=yes到 vimrc 文件中。您可以省去很多测试时间,因为无论您在 vimrc 文件中注释多少,vim 都会'compatible'在找到 vimrc 文件后立即重置该选项,并将其设置'backupcopy'为“自动”。我的 vimrc 文件中有以下内容:

" When vim is called from "crontab -e" we need to set this option specially:
au BufEnter /private/tmp/crontab.* setl backupcopy=yes

相关内容