source: companies/celepar/phpgwapi/doc/vim.format @ 763

Revision 763, 2.3 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

Line 
1VIM 6.0:
2
3The following should be helpful in making sure your code adheres to
4our required format.  This should turn on indenting and syntax
5highlighting for .php files in vim.
6
7Add the following to your ~/.vimrc:
8
9set ts=4
10filetype on
11filetype indent on
12set sw=4
13set smarttab
14
15You can adjust the ts and sw variables to use your preferred tabstop.
16
17
18Place the following into, e.g., /usr/share/vim/vim60/indent/php.vim.
19This is not a vim syntax file, so don't overwrite your syntax/php.vim
20with 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.
30if exists("b:did_indent")
31  finish
32endif
33let b:did_indent = 1
34
35setlocal indentexpr=GetPhpIndent()
36setlocal indentkeys+=0=,0),=EO
37
38" Only define the function once.
39if exists("*GetPhpIndent")
40  finish
41endif
42
43function 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
73endfunction
74----CUT HERE----
75
76
77HINT:  To reformat an already-coded file using the above:
78
791. 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
882. Enter command mode (hit ESC key).
89
903. 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
934. Type '='.  This should format the selected area, using cues from
94   the section above to set the initial TAB, etc.
95
965. 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
100FIN
Note: See TracBrowser for help on using the repository browser.