1. 使用vim来编辑程序
首先先安装vim工具包,安装方法就不详细介绍了:
[lvdbing@localhost test]$ rpm -qa |grep vim vim-enhanced-6.3.046-0.40E.7 vim-minimal-6.3.046-0.40E.7 vim-common-6.3.046-0.40E.7
|
默认情况下,vim会打开高亮显示语法的。
[lvdbing@localhost test]$ cat /etc/vimrc if v:lang =~ "utf8$" || v:lang =~ "UTF-8$" set fileencodings=utf-8,latin1 endif
set nocompatible " Use Vim defaults (much better!) set bs=2 " allow backspacing over everything in insert mode "set ai " always set autoindenting on "set backup " keep a backup file set viminfo='20,\"50 " read/write a .viminfo file, don't store more " than 50 lines of registers set history=50 " keep 50 lines of command line history set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands if has("autocmd") " In text files, always limit the width of text to 78 characters autocmd BufRead *.txt set tw=78 " When editing a file, always jump to the last cursor position autocmd BufReadPost * \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal! g'\"" | \ endif endif
if has("cscope") set csprg=/usr/bin/cscope set csto=0 set cst set nocsverb " add any database in current directory if filereadable("cscope.out") cs add cscope.out " else add database pointed to by environment elseif $CSCOPE_DB != "" cs add $CSCOPE_DB endif set csverb endif
" Switch syntax highlighting on, when the terminal has colors " Also switch on highlighting the last used search pattern. if &t_Co > 2 || has("gui_running") syntax on set hlsearch endif
if &term=="xterm" set t_Co=8 set t_Sb=dm set t_Sf=dm endif
|
如上面红色字体显示的/etc/vimrc配置文件中。
2. 折叠行
#!/usr/bin/perl -w
# vim: set ai cindent et sw=4 ts=4 nowrap foldmethod=marker:
# Date : 2008-09-04
# Author: lvDbing
# {{{ sub part1($a,$b)
PART1: @list = (0x53,0x77,0x65,0x64,0x65,0x6e,012); @words = map chr, @list; print @words; # }}}
# {{{ sub part2($c,$d)
PART2: @n = (2,4,6,8); @n = map $_*2 + 6, @n; print "@n\n";
# }}}
|
用vim打开后显示如下:
#!/usr/bin/perl -w
# vim: set ai cindent et sw=4 ts=4 nowrap foldmethod=marker:
# Date : 2008-09-04
# Author: lvDbing
+-- 6 lines: # sub part1($a,$b) -----------------------------------------------------------------------------------------------
+-- 6 lines: # sub part2($c,$d) -----------------------------------------------------------------------------------------------
|
这样可以把在 # {{{sub xxx() ... # }}} 行的内容给折叠起来了,方便对整个程序的把握。
阅读(1399) | 评论(0) | 转发(0) |