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

how do i remap dd so that it becomes context-dependent?

Expand Messages
  • leo
    Hello all, I m using set wrap . I d like to come up with a remap of dd that would does the follwing: If the current line is wrapped, it then performs g0dg$
    Message 1 of 5 , Jun 30, 2013
      Hello all,

      I'm using "set wrap". I'd like to come up with a remap of dd that would does the follwing:
      If the current line is wrapped, it then performs g0dg$
      Else, it performs the conventional dd.

      The problem is this. if i just use:
      vnoremap dd g0dg$
      nnoremap dd g0dg$
      whenever i have non wrapped lines, such as:
      a
      b
      c
      And I "dd" line two, it will end up with sth like:
      a
      (blank line)
      c
      Instead of this expecting result:
      a
      c

      Thanks in advance



      --
      --
      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.
    • Nikolay Pavlov
      Check whether virtcol( $ ) is greater then winwidth(0): something like this: nnoremap dd (virtcol( $ ) winwidth(0)) ? g0dg$ : dd ... vim_use
      Message 2 of 5 , Jun 30, 2013

        Check whether virtcol('$') is greater then winwidth(0): something like this:

        nnoremap <expr> dd (virtcol('$') > winwidth(0)) ? 'g0dg$' : 'dd'

        On Jun 30, 2013 10:32 PM, "leo" <barbosa.leonardo@...> wrote:
        >
        >
        > Hello all,
        >
        > I'm using "set wrap".  I'd like to come up with a remap of dd that would does the follwing:
        >     If the current line is wrapped, it then performs g0dg$
        >     Else, it performs the conventional dd.
        >
        > The problem is this. if i just use:
        >     vnoremap dd g0dg$
        >     nnoremap dd g0dg$
        > whenever i have non wrapped lines, such as:
        >     a
        >     b
        >     c
        > And I "dd" line two, it will end up with sth like:
        >     a
        >     (blank line)
        >     c
        > Instead of this expecting result:
        >     a
        >     c
        >
        > Thanks in advance
        >
        >
        >
        > --
        > --
        > 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.
        >
        >

        --
        --
        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.
         
         
      • Leonardo Barbosa
        Thanks Nikolay. That did the job. I was wondering if i could pass an argument to the map so that i can do something like : 2dd, 3dd, and so on... Leo ... -- --
        Message 3 of 5 , Jul 13, 2013
          Thanks Nikolay. That did the job. I was wondering if i could pass an
          argument to the map so that i can do something like : 2dd, 3dd, and so
          on...

          Leo


          On Sun, Jun 30, 2013 at 3:38 PM, Nikolay Pavlov <zyx.vim@...> wrote:
          > Check whether virtcol('$') is greater then winwidth(0): something like this:
          >
          > nnoremap <expr> dd (virtcol('$') > winwidth(0)) ? 'g0dg$' : 'dd'
          >
          > On Jun 30, 2013 10:32 PM, "leo" <barbosa.leonardo@...> wrote:
          >>
          >>
          >> Hello all,
          >>
          >> I'm using "set wrap". I'd like to come up with a remap of dd that would
          >> does the follwing:
          >> If the current line is wrapped, it then performs g0dg$
          >> Else, it performs the conventional dd.
          >>
          >> The problem is this. if i just use:
          >> vnoremap dd g0dg$
          >> nnoremap dd g0dg$
          >> whenever i have non wrapped lines, such as:
          >> a
          >> b
          >> c
          >> And I "dd" line two, it will end up with sth like:
          >> a
          >> (blank line)
          >> c
          >> Instead of this expecting result:
          >> a
          >> c
          >>
          >> Thanks in advance
          >>
          >>
          >>
          >> --
          >> --
          >> 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.
          >>
          >>
          >
          > --
          > --
          > 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 a topic in the
          > Google Groups "vim_use" group.
          > To unsubscribe from this topic, visit
          > https://groups.google.com/d/topic/vim_use/YHrLi4MGons/unsubscribe.
          > To unsubscribe from this group and all its topics, send an email to
          > vim_use+unsubscribe@....
          > For more options, visit https://groups.google.com/groups/opt_out.
          >
          >

          --
          --
          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.
        • Nikolay Pavlov
          On Jul 14, 2013 1:53 AM, Leonardo Barbosa ... Count is accessible via v:count and v:count1. You will have to write function that
          Message 4 of 5 , Jul 14, 2013


            On Jul 14, 2013 1:53 AM, "Leonardo Barbosa" <barbosa.leonardo@...> wrote:
            >
            > Thanks Nikolay. That did the job. I was wondering if i could pass an
            > argument to the map so that i can do something like : 2dd, 3dd, and so
            > on...

            Count is accessible via v:count and v:count1. You will have to write function that handles it properly though in the case of lengthy lines.

            > Leo
            >
            >
            > On Sun, Jun 30, 2013 at 3:38 PM, Nikolay Pavlov <zyx.vim@...> wrote:
            > > Check whether virtcol('$') is greater then winwidth(0): something like this:
            > >
            > > nnoremap <expr> dd (virtcol('$') > winwidth(0)) ? 'g0dg$' : 'dd'
            > >
            > > On Jun 30, 2013 10:32 PM, "leo" <barbosa.leonardo@...> wrote:
            > >>
            > >>
            > >> Hello all,
            > >>
            > >> I'm using "set wrap".  I'd like to come up with a remap of dd that would
            > >> does the follwing:
            > >>     If the current line is wrapped, it then performs g0dg$
            > >>     Else, it performs the conventional dd.
            > >>
            > >> The problem is this. if i just use:
            > >>     vnoremap dd g0dg$
            > >>     nnoremap dd g0dg$
            > >> whenever i have non wrapped lines, such as:
            > >>     a
            > >>     b
            > >>     c
            > >> And I "dd" line two, it will end up with sth like:
            > >>     a
            > >>     (blank line)
            > >>     c
            > >> Instead of this expecting result:
            > >>     a
            > >>     c
            > >>
            > >> Thanks in advance
            > >>
            > >>
            > >>
            > >> --
            > >> --
            > >> 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.
            > >>
            > >>
            > >
            > > --
            > > --
            > > 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 a topic in the
            > > Google Groups "vim_use" group.
            > > To unsubscribe from this topic, visit
            > > https://groups.google.com/d/topic/vim_use/YHrLi4MGons/unsubscribe.
            > > To unsubscribe from this group and all its topics, send an email to
            > > vim_use+unsubscribe@....
            > > For more options, visit https://groups.google.com/groups/opt_out.
            > >
            > >
            >
            > --
            > --
            > 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.
            >
            >

            --
            --
            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
            ... This should work: nnoremap dd (virtcol( $ ) winwidth(0)) ? g0d . (v:count 1 ? v . v:count : ) . g$ : dd The conditional
            Message 5 of 5 , Jul 14, 2013
              Nikolay Pavlov <zyx.vim@...> a écrit:
              > On Jul 14, 2013 1:53 AM, "Leonardo Barbosa" <barbosa.leonardo@...>
              > wrote:
              > >
              > > Thanks Nikolay. That did the job. I was wondering if i could pass an
              > > argument to the map so that i can do something like : 2dd, 3dd, and so
              > > on...
              >
              > Count is accessible via v:count and v:count1. You will have to write
              > function that handles it properly though in the case of lengthy lines.

              This should work:

              nnoremap <buffer> <expr> dd (virtcol('$') > winwidth(0)) ? 'g0d' . (v:count > 1 ? 'v' . v:count : '') . 'g$' : 'dd'

              The conditional addition of “v” is explained (more or less) in my next message.

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