Loading ...
Sorry, an error occurred while loading the content.
 

combining two mapping into one

Expand Messages
  • Kamaraju Kusumanchi
    I use two mappings for my Fortran (.f90) files map v%zf map zDv%zf The idea is to create folds for code blocks which are of the form
    Message 1 of 6 , Oct 6, 2006
      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

      --
      http://groups.google.com/group/ask-anything/about
    • Andy Wokula
      ... Some time ago I saw this: http://vim.sourceforge.net/tips/tip.php?tip_id=1330 Andy ___________________________________________________________ Telefonate
      Message 2 of 6 , Oct 6, 2006
        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


        ___________________________________________________________
        Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
      • Kamaraju Kusumanchi
        ... Thanks for the pointer. I tried nnoremap @=((foldclosed(line( . )) but it did not work due to .
        Message 3 of 6 , Oct 6, 2006
          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

          --
          http://groups.google.com/group/ask-anything/about
        • A.J.Mechelynck
          ... To use the key in an expression (as here), use a double-quoted string and a backslash-escape: See the last item under :help expr-quote .
          Message 4 of 6 , Oct 6, 2006
            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.
          • Andy Wokula
            ... Seems to be theory in this case, a mapping like ... results in an error: = E15: Invalid expression: Nevertheless ... works. Same for both GVim 6.4
            Message 5 of 6 , Oct 8, 2006
              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



              ___________________________________________________________
              Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
            • A.J.Mechelynck
              ... The backslash is interpreted when storing the mapping, and then again when invoking it In this case, you don t need @= at all ...
              Message 6 of 6 , Oct 8, 2006
                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.
              Your message has been successfully submitted and would be delivered to recipients shortly.