Skip to content

Instantly share code, notes, and snippets.

@xbot
Last active April 9, 2021 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xbot/8c4d0c8fadbe0bd78210c5a1bb971f06 to your computer and use it in GitHub Desktop.
Save xbot/8c4d0c8fadbe0bd78210c5a1bb971f06 to your computer and use it in GitHub Desktop.
vimrc that enables copying full class or method name in PHP files.
" Copy full class & method name in php files
" @see https://github.com/tyru/current-func-info.vim
au filetype php command! CopyFullClassName let @+=GetFullPHPClassName() | echo @+ . ' copied.'
au filetype php command! CopyFullMethodName let @+=GetFullPHPMethodName() | echo @+ . ' copied.'
function! GetFullPHPClassName()"{{{
" Save some registers
let l:r_a = @a
let l:r_b = @b
" Save cursor position
let l:pos = getcurpos()
" Start at the top of the file
:0
" Search for the first "namespace" occurence
/^namespace
" Get the namespace string into the regsiter a
normal! w"ayt;
" Search for the class definition
/\(^\(\(abstract\|final\)\s\+\|\)\)\@<=class
" Get the class string into the regsiter b
normal! knw"bye
let l:full_class_name = @a . '\' . @b
" Restore cursor position
call setpos('.', l:pos)
" Restore registers
let @a = l:r_a
let @b = l:r_b
return l:full_class_name
endfunction"}}}
" This function should be triggered when the cursor is on the method name
function! GetFullPHPMethodName()"{{{
let l:r_a = @a
normal! "ayiw
let l:full_class_name = GetFullPHPClassName()
let l:full_method_name = l:full_class_name . '::' . @a . '()'
let @a = l:r_a
return l:full_method_name
endfunction"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment