Andy Wokula wrote:
A.J.Mechelynck schrieb:
Kamaraju Kusumanchi wrote:
On Friday 06 October 2006 08:24, Andy Wokula wrote:
Kamaraju Kusumanchi schrieb:
I use two mappings for my Fortran (.f90) files
map <F5> <Home>v%zf
map <F6> <Home>zDv%zf
The idea is to create folds for code blocks which are of the form
subroutine some_name_here
statements_here
end subroutine some_name_here
Here F5 folds the subroutine block irrespective of whether there are
any
folds within it. F6 folds the subroutine block after deleting the
existing folds.
However, if there are no folds and if I press F6, I get an error saying
that
E490: No fold found
Is it possible to combine these two maps into a single map such that
1) If there are no existing folds, create a fold (i.e. perform <F5>)
2) If there are already some folds defined, then delete them and
define a
new fold (i.e. perform <F6>)
Any ideas?
thanks
raju
Some time ago I saw this:
http://vim.sourceforge.net/tips/tip.php?tip_id=1330
Andy
Thanks for the pointer. I tried
nnoremap <F5> @=((foldclosed(line('.')) < 0) ? '<Home>v%zfjj' :
'<Home>zDv%zfjj')<CR>
but it did not work due to <Home>. Dont know how to escape it
properly. Any ideas? For now I am using
nnoremap <F5> @=((foldclosed(line('.')) < 0) ? '1\|v%zfjj' : '1\|
zDv%zfjj')<CR>
but would like to use <Home> instead of 1\| since that would make the
map more readable.
thanks
raju
To use the <Home> key in an expression (as here), use a double-quoted
string and a backslash-escape: "\<Home>"
See the last item under ":help expr-quote".
Best regards,
Tony.
Seems to be theory in this case, a mapping like
:nn <f7> @="\<home>"<cr>
results in an error:
=""\
E15: Invalid expression: ""\
Nevertheless
:let home = "\<home>"
:nn <f7> @=home<cr>
works. Same for both GVim 6.4 and GVim 7.0 (no latest patches) on Win32.
Looks like a bug?!
Andy
The backslash is interpreted when storing the mapping, and then again when
invoking it
In this case, you don't need @= at all
:map <F7> <Home>
:nnoremap <F5> @=((foldclosed(line('.')) < 0) ?
\ "<Bslash><lt>Home>v%zfjj" :
\ "<Bslash><lt>Home>zDv%zfjj")<CR>
see ":help :map-special-chars"
Best regards,
Tony.