Gary Johnson wrote:
>> Is there a good way to jump to the start of the current
>> function in a case like the following (or in other languages
>> like Python)?
>>
>> int func() {
>> int a = 1;
>> if ( whatever ) {
>> a = something(); // say cursor is on '='
>> }
>> return a;
>> }
>
> If you scroll to the bottom of the section which contains the
> target of ":help [[", you'll find this:
>
> If your '{' or '}' are not in the first column, and you would
> like to use "[[" and "]]" anyway, try these mappings: >
> :map [[ ?{<CR>w99[{
> :map ][ /}<CR>b99]}
> :map ]] j0[[%/{<CR>
> :map [] k$][%?}<CR>
>
> I tried the [[ mapping in this message and it did find the
> opening { of func(). The disadvantage to this particular set
> of mappings is that they affect the search register. A
> better approach would be to do the searching within functions
> and have the mappings call those functions. I've written a
> plugin that does this. I'll post it here if anyone is interested.
I tried ':map [[ ?{<CR>w99[{' but it only works if there is a
single function in the buffer. When inside a second function,
the mapped [[ goes to the start of the first function.
I see that there are mappings for [[ in some filetype plugins:
$VIMRUNTIME/ftplugin/php.vim
$VIMRUNTIME/ftplugin/python.vim
I guess I'll leave it at this for now, thanks Gary and Tim.
In some future life, tip 1530 might be enhanced so the [[ can be
customised.
John
--
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