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

Moving around comments

Expand Messages
  • Andrew Nesbit
    How can I move to the beginning/end of hash comments: # [/ and ]/ only # work for C-style # comments. ? Andrew. -- The thing that used to worry him most was
    Message 1 of 6 , Feb 1, 2004
      How can I move to the beginning/end of hash comments:

      # [/ and ]/ only
      # work for C-style
      # comments.

      ?

      Andrew.

      --
      "The thing that used to worry him most was the fact that people always
      used to ask him what he was looking so worried about."
      (Douglas Adams, "The Hitch Hiker's Guide to the Galaxy")
    • Michael Geddes
      Try these: map [# ? %(^ s*#.* n ) @ map ]# /^ ( s*# ).* n ( s*# ) @! It only works on #comments in blocks at the beginning of the line
      Message 2 of 6 , Feb 1, 2004
        Try these:

        map [# ?\%(^\s*#.*\n\)\@<!\%(^\s*#\)<CR>
        map ]# /^\(\s*#\).*\n\(\s*#\)\@!<CR>

        It only works on #comments in blocks at the beginning of the line (with
        indents), but it should work a treat.

        //.


        -----Original Message-----
        From: Andrew Nesbit [mailto:alnesbit@...]
        Sent: Monday, 2 February 2004 3:13 PM
        To: vim@...
        Subject: Moving around comments


        How can I move to the beginning/end of hash comments:

        # [/ and ]/ only
        # work for C-style
        # comments.

        ?

        Andrew.

        --
        "The thing that used to worry him most was the fact that people always
        used to ask him what he was looking so worried about." (Douglas Adams,
        "The Hitch Hiker's Guide to the Galaxy")
      • Andrew Nesbit
        ... Thanks, Michael. With :set nohlsearch it works great. Andrew. -- The thing that used to worry him most was the fact that people always used to ask him
        Message 3 of 6 , Feb 2, 2004
          On Mon, 2 Feb 2004, Michael Geddes wrote:

          > Try these:
          >
          > map [# ?\%(^\s*#.*\n\)\@<!\%(^\s*#\)<CR>
          > map ]# /^\(\s*#\).*\n\(\s*#\)\@!<CR>

          Thanks, Michael. With ":set nohlsearch" it works great.

          Andrew.

          --
          "The thing that used to worry him most was the fact that people always
          used to ask him what he was looking so worried about."
          (Douglas Adams, "The Hitch Hiker's Guide to the Galaxy")
        • Charles E. Campbell, Jr.
          ... Here s a wee modification of Michael s idea set up for sh, vim, and tex. I suggest using ftplugin and putting them in:
          Message 4 of 6 , Feb 3, 2004
            On Mon, 2 Feb 2004, Michael Geddes wrote:
            >Try these:
            > map [# ?\%(^\s*#.*\n\)\@<!\%(^\s*#\)<CR>
            > map ]# /^\(\s*#\).*\n\(\s*#\)\@!<CR>

            Here's a wee modification of Michael's idea set up for
            sh, vim, and tex. I suggest using ftplugin and putting
            them in:

            .vim/ftplugin[sh|vim|tex]/[sh|vim|tex].vim

            " ---------------------------------------------------------------------
            " --- For sh/csh/ksh/bash
            " comment jumping: (based on idea from Michael Geddes)
            " ]# : jump to beginning of next comment block
            " [# : jump to ending of previous comment block
            noremap ]# /^\(\s*#.*\n\)\@<!\(\s*#\)<CR>
            noremap [# ?\%(^\s*#.*\n\)\%(^\s*#\)\@!<CR>
            " ---------------------------------------------------------------------

            " ---------------------------------------------------------------------
            " --- For vimL
            " support function jumps
            noremap <silent> [[ ?^\s*fu\%[nction]\><CR>
            noremap <silent> ]] /^\s*fu\%[nction]\><CR>
            noremap <silent> [] ?^\s*endf*\%[unction]\><CR>
            noremap <silent> ][ /^\s*endf*\%[unction]\><CR>

            " support comment jumps
            noremap ]" /^\(\s*".*\n\)\@<!\(\s*"\)<CR>
            noremap [" ?\%(^\s*".*\n\)\%(^\s*"\)\@!<CR>
            " ---------------------------------------------------------------------

            " ---------------------------------------------------------------------
            " --- For tex
            " comment jumping: (based on idea from Michael Geddes)
            " ]% : jump to beginning of next comment block
            " [% : jump to ending of previous comment block
            noremap ]% /^\(\s*%.*\n\)\@<!\(\s*%\)<CR>
            noremap [% ?\%(^\s*%.*\n\)\%(^\s*%\)\@!<CR>
            " ---------------------------------------------------------------------

            Regards,
            Chip Campbell
          • Bram Moolenaar
            ... To avoid hlsearch highlighting, avoid using these maps in non-Vim buffers and avoid wrapping around the end of the file: Move around functions. noremap
            Message 5 of 6 , Feb 3, 2004
              Charles Campbell wrote:

              > " --- For vimL
              > " support function jumps
              > noremap <silent> [[ ?^\s*fu\%[nction]\><CR>
              > noremap <silent> ]] /^\s*fu\%[nction]\><CR>
              > noremap <silent> [] ?^\s*endf*\%[unction]\><CR>
              > noremap <silent> ][ /^\s*endf*\%[unction]\><CR>
              >
              > " support comment jumps
              > noremap ]" /^\(\s*".*\n\)\@<!\(\s*"\)<CR>
              > noremap [" ?\%(^\s*".*\n\)\%(^\s*"\)\@!<CR>

              To avoid 'hlsearch' highlighting, avoid using these maps in non-Vim
              buffers and avoid wrapping around the end of the file:

              Move around functions.
              noremap <silent><buffer> [[ :call search('^\s*fu\%[nction]\>', "bW")<CR>
              noremap <silent><buffer> ]] :call search('^\s*fu\%[nction]\>', "W")<CR>
              noremap <silent><buffer> [] :call search('^\s*endf*\%[unction]\>', "bW")<CR>
              noremap <silent><buffer> ][ :call search('^\s*endf*\%[unction]\>', "W")<CR>

              " Move around comments
              noremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR>
              noremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>

              I could add these to the Vim filetype plugin.

              --
              Apparently, 1 in 5 people in the world are Chinese. And there are 5
              people in my family, so it must be one of them. It's either my mum
              or my dad. Or my older brother Colin. Or my younger brother
              Ho-Cha-Chu. But I think it's Colin.

              /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
              /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
              \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
              \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html ///
            • Michael Geddes
              Thanks guys :) I knew there were some issues with my solution. //. ... From: Bram Moolenaar [mailto:Bram@moolenaar.net] Sent: Wednesday, 4 February 2004 1:45
              Message 6 of 6 , Feb 3, 2004
                Thanks guys :) I knew there were some issues with my solution.

                //.

                -----Original Message-----
                From: Bram Moolenaar [mailto:Bram@...]
                Sent: Wednesday, 4 February 2004 1:45 AM
                To: Charles E. Campbell, Jr.
                Cc: vim@...
                Subject: Re: Moving around comments



                Charles Campbell wrote:

                > " --- For vimL
                > " support function jumps
                > noremap <silent> [[ ?^\s*fu\%[nction]\><CR>
                > noremap <silent> ]] /^\s*fu\%[nction]\><CR>
                > noremap <silent> [] ?^\s*endf*\%[unction]\><CR>
                > noremap <silent> ][ /^\s*endf*\%[unction]\><CR>
                >
                > " support comment jumps
                > noremap ]" /^\(\s*".*\n\)\@<!\(\s*"\)<CR>
                > noremap [" ?\%(^\s*".*\n\)\%(^\s*"\)\@!<CR>

                To avoid 'hlsearch' highlighting, avoid using these maps in non-Vim
                buffers and avoid wrapping around the end of the file:

                Move around functions.
                noremap <silent><buffer> [[ :call search('^\s*fu\%[nction]\>', "bW")<CR>
                noremap <silent><buffer> ]] :call search('^\s*fu\%[nction]\>', "W")<CR>
                noremap <silent><buffer> [] :call search('^\s*endf*\%[unction]\>',
                "bW")<CR> noremap <silent><buffer> ][ :call
                search('^\s*endf*\%[unction]\>', "W")<CR>

                " Move around comments
                noremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)',
                "W")<CR> noremap <silent><buffer> [" :call
                search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR>

                I could add these to the Vim filetype plugin.

                --
                Apparently, 1 in 5 people in the world are Chinese. And there are 5
                people in my family, so it must be one of them. It's either my mum or
                my dad. Or my older brother Colin. Or my younger brother Ho-Cha-Chu.
                But I think it's Colin.

                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net
                \\\
                /// Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/
                \\\
                \\\ Project leader for A-A-P -- http://www.A-A-P.org
                ///
                \\\ Help AIDS victims, buy here: http://ICCF-Holland.org/click1.html
                ///
              Your message has been successfully submitted and would be delivered to recipients shortly.