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

saving a mark through a filter?

Expand Messages
  • Jeremy M. Dolan
    I m trying to return the cursor to where it was before I run a file through a filter. I have a key mapping, similar to: nmap mc:%!/path/csv-add c but
    Message 1 of 2 , May 1, 2001
    • 0 Attachment
      I'm trying to return the cursor to where it was before I run a file
      through a filter. I have a key mapping, similar to:

      nmap <C-D> mc:%!/path/csv-add<CR>'c

      but when the buffer is filtered through /path/csv-add, all marks are
      lost. I read the documentation on marks, and on restore-position, but
      none of what I found survives a filter.

      Is there no way to mark row X column Y, and not the *text* at row X
      column Y?

      Also, I assume one must exist, since the column is recorded... but I
      couldn't find the command to return to the line and column of a set
      mark... only the line.

      Thanks for any help!

      /jmd
    • Benji Fisher
      ... From :help :marks, ... Filtering lines through a filter counts as deleting the lines, and adding new ones, so the marks are lost. ... You can store these
      Message 2 of 2 , May 2, 2001
      • 0 Attachment
        "Jeremy M. Dolan" wrote:
        >
        > I'm trying to return the cursor to where it was before I run a file
        > through a filter. I have a key mapping, similar to:
        >
        > nmap <C-D> mc:%!/path/csv-add<CR>'c
        >
        > but when the buffer is filtered through /path/csv-add, all marks are
        > lost. I read the documentation on marks, and on restore-position, but
        > none of what I found survives a filter.

        From :help :marks,
        > If you delete a line that contains a mark, that mark is erased.
        Filtering lines through a filter counts as deleting the lines, and adding
        new ones, so the marks are lost.

        > Is there no way to mark row X column Y, and not the *text* at row X
        > column Y?

        You can store these in a variable. (Variables can be global, local
        to the buffer, or local to a user-defined function.) For example,

        :let myline = line(".")
        :let mycol = col(".")
        :let mymark = "L=" . line(".") . "C=" . col(".")

        To make this more convenient, you can use the functions below, extracted
        from my file of example vim functions, at
        http://sites.netscape.net/BBenjiF/vim/#examples

        > Also, I assume one must exist, since the column is recorded... but I
        > couldn't find the command to return to the line and column of a set
        > mark... only the line.

        :echo "L=" . line("'c") . " C=" . col("'c")
        :help line()
        :help col()

        HTH --Benji Fisher

        " Usage: let ma = Mark() ... execute ma
        " has the same effect as normal ma ... normal 'a
        " without affecting global marks.
        " You can also use Mark(17) to refer to the start of line 17 and
        Mark(17,34)
        " to refer to the 34'th (screen) column of the line 17. The functions
        " Line() and Virtcol() extract the line or (screen) column from a "mark"
        " constructed from Mark() and default to line() and virtcol() if they do
        not
        " recognize the pattern.
        fun! Mark(...)
        if a:0 == 0
        return line(".") . "normal!" . virtcol(".") . "|"
        elseif a:0 == 1
        return a:1 . "normal!" . 0 . "|"
        else
        return a:1 . "normal!" . a:2 . "|"
        endif
        endfun

        " See comments above Mark()
        fun! Line(mark)
        if a:mark =~ '^\d\+normal!\d\+|$'
        return matchstr(a:mark, '\d\+')
        else
        return line(a:mark)
        endif
        endfun

        " See comments above Mark()
        fun! Virtcol(mark)
        if a:mark =~ '^\d\+normal!\d\+|$'
        return substitute(a:mark, '.*!\(.*\)|', '\1', "")
        else
        return col(a:mark)
        endif
        endfun
      Your message has been successfully submitted and would be delivered to recipients shortly.