Sunday, May 2, 2010

Re: Vim Tip 1530

On 10/03/10 00:00, Paul wrote:
> On Tue, Mar 09, 2010 at 05:44:58PM +1100, John Beckett wrote:
>> (2) See if you can make any map work:
>>
>> nnoremap \/ :echo 'This is the mapping'<CR>
>>
>> In Vim, select the above line and press y to copy it.
>> Then type :@" to execute the line.
>> Then type \/
>> You should see the text from echo.
>
> I did this and it worked. However, I was able to further narrow down the
> cause of why this wasn't working for me, and I think it's a bug!
>
> {
> The search happens when inside a block like this
> }
>
> but {
> doesn't work when in one like this!
> }
>

Well, it is true that Bram's C coding style (as exemplified by the Vim
source) always puts every single brace alone on its line, with nothing
else on the same line than zero or more whitespace and perhaps a
comment. But why not do it the other way round? Jump forward to the next
closing brace in column 1, then use % to find its mate. A column-1
closing brace would end a function or a similar top-level block,
wouldn't it? (And vice-versa.) -- Well, of course relying on indentation
to analyze C code makes some assumptions about how the coder wrote, but
I suppose anything better would require parsing the code the way a
compiler or preprocessor does.


Best regards,
Tony.
--
"Somewhere", said Father Vittorini, "did Blake not speak of the
Machineries of Joy? That is, did not God promote environments, then
intimidate these Natures by provoking the existence of flesh, toy men
and women, such as are we all? And thus happily sent forth, at our
best, with good grace and fine wit, on calm noons, in fair climes, are
we not God's Machineries of Joy?"

"If Blake said that", said Father Brian, "he never lived in Dublin."
-- R. Bradbury, "The Machineries of Joy"

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: