Making vim grok Obj-C
Like many, I use the popular open-source text editor vim. Earlier, I set about making it more usable through syntax coloring. This included tweaking its support for Objective-C.
First, mkdir ~/.vim, and cd ~/.vim. Now mkdir syntax. cp /usr/share/vim/vim62/filetype.vim . and cp /usr/share/vim/vim62/syntax/objc.vim syntax/. Then select and copy this patch:
Index: filetype.vim =================================================================== --- filetype.vim 2005-03-21 02:12:47.000000000 -0800 +++ filetype.vim 2006-04-24 03:33:27.000000000 -0700 @@ -262,7 +262,7 @@ " .h files can be C or C++, set c_syntax_for_h if you want C au BufNewFile,BufRead *.h - \ if exists("c_syntax_for_h") | setf c | else | setf cpp | endif + \ if exists("c_syntax_for_h") | setf c | else | if exists("objc_syntax_for_h") | setf objc | else | setf cpp | endif | endif " TLH files are C++ headers generated by Visual C++'s #import from typelibs au BufNewFile,BufRead *.tlh setf cpp Index: syntax/objc.vim =================================================================== --- syntax/objc.vim 2005-03-21 02:12:49.000000000 -0800 +++ syntax/objc.vim 2006-04-24 03:19:25.000000000 -0700 @@ -43,6 +43,8 @@ syn match objcDirective "@class\|@end\|@defs" syn match objcDirective "@encode\|@protocol\|@selector" +syn keyword objcStorageClass in out inout byref bycopy + " Match the ObjC method types " " NOTE: here I match only the indicators, this looks @@ -73,6 +75,7 @@ HiLink objcFactMethod Function HiLink objcStatement Statement HiLink objcDirective Statement + HiLink objcStorageClass StorageClass delcommand HiLink endif
Now type pbpaste | patch -p0.
OK, now you have modified copies of the file type detector and the Obj-C syntax coloring. Now you need a .vimrc. If you already have one, add this to it; otherwise, create it with this:
let c_gnu=1 let c_no_bracket_error=1 let objc_syntax_for_h=1 syntax enable
This makes the following changes:
- c_gnu
- Enables detection of some GCC extensions to C.
- c_no_bracket_error
- Allows
{}
inside of[]
. This lets you do compound literals inside messages; for example:[self setFrame:(NSRect){ NSZeroPoint, (NSSize){ 128.0f, 128.0f } }];
- objc_syntax_for_h
- Tells vim (with my modifications, that you did above) that a .h file is an Obj-C header, not a C++ header.
- syntax enable
- Enables syntax-highlighting.
0 comments:
Post a Comment
<< Home