Difference between revisions of "vim"

Jump to: navigation, search
(Ctags)
 
(5 intermediate revisions by 3 users not shown)
Line 4: Line 4:
 
to ensure you get powerful use out of vim with moodle development
 
to ensure you get powerful use out of vim with moodle development
  
== Old Progress Bar ==
+
== Indentation ==
 +
Moodle [[Coding|Coding Guidelines]] state that indentation should be spaces of 4 spaces (not Tabs). Some .vimrc options will help you adhere to these guidelines with ease:
 +
 
 +
<pre>
 +
" insert space characters whenever the tab key is presse
 +
set expandtab
 +
 
 +
" insert 4 spaces characters when tab key is pressed
 +
set tabstop=4
 +
 
 +
" insert 4 spaces wen autoindent indents
 +
set shiftwidth=4
 +
 
 +
" automatically indent files
 +
set autoindent
 +
 
 +
" Do smart indentation depending on code syntax (e.g. change after { }, keywords etc)
 +
set smartindent
 +
</pre>
 +
 
 +
== Syntax Highlighting ==
 +
Recent versions of vim have robust syntax highlighting for php. In order to switch syntax highlighting on add the following to your .vimrc:
 
<pre>
 
<pre>
function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext='')
+
" set syntax highlighting on
 +
syntax on
 
</pre>
 
</pre>
== OOP Progress Bar ==
 
  
Usage:
+
== Other Useful vimrc settings ==
 
<pre>
 
<pre>
set_time_limit(0);
+
" show a ruler with line number, % through file on status line
$pb = new progressbar('bar', 500);
+
set ruler
$pb->create();
+
" show line number
$num_tasks = 200; // the number of tasks to be completed.
+
set nu
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
+
" PHP syntax check
{
+
set makeprg=php\ -l\ %
    for ($i=0; $i<100000; $i++)
+
set errorformat=%m\ in\ %f\ on\ line\ %l
    {
 
        ;;;
 
    }
 
    $pb->update_adv($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
 
}
 
?>
 
<hr/>
 
<?php
 
$pt = new progressbar('zbar', 900);
 
$pt->create();
 
$num_tasks = 200; // the number of tasks to be completed.
 
for($cur_task = 0; $cur_task <= $num_tasks; $cur_task++)
 
{
 
    for ($i=0; $i<100000; $i++)
 
    {
 
        ;;;
 
    }
 
    $pt->update_adv($cur_task, $num_tasks, 'this is'. $cur_task . 'h');
 
}
 
 
</pre>
 
</pre>
 +
 +
During development, you will probably often find yourself typing print_object($foo) and die(). The following lines is vimrc create a keystroke to make this faster
 +
<pre>
 +
" F5 put a Moodle debugging msg
 +
map <F5> oprint_object(); die(); // DONOTCOMMIT<Esc>23hi
 +
</pre>
 +
 +
== File encoding and decoding ==
 +
<pre>
 +
set fileencodings=ucs-bom,utf-8,gbk,big5,latin1
 +
set termencoding=utf-8,gbk
 +
if has ('multi_byte') && v:version > 601
 +
  if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
 +
    set ambiwidth=double
 +
  endif
 +
endif
 +
</pre>
 +
 +
== Status Line ==
 +
<pre>
 +
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P
 +
</pre>
 +
 +
== Ctags ==
 +
See the [[ctags|Ctags Article]] for details on how to setup ctags usage with moodle and vim
 +
 +
[[Category:Developer tools|vim]]

Latest revision as of 07:43, 10 June 2011

Setting up Vim for Moodle Development

There are many powerful features available in vim, here are a few tips to ensure you get powerful use out of vim with moodle development

Indentation

Moodle Coding Guidelines state that indentation should be spaces of 4 spaces (not Tabs). Some .vimrc options will help you adhere to these guidelines with ease:

" insert space characters whenever the tab key is presse
set expandtab

" insert 4 spaces characters when tab key is pressed
set tabstop=4

" insert 4 spaces wen autoindent indents
set shiftwidth=4

" automatically indent files
set autoindent

" Do smart indentation depending on code syntax (e.g. change after { }, keywords etc)
set smartindent

Syntax Highlighting

Recent versions of vim have robust syntax highlighting for php. In order to switch syntax highlighting on add the following to your .vimrc:

" set syntax highlighting on
syntax on

Other Useful vimrc settings

" show a ruler with line number, % through file on status line
set ruler
" show line number
set nu
" PHP syntax check
set makeprg=php\ -l\ %
set errorformat=%m\ in\ %f\ on\ line\ %l

During development, you will probably often find yourself typing print_object($foo) and die(). The following lines is vimrc create a keystroke to make this faster

" F5 put a Moodle debugging msg
map <F5> oprint_object(); die(); // DONOTCOMMIT<Esc>23hi

File encoding and decoding

set fileencodings=ucs-bom,utf-8,gbk,big5,latin1
set termencoding=utf-8,gbk
if has ('multi_byte') && v:version > 601
  if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
    set ambiwidth=double
  endif
endif

Status Line

set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P

Ctags

See the Ctags Article for details on how to setup ctags usage with moodle and vim