Leaderf-phpnamespace: Yet another PHP namespace resolver

发布于 — 2022 年 09 月 25 日
#Vim #LeaderF #plugin #编程 #计算机

This plugin uses the power of LeaderF to perform PHP namespace related tasks.

https://github.com/xbot/Leaderf-phpnamespace

Features

  • Insert use statements for FQCNs.
  • Sort use statements alphabetically.
  • Expand class names to FQCNs.
  • Insert namespace for the current file.
  • All the above features support the fuzzy searching function and all the three modes (nameonly, fullpath and regex) provided by LeaderF.

Requirements

  • LeaderF
  • ctags is properly configured in Vim/Neovim.

Install

Use any of your favourite plugin manager to install it, for example:

vim-plug

1
Plug 'xbot/Leaderf-phpnamespace'

Setup

1
2
3
4
5
" Import the current class under cursor.
noremap <leader>iu :<C-U><C-R>=printf("Leaderf phpns --input %s", expand("<cword>"))<CR><CR>

" Expand the classname under cursor to its FQCN form.
noremap <leader>ec :<C-U><C-R>=printf("Leaderf phpns --input %s --expand", expand("<cword>"))<CR><CR>

Commands

CommandDescription
LeaderfPhpnsChoose an FQCN to import.
PHPNamespaceInsertInsert namespace for the current file.

Press F1 in the popup window to get more help.

Options

OptionDefaultDescription
g:Lf_PHPNamespaceExpandToAbsolute1Expand the classname under cursor to absolute FQCN.
g:Lf_PHPNamespaceSortAfterImport1Sort the use statements block alphabetically after importing a class.