Hướng dẫn run php sublime text - chạy văn bản php sublime

Sau 1 ngày vọc Sublime Text 2, dù chỉ xài bản unregistered của nó nhưng thực sự mình cảm thấy rất hay ‘falling in love with Sublime’ ! Nhưng để dùng nó thực sự không dễ, sau đây là 1 số kinh nghiệm của mình, sẽ share ra cho các bạn, ai có idea gì hay chỉ mình với nhé.
Nhưng để dùng nó thực sự không dễ, sau đây là 1 số kinh nghiệm của mình, sẽ share ra cho các bạn, ai có idea gì hay chỉ mình với nhé.

1) Tuy là bản unregistered nhưng xài thoải mái, thỉnh thoảng sublime text mới hiện lên pop-up báo là bạn đang dùng thử, vui lòng mua, vậy thôi. Tuy là bản unregistered nhưng xài thoải mái, thỉnh thoảng sublime text mới hiện lên pop-up báo là bạn đang dùng thử, vui lòng mua, vậy thôi.

2) Về Plugin của Sublime Text 2 mà mình đang dùng: là 1 dev php, mình cần những plugin để giúp mình hoàn thành công việc, do đó mình chọn plugin sau: Package manager, Alignment, Jdoc, Jslint, CodeIntel (Đặc biệt là thằng này rất hay). Các Plugin đều rất dễ install và sử dụng, duy chỉ có Jslint và Code Intel là hơi khổ 1 tí. a) Jslint bạn phải cấu hình cho nó chạy oke. Mình chỉ cấu hình đơn giản như sau: Về Plugin của Sublime Text 2 mà mình đang dùng: là 1 dev php, mình cần những plugin để giúp mình hoàn thành công việc, do đó mình chọn plugin sau: Package manager, Alignment, Jdoc, Jslint, CodeIntel (Đặc biệt là thằng này rất hay).
Các Plugin đều rất dễ install và sử dụng, duy chỉ có Jslint và Code Intel là hơi khổ 1 tí.
a) Jslint bạn phải cấu hình cho nó chạy oke. Mình chỉ cấu hình đơn giản như sau:

{

    "jslint_options": "--regexp --white --sloppy"

}


b) Code Intel sau khi install, để chạy nó, bạn cần làm là: – Tạo 1 project, trong project đó có folder source của bạn. Ví dụ mình tạo 2 folder là A và B. Với A là folder web của mình và B là folder library (có thể là WP, Zend…). – Bạn chỉ việc alt + Click vào hàm muốn dùng, lần đầu tiên CodeIntel sẽ run toàn bộ 2 folder của bạn, việc này mất khoảng 10p nếu folder rộng. Sau đó 1 là nó sẽ show definition, 2 là open file đó giúp bạn. Khi new File thì nó sẽ load thư viện phù hợp giúp bạn.(Trong trường hợp muốn SublimeCodeIntel scan lại thì vào trong folder: C:Userscomputer-name.codeintel và delete thư mục ‘db’)3) Học các phím tắt quan trọng của nó như: Ctrl + P, Ctrl + F5(Jslint)… và chuyển các phím tắt mình thường dùng sang Sublime Text 2. Tắt minimap đi vì mình thấy minimap không cần thiết lắm. Bật Wordwrap.
– Tạo 1 project, trong project đó có folder source của bạn. Ví dụ mình tạo 2 folder là A và B. Với A là folder web của mình và B là folder library (có thể là WP, Zend…).

Hướng dẫn run php sublime text - chạy văn bản php sublime

– Bạn chỉ việc alt + Click vào hàm muốn dùng, lần đầu tiên CodeIntel sẽ run toàn bộ 2 folder của bạn, việc này mất khoảng 10p nếu folder rộng. Sau đó 1 là nó sẽ show definition, 2 là open file đó giúp bạn. Khi new File thì nó sẽ load thư viện phù hợp giúp bạn.(Trong trường hợp muốn SublimeCodeIntel scan lại thì vào trong folder: C:Userscomputer-name.codeintel và delete thư mục ‘db’)
Hướng dẫn run php sublime text - chạy văn bản php sublime

3) Học các phím tắt quan trọng của nó như: Ctrl + P, Ctrl + F5(Jslint)… và chuyển các phím tắt mình thường dùng sang Sublime Text 2. Tắt minimap đi vì mình thấy minimap không cần thiết lắm. Bật Wordwrap.

4) Tạo theme, mình dùng color Scheme ‘Mac Classic’ và theme Soda dark. Cuối cùng là cấu hình preferences -> Finish! Tạo theme, mình dùng color Scheme ‘Mac Classic’ và theme Soda dark. Cuối cùng là cấu hình preferences -> Finish!

5) Tạo regedit cho sublime Text 2 để nó có thể code cho mọi file: Tạo regedit cho sublime Text 2 để nó có thể code cho mọi file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT*shellEdit with Sublime Text 2Command]

    0    1

6) Tạo validate cho PHP file: Code php mà không validate được thì thật nguy hiểm. Để validate được, đầu tiên ta cần cài PHP CodeSniffer. Cách cài thì follow theo hướng dẫn tạiđây. Tạo validate cho PHP file: Code php mà không validate được thì thật nguy hiểm. Để validate được, đầu tiên ta cần cài PHP CodeSniffer. Cách cài thì follow theo hướng dẫn tạiđây.

1

    2

Sau khi install PHP_CodeSniffer thì ta phải dùng tới công cụ Build System để validate. Vào Tool -> Build System -> New Build System -> Gõ đoạn code này vào (sẽ kiểm tra cả phplint và PHP_CodeSniffer):

{

    4    5    6    7    8    9    8"jslint_options"1    8"jslint_options"3    8"jslint_options"5    8    9    8"jslint_options"9    8"jslint_options"1: 2

    4: 4: : 6: 7

    4: 9: "--regexp --white --sloppy"1: 7

    4"--regexp --white --sloppy"4: "--regexp --white --sloppy"6

}

Thay d:/xampp/php/php và d:/xampp/php/phpcs.bat thành thư mục của bạn. Sau đó save file này tại: Sublime Text 2DataPackagesUser, đặt tên là php.sublime-build. Vào lại Sublime Text -> Tool -> Build (Nhớ kiểm tra xem Build System có check là Automatic chưa?) Trong quá trình build, nếu thấy báo lỗi ‘Unable to load dynamic library…’ thì vào file php.ini để kiểm tra xem extension và browse cap có đặt đúng đường dẫn chưa?
Sau đó save file này tại: Sublime Text 2DataPackagesUser, đặt tên là php.sublime-build.
Vào lại Sublime Text -> Tool -> Build (Nhớ kiểm tra xem Build System có check là Automatic chưa?)
Trong quá trình build, nếu thấy báo lỗi ‘Unable to load dynamic library…’ thì vào file php.ini để kiểm tra xem extension và browse cap có đặt đúng đường dẫn chưa?

"--regexp --white --sloppy"8"--regexp --white --sloppy"9

}0}1

Để tạo MyRule ta tạo folder MyRule và ruleset.xml trong: phppearPHPCodeSnifferStandardsMyRuleruleset.xml Config cho standard MyRule trong ruleset.xml ta cần lưu ý như sau: ref = Generic.Files.LineEndings có nghĩa là ta sẽ gán biến eolChar vào file phppearPHPCodeSnifferStandardsGenericSniffsFilesLineLengthSniff.php File ruleset.xml của mình như sau:
phppearPHPCodeSnifferStandardsMyRuleruleset.xml
Config cho standard MyRule trong ruleset.xml ta cần lưu ý như sau:
ref = Generic.Files.LineEndings có nghĩa là ta sẽ gán biến eolChar vào file
phppearPHPCodeSnifferStandardsGenericSniffsFilesLineLengthSniff.php
File ruleset.xml của mình như sau:

}2}3 }4}5}6}7

}8}9 Windows Registry Editor Version 5.000}5Windows Registry Editor Version 5.002Windows Registry Editor Version 5.003

Windows Registry Editor Version 5.004}8Windows Registry Editor Version 5.006Windows Registry Editor Version 5.007Windows Registry Editor Version 5.006Windows Registry Editor Version 5.003

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5[HKEY_CLASSES_ROOT*shellEdit 5[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5with2[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5with9[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5Sublime Text 2Command]6[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5    03[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5    10[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004}8[HKEY_CLASSES_ROOT*shellEdit 2 [HKEY_CLASSES_ROOT*shellEdit 3}5    17Windows Registry Editor Version 5.003

    4}8    21 Windows Registry Editor Version 5.000}5    24[HKEY_CLASSES_ROOT*shellEdit 6

    4}8    21 Windows Registry Editor Version 5.000}5    31[HKEY_CLASSES_ROOT*shellEdit 6

    4}8    21 Windows Registry Editor Version 5.000}5    38[HKEY_CLASSES_ROOT*shellEdit 6

    4}8    21 Windows Registry Editor Version 5.000}5    45[HKEY_CLASSES_ROOT*shellEdit 6

    4}8    21 Windows Registry Editor Version 5.000}5    52[HKEY_CLASSES_ROOT*shellEdit 6

Windows Registry Editor Version 5.004    55[HKEY_CLASSES_ROOT*shellEdit 2Windows Registry Editor Version 5.003

    55}9Windows Registry Editor Version 5.003

Document ruleset.xml tại đây. Sau khi setup đầy đủ, bấm Ctrl+B để cảm nhận thành quả!
Sau khi setup đầy đủ, bấm Ctrl+B để cảm nhận thành quả!

Hướng dẫn run php sublime text - chạy văn bản php sublime

7) Cho phép PHP block hiển thị trong Javascript: Đầu tiên phải tìm được chỗ cần lấy ra có scope là gì? Để con trỏ chuột vào chỗ cần lấy, gõ Ctrl+Alt+Shift+P sẽ show ra được ở console dòng cuối là: string.quoted.double.js. Chỉ việc tìm đoạn đó và include vào đoạn hỗ trợ PHP code #php. Thực thi như sau: Tìm file /Sublime Text 2/Data/Packages/JavaScript/JavaScript.tmLanguage. Thêm đoạn này vào gần cuối: Cho phép PHP block hiển thị trong Javascript:

Hướng dẫn run php sublime text - chạy văn bản php sublime

Đầu tiên phải tìm được chỗ cần lấy ra có scope là gì? Để con trỏ chuột vào chỗ cần lấy, gõ Ctrl+Alt+Shift+P sẽ show ra được ở console dòng cuối là: string.quoted.double.js. Chỉ việc tìm đoạn đó và include vào đoạn hỗ trợ PHP code #php. Thực thi như sau:
Tìm file /Sublime Text 2/Data/Packages/JavaScript/JavaScript.tmLanguage. Thêm đoạn này vào gần cuối:

}8    62Windows Registry Editor Version 5.003

    }8    66    67    66Windows Registry Editor Version 5.003

    }8    72    73    72Windows Registry Editor Version 5.003

    }8    66    79    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72"jslint_options"05    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66"jslint_options"19    66Windows Registry Editor Version 5.003

    }8    72    73    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"31    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72"jslint_options"57    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66    99    66Windows Registry Editor Version 5.003

    }8    72"jslint_options"77    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"83    66Windows Registry Editor Version 5.003

    }8"jslint_options"88Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66"jslint_options"97    66Windows Registry Editor Version 5.003

    96}8    72: 03    72Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72: 15    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66: 29    66Windows Registry Editor Version 5.003

    96}8    72: 35    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55"jslint_options"88Windows Registry Editor Version 5.003

    55    62Windows Registry Editor Version 5.003

}8    62Windows Registry Editor Version 5.003

    }8    66    67    66Windows Registry Editor Version 5.003

    }8    72: 61    72Windows Registry Editor Version 5.003

    }8    66    79    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72"jslint_options"05    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66"jslint_options"19    66Windows Registry Editor Version 5.003

    }8    72: 61    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"31    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72"jslint_options"57    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66    99    66Windows Registry Editor Version 5.003

    }8    72"--regexp --white --sloppy"65    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"83    66Windows Registry Editor Version 5.003

    }8"jslint_options"88Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66"jslint_options"97    66Windows Registry Editor Version 5.003

    96}8    72"--regexp --white --sloppy"91    72Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72: 15    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66: 29    66Windows Registry Editor Version 5.003

    96}8    72: 35    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55"jslint_options"88Windows Registry Editor Version 5.003

    55    62Windows Registry Editor Version 5.003

}37

}8    66}40    66Windows Registry Editor Version 5.003

}8    62Windows Registry Editor Version 5.003

    }8    66}49    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    67    66Windows Registry Editor Version 5.003

    86}8    72}65    72Windows Registry Editor Version 5.003

    86}8    66"jslint_options"19    66Windows Registry Editor Version 5.003

    86}8    72}77    72Windows Registry Editor Version 5.003

    86}8    66"jslint_options"83    66Windows Registry Editor Version 5.003

    86}8"jslint_options"88Windows Registry Editor Version 5.003

    96}8    62Windows Registry Editor Version 5.003

}94}8    66: 29    66Windows Registry Editor Version 5.003

}94}8    72Windows Registry Editor Version 5.0003    72Windows Registry Editor Version 5.003

    96    55    62Windows Registry Editor Version 5.003

    86    55"jslint_options"88Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    55    62Windows Registry Editor Version 5.003

Tương tự như vậy, muốn hỗ trợ tag HTML trong php code thì ta làm như sau: Tìm Sublime Text 2/Data/Packages/PHP/PHP.tmLanguage thêm vào include text.html.basic

}8    66Windows Registry Editor Version 5.0023    66Windows Registry Editor Version 5.003

}8    62Windows Registry Editor Version 5.003

    }8    66    67    66Windows Registry Editor Version 5.003

    }8    72: 61    72Windows Registry Editor Version 5.003

    }8    66    79    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72Windows Registry Editor Version 5.0070    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66Windows Registry Editor Version 5.0084    66Windows Registry Editor Version 5.003

    }8    72Windows Registry Editor Version 5.0090    72Windows Registry Editor Version 5.003

    }8    66Windows Registry Editor Version 5.0096    66Windows Registry Editor Version 5.003

    }8    72[HKEY_CLASSES_ROOT*shellEdit 02    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"19    66Windows Registry Editor Version 5.003

    }8    72: 61    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"31    66Windows Registry Editor Version 5.003

    }8    62Windows Registry Editor Version 5.003

    86}8    66    89    66Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66    99    66Windows Registry Editor Version 5.003

    96}8    72[HKEY_CLASSES_ROOT*shellEdit 46    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55    62Windows Registry Editor Version 5.003

    }8    66    99    66Windows Registry Editor Version 5.003

    }8    72[HKEY_CLASSES_ROOT*shellEdit 66    72Windows Registry Editor Version 5.003

    }8    66"jslint_options"83    66Windows Registry Editor Version 5.003

    }8"jslint_options"88Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66: 29    66Windows Registry Editor Version 5.003

    96}8    72[HKEY_CLASSES_ROOT*shellEdit 92    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

    86}8    62Windows Registry Editor Version 5.003

    96}8    66: 29    66Windows Registry Editor Version 5.003

    96}8    72with12    72Windows Registry Editor Version 5.003

    86    55    62Windows Registry Editor Version 5.003

        55"jslint_options"88Windows Registry Editor Version 5.003

    55    62Windows Registry Editor Version 5.003

8) Cho phép mouse select trong 1 click: Chỉnh tại: Packages/User/Default (Windows).sublime-mousemap Cho phép mouse select trong 1 click:
Chỉnh tại: Packages/User/Default (Windows).sublime-mousemap

with26

    {

    86with30: with32    8with34with35with36    6with38with39

    86with41with42with43: with45with46

    86with48: with50

    }

with53

Tóm lại Sublime Text 2 là 1 text editor tuyệt vời mà mình nghĩ nếu ai biết nó cũng sẽ LOVE.