1 | VIM 6.0: |
---|
2 | |
---|
3 | The following should be helpful in making sure your code adheres to |
---|
4 | our required format. This should turn on indenting and syntax |
---|
5 | highlighting for .php files in vim. |
---|
6 | |
---|
7 | Add the following to your ~/.vimrc: |
---|
8 | |
---|
9 | set ts=4 |
---|
10 | filetype on |
---|
11 | filetype indent on |
---|
12 | set sw=4 |
---|
13 | set smarttab |
---|
14 | |
---|
15 | You can adjust the ts and sw variables to use your preferred tabstop. |
---|
16 | |
---|
17 | |
---|
18 | Place the following into, e.g., /usr/share/vim/vim60/indent/php.vim. |
---|
19 | This is not a vim syntax file, so don't overwrite your syntax/php.vim |
---|
20 | with this: |
---|
21 | |
---|
22 | ----CUT HERE---- |
---|
23 | " Vim indent file |
---|
24 | " Language: Php |
---|
25 | " Author: Miles Lott <milos@groupwhere.org> |
---|
26 | " URL: http://milosch.dyndns.org/php.vim |
---|
27 | " Last Change: 2001 Sep 08 |
---|
28 | |
---|
29 | " Only load this indent file when no other was loaded. |
---|
30 | if exists("b:did_indent") |
---|
31 | finish |
---|
32 | endif |
---|
33 | let b:did_indent = 1 |
---|
34 | |
---|
35 | setlocal indentexpr=GetPhpIndent() |
---|
36 | setlocal indentkeys+=0=,0),=EO |
---|
37 | |
---|
38 | " Only define the function once. |
---|
39 | if exists("*GetPhpIndent") |
---|
40 | finish |
---|
41 | endif |
---|
42 | |
---|
43 | function GetPhpIndent() |
---|
44 | " Get the line to be indented |
---|
45 | let cline = getline(v:lnum) |
---|
46 | |
---|
47 | " Find a non-blank line above the current line. |
---|
48 | let lnum = prevnonblank(v:lnum - 1) |
---|
49 | " Hit the start of the file, use zero indent. |
---|
50 | if lnum == 0 |
---|
51 | return 0 |
---|
52 | endif |
---|
53 | let line = getline(lnum) |
---|
54 | let ind = indent(lnum) |
---|
55 | |
---|
56 | " Indent after php open tags |
---|
57 | if line =~ '<?php' |
---|
58 | let ind = ind + &sw |
---|
59 | endif |
---|
60 | if cline =~ '^\s*[?>]' |
---|
61 | let ind = ind - &sw |
---|
62 | endif |
---|
63 | |
---|
64 | " Indent blocks enclosed by {} or () |
---|
65 | if line =~ '[{(]\s*\(#[^)}]*\)\=$' |
---|
66 | let ind = ind + &sw |
---|
67 | endif |
---|
68 | if cline =~ '^\s*[)}]' |
---|
69 | let ind = ind - &sw |
---|
70 | endif |
---|
71 | |
---|
72 | return ind |
---|
73 | endfunction |
---|
74 | ----CUT HERE---- |
---|
75 | |
---|
76 | |
---|
77 | HINT: To reformat an already-coded file using the above: |
---|
78 | |
---|
79 | 1. Format the first few lines of the file manually |
---|
80 | <?php |
---|
81 | $GLOBALS['phpgw_info']['flags']['appname'] = 'yourapp'; |
---|
82 | include('../header.inc.php'); |
---|
83 | if(1) |
---|
84 | { |
---|
85 | hello(); |
---|
86 | } |
---|
87 | |
---|
88 | 2. Enter command mode (hit ESC key). |
---|
89 | |
---|
90 | 3. Type 'v' to enter visual mode. Use your arrow and PAGEUP/DOWN keys |
---|
91 | to select the rest of the file or a section you wish to format. |
---|
92 | |
---|
93 | 4. Type '='. This should format the selected area, using cues from |
---|
94 | the section above to set the initial TAB, etc. |
---|
95 | |
---|
96 | 5. Visually inspect this section to make sure the formatting is correct. |
---|
97 | Using the above method is nearly perfect, but depends on the proper |
---|
98 | use of brackets for if statements, etc, as outlined in coding_standard.txt. |
---|
99 | |
---|
100 | FIN |
---|