如何在VIM中显示phpcs的结果?
我目前正在尝试在 vim 中使用 PHP Codesniffer (PEAR) 来处理 PHP 文件。我发现有 2 个站点提供了要添加到 $HOME/.vim/plugin/phpcs.vim
文件中的代码。我已经添加了代码,并且我“认为”它正在工作,但我看不到结果,我只在 vim 的最底部看到一行,上面写着 (1 of 32)
但我看不到32 个错误中的任何一个。
这是我的 .vimrc 文件,
" Backup Options -> Some People may not want this... it generates extra files
set backup " Enable Backups
set backupext=.bak " Add .bak extention to modified files
set patchmode=.orig " Copy original file to with .orig extention Before saving.
" Set Tabs and spacing for PHP as recomended by PEAR and Zend
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
" Set Auto-indent options
set cindent
set smartindent
set autoindent
" Show lines that exceed 80 characters
match ErrorMsg '\%80v.\+'
" Set Colors
set background=dark
" Show a status bar
set ruler
set laststatus=2
" Set Search options highlight, and wrap search
set hls is
set wrapscan
" File Type detection
filetype on
filetype plugin on
" Enable Spell Checking
set spell
" Enable Code Folding
set foldenable
set foldmethod=syntax
" PHP Specific options
let php_sql_query=1 " Highlight sql in php strings
let php_htmlInStrings=1 " Highlight HTML in php strings
let php_noShortTags=1 " Disable PHP Short Tags
let php_folding=1 " Enable Ability to FOLD html Code
我尝试了 2 个不同版本的 phpcs.vim,并且两个版本都得到了相同的结果:
版本 1(位于:VIM 和 PHP IDE)
function! RunPhpcs()
let l:filename=@%
let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
" echo l:phpcs_output
let l:phpcs_list=split(l:phpcs_output, "\n")
unlet l:phpcs_list[0]
cexpr l:phpcs_list
cwindow
endfunction
set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
command! Phpcs execute RunPhpcs()
版本 2:(位于 VIM 中的集成 PHP Codesniffer )
function! RunPhpcs()
let l:filename=@%
let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
let l:phpcs_list=split(l:phpcs_output, "\n")
unlet l:phpcs_list[0]
cexpr l:phpcs_list
cwindow
endfunction
set errorformat+="%f"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,"%m"
command! Phpcs execute RunPhpcs()
这两个都会产生相同的结果。
phpcs 安装在我的系统上,我能够在 vim 之外生成结果。任何帮助将不胜感激,我只是在学习更多关于 vim 的知识......
I am presently trying to use PHP Codesniffer (PEAR) in vim for PHP Files. I have found 2 sites that give code to add into the $HOME/.vim/plugin/phpcs.vim
file. I have added the code and I "think" it is working, but I cannot see the results, I only see one line at the very bottom of vim that says (1 of 32)
but I cannot see any of the 32 errors.
Here is my .vimrc file
" Backup Options -> Some People may not want this... it generates extra files
set backup " Enable Backups
set backupext=.bak " Add .bak extention to modified files
set patchmode=.orig " Copy original file to with .orig extention Before saving.
" Set Tabs and spacing for PHP as recomended by PEAR and Zend
set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4
" Set Auto-indent options
set cindent
set smartindent
set autoindent
" Show lines that exceed 80 characters
match ErrorMsg '\%80v.\+'
" Set Colors
set background=dark
" Show a status bar
set ruler
set laststatus=2
" Set Search options highlight, and wrap search
set hls is
set wrapscan
" File Type detection
filetype on
filetype plugin on
" Enable Spell Checking
set spell
" Enable Code Folding
set foldenable
set foldmethod=syntax
" PHP Specific options
let php_sql_query=1 " Highlight sql in php strings
let php_htmlInStrings=1 " Highlight HTML in php strings
let php_noShortTags=1 " Disable PHP Short Tags
let php_folding=1 " Enable Ability to FOLD html Code
I have tried 2 different versions of phpcs.vim, and I get the same results for both:
Version 1 (found at: VIM an a PHP IDE)
function! RunPhpcs()
let l:filename=@%
let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
" echo l:phpcs_output
let l:phpcs_list=split(l:phpcs_output, "\n")
unlet l:phpcs_list[0]
cexpr l:phpcs_list
cwindow
endfunction
set errorformat+=\"%f\"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,\"%m\"
command! Phpcs execute RunPhpcs()
Version 2: (found at Integrated PHP Codesniffer in VIM )
function! RunPhpcs()
let l:filename=@%
let l:phpcs_output=system('phpcs --report=csv --standard=YMC '.l:filename)
let l:phpcs_list=split(l:phpcs_output, "\n")
unlet l:phpcs_list[0]
cexpr l:phpcs_list
cwindow
endfunction
set errorformat+="%f"\\,%l\\,%c\\,%t%*[a-zA-Z]\\,"%m"
command! Phpcs execute RunPhpcs()
Both of these produce identical results.
phpcs is installed on my system, and I am able to generate results outside of vim. Any help would be appreciated I am just learning more about vim...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 Matt 的评论转换为答案,以从未回答的问题列表中获取它:
有 2 个问题。
:cl
->列出屏幕上的所有错误;:cnext
->显示下一个错误。所以现在他们两个之间就可以了。感谢您的阅读,希望它能帮助别人。
Converting Matt's comment to an answer to get it from the unanswered questions list:
There were 2 problems.
:cl
-> lists all errors on the screen;:cnext
-> shows the next error.So between the two of them it now works. Thanks for any reads hope it helps someone out.