sublime插件與使用技巧

1. 好用插件推薦

1.1 HtmlBeautify

html頁面的美化,直接ctr+shift+p輸入htmlB調用即可。

1.2 JsFormat

快捷方式ctr+alt+F,js的格式化。

1.3 SideBarEnhancements

增強的側欄功能,添加就知道怎麼好了

1.4 AdvancedNewFile

快捷方式ctr+alt+N,New新的文件,支持tab自動補全文件夾,非常方便。

1.5 SyncedSideBar

自動同步當前打開文件的side bar位置。

1.6 phpfmt(deleted)

直接安裝就行。
https://packagecontrol.io/packages/phpfmt
注意確保php在系統的PATH中,因爲這個功能具是php寫的,需要php執行。
phpfmt已經商業化,需要使用免費的php-cs-fixer.phar作爲engine,點擊下載php-cs-fixer.phar拷貝到phpfmt的安裝目錄,更改phpfmt的settings,將engine更改爲php-cs-fixer.phar。

另外,在Preferences----Package Settings----phpfmt----Settings - User中添加如下內容

{
    "autocomplete": true,
    "autoimport": true,
    "passes":
    [
        "AlignEquals",
        "AlignDoubleArrow",
        "AlignDoubleSlashComments",
        "AlignGroupDoubleArrow",
        "LongArray",
    ],
    "psr2": true,
    "smart_linebreak_after_curly": true,
    "version": 3
}

要執行,直接使用ctrl+shitf+p phpfmt: format now。或者快捷鍵ctrl+f11

1.7 sublime_phpcs

這個是檢查php代碼錯誤的插件,推薦。
安裝PHP_CodeSniffer:

pear :  下載 http://pear.php.net/go-pear.phar
執行: php go-pear.phar
執行:pear install PHP_CodeSniffer

cpi ---安裝package---->  sublimilinter_phpcs

1.8 DocBlockr

sublime的php doc插件 DocBlockr,應該大家已經在用,現在需要修改一下配置,避免到處是[description]而實際上沒有任何有效的description被添加的情況。
Preferences --> Package Settings --> DocBlockr -> Settings -User:

{
    "jsdocs_function_description": false,
    "jsdocs_return_description": false,
    "jsdocs_param_description": false,
    "jsdocs_param_name": true,
    "jsdocs_align_tags": "shallow",
    "jsdocs_spacer_between_sections": true
}

一個示例如下:

    /**
     * Send wechat message and notice for purchasing order finished.
     *
     * @param  App\Shop $shop
     * @param  App\PurchasingOrder $purchasingOrder
     *
     * @return void
     */

注意

  • @param 後面有兩個空格,而類型後面有一個空格,不需要對齊。

  • 方法說明後一個空行,@param塊後一個空行。@return後不允許有空行。

1.9 Cobalt2

這是一個color scheme,關注於把注意力放在代碼本身,試用幾個周後確實發現這種scheme有其優勢。建議大家體驗。

1.10 phpcs

因爲phpfmt商業化導致無法正常使用,使用php-cs-fixer的engine也需要配置很多數據,建議使用phpcs,配置如下:

  1. 使用composer安裝php-cs-fixer

    composer global require friendsofphp/php-cs-fixer
  2. sublime安裝phpcs

    pci------------- phpcs
  3. 配置phpcs,

    preferences--package settings---php code sniffer

    將以下內容添加進去:

{
    // Example for:
    // - Windows 8.1
    // - With phpcs and php-cs-fixer support
    // - You have to change "YOUR_USERNAME_HERE" strings.
    // - Notice: This uses phpcs which is installed
    // -         using composer not xampp.
    // -         Be sure to install phpcs using composer.

    // We want debugging on
    "show_debug": true,

    // Only execute the plugin for php files
    "extensions_to_execute": ["php"],

    // Do not execute for twig files
    "extensions_to_blacklist": ["twig.php"],

    // Execute the sniffer on file save
    "phpcs_execute_on_save": true,

    // Show the error list after save.
    "phpcs_show_errors_on_save": true,

    // Show the errors in the gutter
    "phpcs_show_gutter_marks": true,

    // Show outline for errors
    "phpcs_outline_for_errors": true,

    // Show the errors in the status bar
    "phpcs_show_errors_in_status": true,

    // Show the errors in the quick panel so you can then goto line
    "phpcs_show_quick_panel": true,

    // Path to php on windows installation
    // This is needed as we cannot run phars on windows, so we run it through php
    "phpcs_php_prefix_path": "",

    // We want the fixer to be run through the php application
    "phpcs_commands_to_php_prefix": ["Fixer"],


    // PHP_CodeSniffer settings
    // Yes, run the phpcs command
    "phpcs_sniffer_run": true,

    // And execute it on save
    "phpcs_command_on_save": true,

    // This is the path to the bat file when we installed PHP_CodeSniffer
    "phpcs_executable_path": "C:\\Users\\benjamincao\\AppData\\Roaming\\Composer\\vendor\\bin\\phpcs.bat",

    // I want to run the PSR2 standard, and ignore warnings
    "phpcs_additional_args": {
        "--standard": "PSR2",
        "-n": ""
    },


    // PHP-CS-Fixer settings
    // Don't want to auto fix issue with php-cs-fixer
    "php_cs_fixer_on_save": true,

    // Show the quick panel
    "php_cs_fixer_show_quick_panel": false,

    // The fixer phar file is stored here:
    "php_cs_fixer_executable_path": "C:\\Users\\benjamincao\\AppData\\Roaming\\Composer\\vendor\\bin\\php-cs-fixer.bat",

    // Additional arguments, run all levels of fixing
    "php_cs_fixer_additional_args": {
        "--level":"psr2",
        "--fixers":"-psr0,array_element_no_space_before_comma,array_element_white_space_after_comma,extra_empty_lines,blankline_after_open_tag,duplicate_semicolon,function_typehint_space,operators_spaces,align_equals,align_double_arrow,ordered_use,whitespacy_lines,concat_with_spaces,unused_use,unary_operators_spaces,ternary_spaces,single_quote"
    },


    // PHP Linter settings
    // Yes, lets lint the files
    "phpcs_linter_run": true,

    // And execute that on each file when saved (php only as per extensions_to_execute)
    "phpcs_linter_command_on_save": true,

    // Path to php
    "phpcs_php_path": "C:\\php-7.0.5-nts-Win32-VC14-x64\\php.exe",

    // This is the regex format of the errors
    "phpcs_linter_regex": "(?P<message>.*) on line (?P<line>\\d+)",


    // PHP Mess Detector settings
    // Not turning on the mess detector here
    "phpmd_run": false,
    "phpmd_command_on_save": false,
    "phpmd_executable_path": "",
    "phpmd_additional_args": {"align_equals":""}
}

注意:需要將路徑配置爲自己本地路徑。

  1. 試一下是否正常。

2. 使用技巧

2.1 關於代碼摺疊:

ctrl+shift+[    摺疊代碼塊(光標所在位置)
ctrlshift]      取消折疊(光標所在位置)

ctrl+k,0        取消所有摺疊
ctrl+k, 1 (-9)  設置摺疊等級:1是類層面,2,就是類的所有函數了。

例如如果要將所有函數都摺疊,可以這樣操作:ctrl+k,2

php語法檢測,sublime linter-php

打開控制檯,install package

搜 sublimelinter

先安裝sublimelinter本體

安裝完以後再搜索一下,安裝sublimelinter-php

接下來,打開preferences-package settings-sublimeLinter-settings--user

如下配置:

{
    "user": {
         
        "linters": {
             
        },
         
        "paths": {
            "linux": [],
            "osx": [],
            "windows": [
                "D:\\xampp\\php"            ]
        },
         
    }
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章