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

Canonical way of replacing words at given sets of positions in files (which may not be open)

Expand Messages
  • Nathan Hüsken
    Hey, For doing libclang assisted re-factoring (renaming of symbols), I want to replace the symbol name at given locations with the new symbol name. Now, the
    Message 1 of 2 , Feb 15, 2013
    • 0 Attachment
      Hey,

      For doing libclang assisted re-factoring (renaming of symbols), I want to replace the symbol name at given locations with the new symbol name.

      Now, the locations are given as (fileName,line,column).
      I could issue the editor commands to:

      * edit fileName
      * jump to (line,column)
      * delete old symbol (I know how long it is)
      * insert new symbol

      While this would work, it would pollute my jump list.
      So I am wondering, what would be the best way to replace words at a given set of locations without any side effects like polluting the jump list?

      Thanks!
      Nathan

      --
      --
      You received this message from the "vim_dev" 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_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Ingo Karkat
      ... I would use getline() in a loop over the positions and perform the replacement with either substitute() or strpart() (probably the latter when I already
      Message 2 of 2 , Feb 15, 2013
      • 0 Attachment
        On 15-Feb-13 09:24:11 +0100, Nathan Hüsken wrote:

        > Hey,
        >
        > For doing libclang assisted re-factoring (renaming of symbols), I want
        > to replace the symbol name at given locations with the new symbol
        > name.
        >
        > Now, the locations are given as (fileName,line,column). I could issue
        > the editor commands to:
        >
        > * edit fileName * jump to (line,column) * delete old symbol (I know
        > how long it is) * insert new symbol
        >
        > While this would work, it would pollute my jump list. So I am
        > wondering, what would be the best way to replace words at a given set
        > of locations without any side effects like polluting the jump list?

        I would use getline() in a loop over the positions and perform the replacement
        with either substitute() or strpart() (probably the latter when I already have
        the byte indices). Then write back the result with setline(). This avoids all
        side effects.

        -- regards, ingo

        PS: Such questions are better directed to vim_use.

        --
        --
        You received this message from the "vim_dev" 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_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+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.