Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I display results of phpcs in 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...

like image 885
Matt Avatar asked Feb 26 '11 23:02

Matt


1 Answers

Converting Matt's comment to an answer to get it from the unanswered questions list:


There were 2 problems.

  1. I did not have a cs name YML, I had to changed it to PHPCS,
  2. I did not know how to scroll through the list :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.

like image 143
cweiske Avatar answered Oct 12 '22 13:10

cweiske