1

I started using Seeing is Believing and updated my vimrc:

nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>

However, after I run the command, my cursor moves to the top of the file.

Is there a way to keep my cursor in the original line & column that I ran the command?

1
  • 2
    I'm not sure what seeing_is_believing is, but you could always mark your position at the beginning of the command with ma and then return to that position with `a.
    – Tumbler41
    Mar 14, 2017 at 19:28

2 Answers 2

1

In theory:

You could end your map with '' to jump back to the first non blank column on the line where you were:

nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>''

Or you could use `` to jump back to the exact column on the line where you were:

nmap <leader>s A # => <Esc>:%.!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>``

Or you could just hit <CTRL-o> (:h CTRL-o) to go to older cursor position on the jump list.

2
  • Thanks for the help @Isrdg but these solutions didn't work for me. I seem to get E20: Mark not set warning. Also, when I use u, there seems to be a more than 1 change. This might be preventing Vim from understanding my real last used line. Any suggestions? :/
    – ogirginc
    Mar 16, 2017 at 8:53
  • No idea, but just let me know if you want me to delete the answer. (: In the meantime, two things: 1) you could try to start your map by setting a mark as @Tumbler41 said, and 2) note the "A" in the beginning of the map, isn't it already changing the cursor position (but not "jumping", though not setting the ``` `` ``` mark)? And aparantly the Vim integration was done by the author, you could create an issue on the repository (and come back here with the solution o/).
    – lsrdg
    Mar 16, 2017 at 12:06
0

Vim has a couple of functions to help with this, namely winsaveview() and winrestview(). Here's an example of how you might use them:

fun! Stayput(cmd)
    let v = winsaveview()
    exec a:cmd
    call winrestview(v)
endfun
nno <leader>s mmA # => <Esc>`m:silent call Stayput('%!seeing_is_believing ...')<CR>

So save your view, do some stuff, then restore your view, including cursor and scroll positions, to exactly how it was before. I've wrapped it up in a function for convenience.

A few other notes:

  • consider using :nnoremap rather than :nmap;
  • I've used a mark in the mapping to return the cursor to where it was before the comment was appended;
  • I've used :silent to prevent editing messages appearing in the last line of the screen; and
  • I'm not sure what the . in %.! is meant to be doing.

More info. at :help winsaveview().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.