ta-tikoma/php.easy.nvim

github github
programming-languages-supportphp
stars 10
issues 0
subscribers 1
forks 1
CREATED

2023-04-08

UPDATED

3 months ago


Php Easy NVim

A few functions for make work with PHP 7.4 (or more) projects easy and quickly.

Install

With lazy.nvim:

    {
        'ta-tikoma/php.easy.nvim',
        config = true,
        keys = {
            {'-b', '<CMD>PHPEasyDocBlock<CR>'},
            {'-r', '<CMD>PHPEasyReplica<CR>'},
            {'-c', '<CMD>PHPEasyCopy<CR>'},
            {'-d', '<CMD>PHPEasyDelete<CR>'},
            {'-ii', '<CMD>PHPEasyInitInterface<CR>'},
            {'-ic', '<CMD>PHPEasyInitClass<CR>'},
            {'-iac', '<CMD>PHPEasyInitAbstractClass<CR>'},
            {'-it', '<CMD>PHPEasyInitTrait<CR>'},
            {'-ie', '<CMD>PHPEasyInitEnum<CR>'},
            {'-c', '<CMD>PHPEasyAppendConstant<CR>', mode = {'n', 'v'}},
            {'-p', '<CMD>PHPEasyAppendProperty<CR>', mode = {'n', 'v'}},
            {'-m', '<CMD>PHPEasyAppendMethod<CR>', mode = {'n', 'v'}},
            {'-_', '<CMD>PHPEasyAppendConstruct<CR>'},
            {'-a', '<CMD>PHPEasyAppendArgument<CR>'},
        }
    },

Features

Example Key Binding Function Description
Any function or property or constant
-y PHPEasyCopy Yank (copy) any under cursor
-r PHPEasyReplica Replica any: Copy under cursor, paste after current and trigger rename function
-d PHPEasyDelete Delete any under cursor
-b PHPEasyDocBlock PhpDocBlock for any or class or variable
Append
-c PHPEasyAppendConstant Append constant
-p PHPEasyAppendProperty Append property
-m PHPEasyAppendMethod Append method
-_ PHPEasyAppendConstruct Append __construct
-a PHPEasyAppendArgument Append new argument in current function
Objects
-ic PHPEasyInitClass Initialize class in current file
-iac PHPEasyInitAbstractClass Initialize abstract class in current file
-ii PHPEasyInitInterface Initialize interface in current file
-it PHPEasyInitTrait Initialize trait in current file
-ie PHPEasyInitEnum Initialize enum in current file

Configuration

{
    regex = { -- regex for parse php file
        tab = '    ',
        startTab = '^' .. tab,
        visibility = startTab .. '\\(public\\|protected\\|private\\|\\)\\s\\{1}',
        static = '\\(static\\s\\|\\)',
        constant = visibility .. 'const ',
        property = visibility .. static .. '\\(?*\\w\\+\\s\\|\\)\\$',
        method = visibility .. static .. 'function',
        construct = method .. ' __construct(',
        methodEnd = startTab .. '}',
        comment = startTab .. '\\/',
        commentMiddle = startTab .. '\\*',
        commentEnd = startTab .. '\\s\\*',
        any = startTab .. '[p}]\\{1}',
        variable = '\\(' .. tab .. '\\)\\+\\$\\w\\+\\s\\{1}=\\s\\{1}',
        object = '^\\(final class\\|abstract class\\|class\\|interface\\|trait\\|enum\\)\\s\\{1}',
    },
    onSave = { -- on save php file action
        removeUnusedUses = true -- remove unused uses (then use lsp: intelephense)
    },
    onAppend = { -- on append entity
        engine = 'defalut' -- how to insert template. 'default' - just string, 'LuaSinp' - via 'L3MON4D3/LuaSnip'
    }
}

Examples

Init

Init trait -it

init trait

Init interface -ii

init interface

Init abstract class -iac

init abstract class

Init class -ic

init class

Add doc block -b

Class

doc class

Constant

doc constant

Property

doc property

Method

doc method

Variable

doc variable