Simon Butler wrote:
On May 11, 2007, at 4:48 PM, A.J.Mechelynck wrote:
Simon Butler wrote:
[...]
maybe i'm missing something here. my objective is not to write the
comments by hand. they should appear automatically after the
brackets, thats how skill mode in emacs is setup and i'd like to be
able to do the same thing in vim
[...]
ah. I suppose it could be done by means of a lot of mappings, but it
would not be easy. Unless a plugin for that kind of thing already
exists at vim-online ("Search for Scripts" at
http://www.vim.org/search.php ), I personally don't think it wouyld be
worth the trouble of writing and debugging that kind of plugin. Of
course, YMMV.
i'm an emacs user considering moving to vim and this is something that
would i would definitely miss.
skill/lisp has a lot of brackets and commenting which bracket closes
which statement is very useful when debugging...
Vimscript has much less brackets, so that's one reason why that kind of
comments is less necessary. There have been threads on this list recently
discussing automatic pairing of brackets; and in Vim placing the cursor on any
bracket (by default () [] {} but it's configurable: e.g. I've added the &;
pair in an "after-plugin" for HTML) you see it and its mate highlighted, by
default with a light-cyan background. You may if you want define (e.g. for C)
mappings like the following:
:imap ( ()<Left>
:imap [ []<Left>
:imap { {<CR><Up><End>
Also, if the cursor is on a bracket, hitting % moves it to its mate, scrolling
the text if necessary. The "matchit" plugin extends this functionality to
paired words of more than one character, like if... elseif... else... endif,
try... catch... finally... endtry, while... enwhile, function... endfunction,
or HTML paired tags.
To repeat a function name or an if-condition in a comment you would have to
write a function asking the user the name and writing it in twice, once at the
cursor and once in a command after the ":endfunction" or ":endif" that it
would write on the next line; and you would have to remap (or maybe define
abbreviations for)
if
while
try
function
for
and maybe others (these are those which immediately come to mind). It is
doable, but I'm not convinced that it's better than adding the comments by
hand where they're actually needed (in a three-line if they probably wouldn't
be). You may want to look at $VIMRUNTIME/vimrc_example.vim (in a Vim
installation, and from within Vim) for a "typical" Vim script.
Now if you want to write Lisp (which Vim doesn't use for its inner workings)
that's a different matter. It might even be easier, by remapping only the left
bracket and finding what's before it, but I don't know Lisp well enough to be
sure.
Best regards,
Tony.
--
You will think of something funnier than this to add to the fortunes.