Purpose: to discuss the Vim editor.
First, you can find Vim at http://www.vim.org/
MC 16 Jul 2003: This is probably old news to many, but I finally stumbled upon this little gem only this evening:
vim already does syntax highlighting for *.tcl files. For files without an extension, however, adding a comment in your code that says:
# vim: syntax=tcl
causes vim to do the highlighting properly.
glennj This magic depends on two settings: (default values)
set modeline modelines=5
vim will then look at the top 5 lines and the bottom 5 lines for these special comments. See
:help modeline
Modelines are handy for "forcing" people to conform to particular vim settings. For example, if you like a 8 space indent using tabs, but you're editing someone else's code who likes 4 space indent and no tabs, then in order not to mess up that person's code, you'll want a modeline like (demonstrating the alternate modeline syntax)
# vim: set shiftwidth=4 smarttab expandtab:
Configuring Vim to conform to yhe Tcl Style Guide
indenting
set autoindent " keep the previous line's indentation set cindent " indent after line ending in {, and use 'cinwords' " see also ':help c-indent' set shiftwidth=4
do not inadvertantly break a line
set textwidth=0
comments
set comments=:# set formatoptions+=r " Automatically insert the current comment leader set formatoptions+=q " Allow formatting of comments with 'gq'
prevent the comment character from forcibly being inserted in column 1
set cpoptions-=< " allow '<keycode>' forms in mappings, e.g. <CR> inoremap # X<BS># set cinkeys-=0# " # in column 1 does not prevent >> from indenting set indentkeys-=0#
Version 6 of vim has a wonderful feature called folding, where blocks of text can be hidden as a single line until you have to enter them. However, I can't seem to get syntax-based automatic folding of procs. The obvious
set foldmethod=syntax syntax region tclFunc start="^proc.*{$" end="^}" transparent fold
does nothing. Folding blocks works fine with
syntax region tclBlock start="{" end="}" transparent fold
but I don't really want to fold every block, I'd rather do it on the proc level. Any suggestions?
US The start regex interferes with "syntax keyword" in the tcl syntax file. Change the line
syn keyword tclStatement proc global return lindex
into
syn keyword tclStatement global return lindex syn match tclStatement "proc" contained
and add the (slightly extended) region rule
syntax region tclFunc start="^\z(\s*\)proc.*{$" end="^\z1}$" transparent fold contains=ALL
Now it should (mostly) work. The "z" part of the start and end regex allows for arbitrary indentation of your proc definition.
There is (at least) one pathological file: I reaped the bitmap editor http://wiki.tcl.tk/6298 and tried the above folding rules on it. It works quite nice, but not for the procedure definitions of ClearBMP, NewBMP, NewDlg and BitFunc. I have no idea, why. Maybe someone else knows better.
What: Vim Where: http://www.vim.org/ http://www.bodenstab.org/#VIMCONSOLE Description: Vi clone which provides language syntax colorization (including Tcl), command line edit and recall, filename completion, split windows, mouse control, drag and drop, and other features. The vimconsole is a Tclsh shell that interacts with the Tcl support one can build into vim. Currently at version 6.0 . Updated: 09/2001 Contact: mailto:[email protected]