Skip to content

Latest commit

 

History

History
145 lines (124 loc) · 6.13 KB

README.md

File metadata and controls

145 lines (124 loc) · 6.13 KB

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 = {
            {'-#', '<CMD>PHPEasyAttribute<CR>', ft = 'php'},
            {'-b', '<CMD>PHPEasyDocBlock<CR>', ft = 'php'},
            {'-r', '<CMD>PHPEasyReplica<CR>', ft = 'php'},
            {'-c', '<CMD>PHPEasyCopy<CR>', ft = 'php'},
            {'-d', '<CMD>PHPEasyDelete<CR>', ft = 'php'},
            {'-uu', '<CMD>PHPEasyRemoveUnusedUses<CR>', ft = 'php'},
            {'-e', '<CMD>PHPEasyExtends<CR>', ft = 'php'},
            {'-i', '<CMD>PHPEasyImplements<CR>', ft = 'php'},
            {'--i', '<CMD>PHPEasyInitInterface<CR>', ft = 'php'},
            {'--c', '<CMD>PHPEasyInitClass<CR>', ft = 'php'},
            {'--ac', '<CMD>PHPEasyInitAbstractClass<CR>', ft = 'php'},
            {'--t', '<CMD>PHPEasyInitTrait<CR>', ft = 'php'},
            {'--e', '<CMD>PHPEasyInitEnum<CR>', ft = 'php'},
            {'-c', '<CMD>PHPEasyAppendConstant<CR>', ft = 'php', mode = {'n', 'v'}},
            {'-p', '<CMD>PHPEasyAppendProperty<CR>', ft = 'php', mode = {'n', 'v'}},
            {'-m', '<CMD>PHPEasyAppendMethod<CR>', ft = 'php', mode = {'n', 'v'}},
            {'__', '<CMD>PHPEasyAppendConstruct<CR>', ft = 'php'},
            {'_i', '<CMD>PHPEasyAppendInvoke<CR>', ft = 'php'},
            {'-a', '<CMD>PHPEasyAppendArgument<CR>', ft = 'php'},
        }
    },

If you want to use better append engine

    {
        'ta-tikoma/php.easy.nvim',
        dependencies = {
            'L3MON4D3/LuaSnip',
        },
        opts = {
            onAppend = {
                engine = 'LuaSnip'
            }
        },
        keys = {
            ...
        }
    },

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
-# PHPEasyAttribute Add #[Attribute] for any or class
Append
-c PHPEasyAppendConstant Append constant
-p PHPEasyAppendProperty Append property
-m PHPEasyAppendMethod Append method
-t PHPEasyAppendTrait Append tait
-__ PHPEasyAppendConstruct Append **__**construct
-_i PHPEasyAppendInvoke Append __invoke
-a PHPEasyAppendArgument Append new argument in current function
Objects
-uu PHPEasyRemoveUnusedUses Remove unused uses from current file, if you use lsp: intelephense
-e PHPEasyExtends Extends current class
-i PHPEasyImplements Implements current class
--c PHPEasyInitClass Initialize class in current file
--ac PHPEasyInitAbstractClass Initialize abstract class in current file
--i PHPEasyInitInterface Initialize interface in current file
--t PHPEasyInitTrait Initialize trait in current file
--e 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\\|\\)',
        readonly = '\\(readonly\\s\\|\\)',
        constant = visibility .. 'const ',
        property = visibility .. static .. readonly .. '\\(?*\\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 --t

init trait

Init interface --i

init interface

Init abstract class --ac

init abstract class

Init class --c

init class

Add doc block -b

Class

doc class

Constant

doc constant

Property

doc property

Method

doc method

Variable

doc variable