GithubHelp home page GithubHelp logo

davidszkiba / vim-phpfmt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from beanworks/vim-phpfmt

0.0 2.0 0.0 866 KB

PHP (phpcbf) auto format plugin for vim

Home Page: https://github.com/beanworks/vim-phpfmt

License: MIT License

Vim Script 100.00%

vim-phpfmt's Introduction

vim-phpfmt

PHP auto format plugin for vim. It works seamlessly with phpcbf, and automatically formats currently editing PHP file on save, or by manually running command :PhpFmt.

Install

Vim-phpfmt follows the standard runtime path structure, so we highly recommend to use a common and well known plugin manager to install vim-phpfmt. For Pathogen just clone the repo. For other plugin managers add the appropriate lines and execute the plugin's install command.

  • Pathogen: git clone https://github.com/beanworks/vim-phpfmt.git ~/.vim/bundle/vim-phpfmt
  • vim-plug: Plug 'beanworks/vim-phpfmt'
  • NeoBundle: NeoBundle 'beanworks/vim-phpfmt'
  • Vundle: Plugin 'beanworks/vim-phpfmt'

Settings

By default third_party/phpcbf.phar is used to format PHP code with PSR2 as the default standard. To change to a different standard type or file, add the following setting to your vimrc file:

" A standard type: PEAR, PHPCS, PSR1, PSR2, Squiz and Zend
let g:phpfmt_standard = 'PSR2'

" Or your own defined source of standard (absolute or relative path):
let g:phpfmt_standard = '/path/to/custom/standard.xml'

Vim-phpfmt will first writes buffer to a temp file in the temp folder configured, then runs phpcbf over the temp file, and then copies formatted content back to the editing view, and restores cursor position.

Auto format on save is enabled by default, to disable it:

let g:phpfmt_autosave = 0

For more precise control, you can specify paths to your own phpcbf executable, or another PHP formatter of your choice. You can also set up a different temp file storing folder for intermediate formatting buffer:

let g:phpfmt_command = '/path/to/phpcbf'
let g:phpfmt_tmp_dir = '/path/to/tmp/folder'

Usage

Once the settings are in place, invoke command :PhpFmt to call the formatter. If auto format is enabled by setting :w or :x will automatically triggers the formatter.

Working with Docker

If you are using docker for dev, and having phpcbf executable installed inside the container, along with your own standard source. You can still use vim-phpfmt.

Assume you have mounted source code folders as volumes to the container, you can then change the settings to:

" NOTE: all the paths below should be pointing to executable, standard file,
"       and tmp folder that are actually inside the container
let g:phpfmt_command = 'docker exec container_name /path/to/phpcbf'
let g:phpfmt_options = '--standard=/path/to/custom/standard.xml --encoding=utf-8'
let g:phpfmt_tmp_dir = '/path/to/tmp/folder'

vim-phpfmt's People

Contributors

leimd avatar waltzofpearls avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.