esamattis / slimux

SLIME inspired tmux integration plugin for Vim
http://esa-matti.suuronen.org/blog/2012/04/19/slimux-tmux-plugin-for-vim/
Other
217 stars 52 forks source link

Calling nmap :SlimuxREPLSendLine changes cursor position. #42

Closed yzhuang closed 9 years ago

yzhuang commented 9 years ago

E.g. I have the following mapping nmap j :SlimuxREPLSendLine

After sending a line to a tmux pane, the cursor is placed to the beginning of that line. A lot of the time, I send line to tmux in insert mode using "j", and it is very inconvenient that the cursor position changes after that.

Would be nice if SlimuxREPLSendLine can be change to not change cursor position.

dvbuntu commented 9 years ago

I took a look at this using echo getpos("."). I thought that it would be pretty straightforward to save off the cursor position to a variable, do whatever changes the position, and then setpos(".",foo), but it's tough to find where the position is initially correct (i.e. it seems reset very early in the process).

dvbuntu commented 9 years ago

Ok, so I can fix this, but it's dirty and I don't like it.

command! -range -bar -nargs=0 SlimuxREPLSendLine let cur_pos=getpos(".")|<line1>,<line2>call s:SlimeSendRange()|call setpos(".",cur_pos)

At least, this works after setting the the target pane the first time. I suspect that's also resetting the cursor position.

But this seems like a gross way to fix the problem. I'm not an expert with vimscript, so I don't know why the cursor position is already reset to the beginning of the line once you go into the SlimeSendRange function.

One alternative would be to pass the cursor position into these functions. That really seems like mixing functionality, though, so I'm not a big fan of that. I haven't poked at wrapping functions, but maybe that could work?

sunaku commented 9 years ago

Try setting a mark (z) and jumping back to it:

nnoremap j mz:SlimuxREPLSendLine<CR>`z
yzhuang commented 9 years ago

Yup, saving cursor position into z and restoring afterwards seems to be a simple workaround.

I am using the below settings now, and it works as expected after setting the target pane:

    nmap <Leader>n mz:SlimuxREPLSendLine<CR>`z
    vmap <Leader>n :SlimuxREPLSendSelection<CR>
    nmap <Leader>N :SlimuxREPLConfigure<CR>

    # I configured iterm2 to send 🀄 when Cmd+N is pressed
    imap 🀄  <Esc>mz:SlimuxREPLSendLine<CR>`za
    nmap 🀄  mz:SlimuxREPLSendLine<CR>`z
    vmap 🀄  :SlimuxREPLSendSelection<CR>

Thanks!

dvbuntu commented 9 years ago

Setting a mark will work, but it also clobbers that mark. So if you ever use the mark z, you'll lose it after doing a SlimuxREPLSendLine. Probably not a big deal for your specific usage, but it'd be nice to not twiddle that.

yzhuang commented 9 years ago

Setting a mark will work, but it also clobbers that mark.

Yup, Agree.

I usually use marks a,s,d,f, and rarely need more marks. I guess z is one of the least likely mark I would use. In practice, I think this works fine; as a general solution, this is probably not very clean.