All Projects → arnaud-lb → Vim Php Namespace

arnaud-lb / Vim Php Namespace

types "use" statements for you

Projects that are alternatives of or similar to Vim Php Namespace

Nsdepcop
NsDepCop is a static code analysis tool that helps to enforce namespace dependency rules in C# projects. No more unplanned or unnoticed dependencies in your system.
Stars: ✭ 114 (-55.12%)
Mutual labels:  namespace
NamingThings
Content on tips, tricks, advice, practices for naming things in in software/technology
Stars: ✭ 31 (-87.8%)
Mutual labels:  namespace
numerifides
A proposal for a system of decentralized trust, built on an open, public blockchain.
Stars: ✭ 14 (-94.49%)
Mutual labels:  namespace
Php Formatter
PHP Formatter is a PHP developer friendly set of tools
Stars: ✭ 163 (-35.83%)
Mutual labels:  namespace
kubeswitch
visually select kubernetes context/namespace from tree
Stars: ✭ 15 (-94.09%)
Mutual labels:  namespace
phaser-super-storage
A cross platform storage plugin for Phaser
Stars: ✭ 49 (-80.71%)
Mutual labels:  namespace
Rdflib
RDFLib is a Python library for working with RDF, a simple yet powerful language for representing information.
Stars: ✭ 1,584 (+523.62%)
Mutual labels:  namespace
sandbox-operator
A Kubernetes operator for creating isolated environments
Stars: ✭ 36 (-85.83%)
Mutual labels:  namespace
kube-watch
Simple tool to get webhooks on Kubernetes cluster events
Stars: ✭ 21 (-91.73%)
Mutual labels:  namespace
proposal-symbol-thenable
gus.host/proposal-symbol-thenable
Stars: ✭ 18 (-92.91%)
Mutual labels:  namespace
Imports In Python
🐍 📄 ✏️ Wrote a guide to help myself better understand how importing works in Python. The guide talks about Regular, Local, Optional, Circular, and Shadowed imports. The guide also covers how to import from Packages with or without the __init__.py file.
Stars: ✭ 181 (-28.74%)
Mutual labels:  namespace
phpcs-psr4-sniff
[READ-ONLY] PHP_CodeSniffer sniff that checks class name matches PSR-4 project structure.
Stars: ✭ 23 (-90.94%)
Mutual labels:  namespace
PackageProject.cmake
🏛️ Help other developers use your project. A CMake script for packaging C/C++ projects for simple project installation while employing best-practices for maximum compatibility.
Stars: ✭ 48 (-81.1%)
Mutual labels:  namespace
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+548.03%)
Mutual labels:  namespace
koko
Connect containers as point-to-point connection, using veth/vxlan/vlan/macvlan
Stars: ✭ 77 (-69.69%)
Mutual labels:  namespace
Rdf.sh
A multi-tool shell script for doing Semantic Web jobs on the command line.
Stars: ✭ 109 (-57.09%)
Mutual labels:  namespace
locize-cli
locize cli to import / export locales, add / edit / remove sync segments
Stars: ✭ 44 (-82.68%)
Mutual labels:  namespace
orjail
a more secure way to force programs to exclusively use tor network
Stars: ✭ 136 (-46.46%)
Mutual labels:  namespace
js-namespace-rails
js-namespace-rails let you choose which javascript snippet can execute in rails assets pipeline
Stars: ✭ 57 (-77.56%)
Mutual labels:  namespace
lxroot
A lightweight, flexible, and safer alternative to chroot and/or Docker.
Stars: ✭ 69 (-72.83%)
Mutual labels:  namespace

Goal

vim-php-namespace is a vim plugin for inserting "use" statements automatically.

Features

Import classes or functions (add use statements)

Automatically adds the corresponding use statement for the name under the cursor.

To use this feature, add the following mappings in ~/.vimrc:

function! IPhpInsertUse()
    call PhpInsertUse()
    call feedkeys('a',  'n')
endfunction
autocmd FileType php inoremap <Leader>u <Esc>:call IPhpInsertUse()<CR>
autocmd FileType php noremap <Leader>u :call PhpInsertUse()<CR>

Then, hitting \u in normal or insert mode will import the class or function under the cursor.

<?php
new Response<-- cursor here or on the name; hit \u now to insert the use statement

Make class or function names fully qualified

Expands the name 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')
endfunction
autocmd FileType php inoremap <Leader>e <Esc>:call IPhpExpandClass()<CR>
autocmd FileType php noremap <Leader>e :call PhpExpandClass()<CR>

Then, hitting \e in normal or insert mode will expand the name to a fully qualified name.

<?php
$this->getMock('RouterInterface<-- cursor here or on the name; hit \e now to expand the class name'

Sort existing use statements alphabetically

If you do not know how to organize use statements, (or anything else, for that matter), the alphabetical order might be a sensible choice, because it makes finding what you are looking for easier, and reduces the risk for conflicts : if everyone adds new things at the same line, conflicts are guaranteed.

This vim plugin defines a PhpSortUse() you may use in your mappings:

autocmd FileType php inoremap <Leader>s <Esc>:call PhpSortUse()<CR>
autocmd FileType php noremap <Leader>s :call PhpSortUse()<CR>

On top of that, you may want to have the dependencies sorted every time you insert one. To enable this feature, use the dedicated global option:

let g:php_namespace_sort_after_insert = 1

Installation:

Using pathogen

git clone git://github.com/arnaud-lb/vim-php-namespace.git ~/.vim/bundle/vim-php-namespace

Using vim-plug

Add to vimrc:

Plug 'arnaud-lb/vim-php-namespace'

Run command in vim:

:PlugInstall

Using vundle

Add to vimrc:

Bundle 'arnaud-lb/vim-php-namespace'

Run command in vim:

:BundleInstall

Manual installation

Download and copy plugin/phpns.vim to ~/.vim/plugin/

Post installation

Generate a tag file

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 the ctags package:

ctags -R --PHP-kinds=cfi

Traits

[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/i

Note that using --regex-php= is 10x slower than using universal-ctags.

Automatically updating tags

The AutoTags 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 src

Do not forget to load both files in vim:

" ~/.vimrc
set tags+=tags,tags.vendors

Key mappings

See Features section for adding key mappings.

The <Leader> key usually is \.

Credits:

This was originally based on a similar script for java packages found at http://vim.wikia.com/wiki/Add_Java_import_statements_automatically (in comments).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].