Introducing Composer.vim

by Noah Frederick |

Composer.vim provides Vim support for Composer PHP projects.

Features

  • A :Composer command wraps composer with smart completion of subcommands and flags. It even completes package names from remote package repositories such as packagist.org. Composer.vim doesn’t care what your current working directory is, rather it activates when the current buffer belongs to a Composer project, and Composer.vim has no trouble dealing with multiple Composer projects simultaneously.
  • Navigate to source files by invoking <Plug>(composer-find) with the cursor on a class, interface, or trait name. This feature takes advantage of Composer’s autoloader to take you to the right file. The fully-qualified class name will be resolved automatically from the context. No tags file is needed.
  • Insert a use statement for the class, interface, or trait under the cursor by invoking <Plug>(composer-use). Composer.vim can also keep your use statements sorted alphabetically, although this feature is currently experimental.
  • Optional Projectionist support: Invoke :Ecomposer to edit your project’s composer.json, :A to jump to composer.lock and back.
  • Optional Dispatch support: :Dispatch runs composer dump-autoload.

No mappings are provided by default. Here is a sample configuration for your vimrc:

autocmd User Composer nmap <buffer> <LocalLeader>f <Plug>(composer-find) |
                    \ nmap <buffer> <LocalLeader>u <Plug>(composer-use)

See :help composer for further details.

Installation and Requirements

Using vim-plug, for example:

Plug 'noahfrederick/vim-composer'

Optionally install Dispatch.vim and Projectionist.vim for projections and asynchronous command execution:

Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-projectionist'

Note: either Projectionist.vim or Vim version 7.4.1304 or later is required for JSON support.

Composer.vim on Codeberg

Credits and License

Thanks to Tim Pope for Bundler.vim on which Composer.vim is modeled.

Copyright © Noah Frederick. Distributed under the same terms as Vim itself. See :help license.