- Notifications
You must be signed in to change notification settings - Fork28
arnaud-lb/vim-php-namespace
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
vim-php-namespace is a vim plugin for inserting "use" statements automatically.
Imports the symbol under the cursor by adding the correspondinguse statement.
To use this feature, add the following mappings in~/.vimrc:
function! IPhpInsertUse() call PhpInsertUse() call feedkeys('a', 'n')endfunctionautocmd FileType php inoremap <Leader>u <Esc>:call IPhpInsertUse()<CR>autocmd FileType php noremap <Leader>u :call PhpInsertUse()<CR>Then, typing\u in normal or insert mode will import the symbol under the cursor.
<?phpnewResponse<--cursor hereor on the name; hit \u now to insert theusestatement
Expands the symbol under the cursor to its fully qualified name.
To use this feature, add the following mappings in~/.vimrc:
function! IPhpExpandClass() call PhpExpandClass() call feedkeys('a', 'n')endfunctionautocmd FileType php inoremap <Leader>e <Esc>:call IPhpExpandClass()<CR>autocmd FileType php noremap <Leader>e :call PhpExpandClass()<CR>Then, typing\e in normal or insert mode will expand the symbol to its fully qualified name.
<?php$this->getMock('RouterInterface<-- cursor here or on the name; type \e now to expand the class name'
To use this feature, add the following mappings in~/.vimrc:
autocmd FileType php inoremap <Leader>s <Esc>:call PhpSortUse()<CR>autocmd FileType php noremap <Leader>s :call PhpSortUse()<CR>Then, hitting\s in normal or insert mode will sort use statements.
It is also possible to sort statements automatically after a PhpInsertUse()by defining the following variable:
let g:php_namespace_sort_after_insert = 1Usingpathogen
git clone git://github.com/arnaud-lb/vim-php-namespace.git~/.vim/bundle/vim-php-namespaceUsingvim-plug
Add to vimrc:
Plug'arnaud-lb/vim-php-namespace'Run command in vim:
:PlugInstall
Usingvundle
Add to vimrc:
Bundle'arnaud-lb/vim-php-namespace'Run command in vim:
:BundleInstall
Download and copyplugin/phpns.vim to~/.vim/plugin/
The plugin makes use of tag files. If you don't already use a tag file you may create one with the following command; after having installed thectags package:
ctags -R --PHP-kinds=cfi[universal-ctags] supports traits natively (with--php-kinds=cfit).
If you can't use universal-ctags, the--regex-php argument allows to extract traits:
ctags -R --PHP-kinds=cfi --regex-php="/^[ \t]*trait[ \t]+([a-z0_9_]+)/\1/t,traits/i"You can also create a~/.ctags file with the following contents:
--regex-php=/^[ \t]*trait[ \t]+([a-z0_9_]+)/\1/t,traits/iNote that using--regex-php= is 10x slower than using universal-ctags.
The--regex-php argument can be used to extract enums:
ctags -R --PHP-kinds=cfi --regex-php="/^[ \t]*enum[ \t]+([a-z0_9_]+)/\1/e,enum/i"You can also create a~/.ctags file with the following contents:
--regex-php=/^[ \t]*enum[ \t]+([a-z0_9_]+)/\1/e,enum/iTheAutoTags plugin can update the tags file every time a file is created or modified under vim.
To keep updates fast, AutoTags won't operate if the tags file exceeds 7MB. To avoid exceeding this limit on projects with many dependencies, use a separate tags file for dependencies:
# dependencies tags file (index only the vendor directory, and save tags in ./tags.vendors)ctags -R --PHP-kinds=cfi -f tags.vendors vendor# project tags file (index only src, and save tags in ./tags; AutoTags will update this one)ctags -R --PHP-kinds=cfi srcDo not forget to load both files in vim:
" ~/.vimrcset tags+=tags,tags.vendorsSeeFeatures section for adding key mappings.
The<Leader> key usually is\.
- Arnaud Le Blanc
- Contributors
This was originally based on a similar script for java packages found athttp://vim.wikia.com/wiki/Add_Java_import_statements_automatically (in comments).
About
PHP namespace support for VIM. Types "use" statements for you
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Contributors13
Uh oh!
There was an error while loading.Please reload this page.