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

do word jump commands without line-wrap?

Expand Messages
  • neolus
    Hi! is there any fast neat way to tell vim not to go to next/previous word if it s on a different line that doesn t require writing a function? e.g. a flag or
    Message 1 of 6 , Apr 3, 2013
      Hi! is there any fast neat way to tell vim not to go to next/previous word if
      it's on a different line that doesn't require writing a function? e.g. a
      flag or something? I looked but can't find anything on it other than
      whichwrap but it seems that only applies to hjkl stuff..



      --
      View this message in context: http://vim.1045645.n5.nabble.com/do-word-jump-commands-without-line-wrap-tp5714783.html
      Sent from the Vim - General mailing list archive at Nabble.com.

      --
      --
      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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • tooth pik
      ... I believe you re looking for the f command -- it is the linewise search -- use it instead of / if you want to search current line only -- after f ,
      Message 2 of 6 , Apr 3, 2013
        On Wed, Apr 03, 2013 at 10:21:08AM -0700, neolus wrote:
        > Hi! is there any fast neat way to tell vim not to go to next/previous word if
        > it's on a different line that doesn't require writing a function? e.g. a
        > flag or something? I looked but can't find anything on it other than
        > whichwrap but it seems that only applies to hjkl stuff..

        I believe you're looking for the 'f' command -- it is the linewise
        search -- use it instead of '/' if you want to search current line
        only -- after 'f', ';' repeats the search (staying on current line).

        --
        --
        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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • Christian Brabandt
        Hi neolus! ... I am afraid it is not possible without writing a function: fu! MyWordMovement(fwd) if a:fwd return :call search( .string( % .line( . ). l
        Message 3 of 6 , Apr 3, 2013
          Hi neolus!

          On Mi, 03 Apr 2013, neolus wrote:

          > Hi! is there any fast neat way to tell vim not to go to next/previous word if
          > it's on a different line that doesn't require writing a function? e.g. a
          > flag or something? I looked but can't find anything on it other than
          > whichwrap but it seems that only applies to hjkl stuff..

          I am afraid it is not possible without writing a function:


          fu! MyWordMovement(fwd)
          if a:fwd
          return ':call search('.string('\%'.line('.').'l\<'). ',"W")'."\<cr>"
          else
          return ':call search('.string('\%'.line('.').'l\<'). ',"bW")'."\<cr>"
          endif
          endfu
          nnoremap <silent> <expr> w MyWordMovement(1)
          nnoremap <silent> <expr> b MyWordMovement(0)

          Quoting is a little bit nastyš, but seems to work for me.

          š) it is probably easier to check, whether the next word movement would
          change lines and in that case return esc else return the normal w/b
          movement keys, but now I have already written down this function...

          Mit freundlichen Grüßen
          Christian
          --
          _.oooO__Oooo._
          _(___)__(___)_
          __\_(____)_/__
          ___\_)__(_/___

          --
          --
          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • Paul Isambert
          ... I think the following is slightly less nasty :) fu! MyWordMovement(backward) if search(
          Message 4 of 6 , Apr 3, 2013
            Selon Christian Brabandt <cblists@...>:

            > Hi neolus!
            >
            > On Mi, 03 Apr 2013, neolus wrote:
            >
            > > Hi! is there any fast neat way to tell vim not to go to next/previous word
            > if
            > > it's on a different line that doesn't require writing a function? e.g. a
            > > flag or something? I looked but can't find anything on it other than
            > > whichwrap but it seems that only applies to hjkl stuff..
            >
            > I am afraid it is not possible without writing a function:
            >
            >
            > fu! MyWordMovement(fwd)
            > if a:fwd
            > return ':call search('.string('\%'.line('.').'l\<'). ',"W")'."\<cr>"
            > else
            > return ':call search('.string('\%'.line('.').'l\<'). ',"bW")'."\<cr>"
            > endif
            > endfu
            > nnoremap <silent> <expr> w MyWordMovement(1)
            > nnoremap <silent> <expr> b MyWordMovement(0)
            >
            > Quoting is a little bit nastyš, but seems to work for me.

            I think the following is slightly less nasty :)

            fu! MyWordMovement(backward)
            if search('\<', 'n' . a:backward, line('.'))
            return len(a:backward) ? "b" : "w"
            else
            return "\<Esc>"
            endif
            endfunction
            nnoremap <silent> <expr> w MyWordMovement("")
            nnoremap <silent> <expr> b MyWordMovement("b")

            Best,
            Paul

            --
            --
            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

            ---
            You received this message because you are subscribed to the Google Groups "vim_use" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
          • neolus
            You guys are awesome for replying so fast :) At least I know now. What I ll do I think is before executing the action, make a mark, save the line number to a
            Message 5 of 6 , Apr 4, 2013
              You guys are awesome for replying so fast :)
              At least I know now.
              What I'll do I think is before executing the action, make a mark, save the
              line number to a variable, do the command, check to see if it changed and if
              so jump to the mark. That way I could apply it to each word command variant.
              Can anyone think of any weird corner cases where something might throw it
              off? it sounds like a concrete aproach but maybe there's weird values for
              line number in some cases or something y'know?



              --
              View this message in context: http://vim.1045645.n5.nabble.com/do-word-jump-commands-without-line-wrap-tp5714783p5714818.html
              Sent from the Vim - General mailing list archive at Nabble.com.

              --
              --
              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

              ---
              You received this message because you are subscribed to the Google Groups "vim_use" group.
              To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
              For more options, visit https://groups.google.com/groups/opt_out.
            • Tim Chase
              ... which also happens to behave in a way that makes sense with your wrapscan setting. The behavior is slightly different from the stock behaviors, as it
              Message 6 of 6 , Apr 4, 2013
                On 2013-04-03 10:21, neolus wrote:
                > Hi! is there any fast neat way to tell vim not to go to
                > next/previous word if it's on a different line that doesn't require
                > writing a function? e.g. a flag or something? I looked but can't
                > find anything on it other than whichwrap but it seems that only
                > applies to hjkl stuff..

                You could try the following mappings:

                :nnoremap w /<bslash>%<c-r>=line('.')<cr>l<bslash><lt><cr>
                :nnoremap b ?<bslash>%<c-r>=line('.')<cr>l<bslash><lt><cr>

                which also happens to behave in a way that makes sense with your
                'wrapscan' setting. The behavior is slightly different from the
                stock behaviors, as it looks for a beginning-of-word, so it doesn't
                land on intermediate punctuation. But for most cases it should do
                what you want.

                -tim



                --
                --
                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

                ---
                You received this message because you are subscribed to the Google Groups "vim_use" group.
                To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
                For more options, visit https://groups.google.com/groups/opt_out.
              Your message has been successfully submitted and would be delivered to recipients shortly.