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

Re: increment existing numbers by 1

Expand Messages
  • stosss
    I found this ... Note that you have to press Ctrl-V Ctrl-A to get the ^A character. I have ... to do what I want. But can CTRL-A or ^A be used in a
    Message 1 of 5 , Dec 31, 2012
    • 0 Attachment
      I found this

      You have to use normal to execute normal mode commands in command mode:

      :g/searchString/ normal ^A

      Note that you have to press Ctrl-V Ctrl-A to get the ^A character.

      I have

      :s@\d\+@\=submatch(0) +1@g

      to do what I want.

      But can CTRL-A or ^A be used in a :s@search@replace@g command? I
      haven't found anything that shows that it can be used that way. I saw
      in :help that it can be used in a macro. It seems if it could be used
      in a single line search with global replacement at the command line
      then it could also be used in a map.

      I'm just curious because I found a workable solution when I was trying
      to figure out if CTRL-A could be used.

      Thanks

      --
      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
    • Ben Fritz
      ... I think it should be possible to use in an s command using the expression register and a function wrapping the normal command. But I think the solution you
      Message 2 of 5 , Jan 1, 2013
      • 0 Attachment
        On Monday, December 31, 2012 9:23:43 PM UTC-6, Jack Gates wrote:
        > I found this
        >
        >
        >
        > You have to use normal to execute normal mode commands in command mode:
        >
        >
        >
        > :g/searchString/ normal ^A
        >
        >
        >
        > Note that you have to press Ctrl-V Ctrl-A to get the ^A character.
        >
        >
        >
        > I have
        >
        >
        >
        > :s@\d\+@\=submatch(0) +1@g
        >
        >
        >
        > to do what I want.
        >
        >
        >
        > But can CTRL-A or ^A be used in a :s@search@replace@g command? I
        >
        > haven't found anything that shows that it can be used that way. I saw
        >
        > in :help that it can be used in a macro. It seems if it could be used
        >
        > in a single line search with global replacement at the command line
        >
        > then it could also be used in a map.
        >

        I think it should be possible to use in an s command using the expression register and a function wrapping the normal command. But I think the solution you used with submatch() is much better.

        It can certainly be used in a mapping as well, where <C-A> is a better notation than a literal ^A character, but either will work. Just remember CTRL-A is a *normal mode* command, and therefore cannot be used directly from the command-line, where your :s command is executed.

        --
        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
      Your message has been successfully submitted and would be delivered to recipients shortly.