-
-
Save ilkermutlu/59ae285edf8763bfa9af101335fad482 to your computer and use it in GitHub Desktop.
Vimscripts to easily create PHP class and easily add dependency to PHP classTweaked versions of a script by Jeffrey Way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Note: To add this to your .vimrc, you'll have to delete any character that is written with a caret (e.g. "^M") and enter the real value; to enter ^M, enter insert mode and type CTRL-V CTRL-M. | |
" Easily create class. | |
function! Class() | |
let name = input('Class Name? ') | |
let namespace = input('Any Namespace? ') | |
if strlen(namespace) | |
exec 'normal i<?php namespace ' . namespace . ';^M^M^[' | |
else | |
exec 'normal i<?php^M^M^[' | |
endif | |
" Open class | |
exec 'normal iclass ' . name . ' {^M}^[O^[' | |
exec 'normal i^M public function __construct()^M {^M ^M }^M^[kkA' | |
endfunction | |
nmap <leader>1 :call Class()<cr> | |
function! AddDependency() | |
let dependency = input('Var Name: ') | |
let namespace = input('Class Path: ') | |
let segments = split(namespace, '\') | |
let typehint = segments[-1] | |
exec 'normal gg/construct^M%i, ' . typehint . ' $' . dependency . '^[/}^MO$this->^[a' . dependency . ' = $' . dependency . ';^[==o^[?{^MkO protected $' . dependency . ';^M^[?{^MOuse ' . namespace . ';^M^[' | |
" Remove opening comma if there is only one dependency | |
exec 'normal :%s/(, /(/ge^M' | |
endfunction | |
nmap <leader>2 :call AddDependency()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment