Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore cursor position also with SlimeRegionSend #354

Open
fredrikekre opened this issue Dec 20, 2022 · 6 comments
Open

Restore cursor position also with SlimeRegionSend #354

fredrikekre opened this issue Dec 20, 2022 · 6 comments

Comments

@fredrikekre
Copy link

When using vim-slime to execute script-like code I often select large portion of the code in visual mode and sending that with SlimeRegionSend. However, when back in normal mode my cursor ends up at the beginning of the previous visual block and I have to navigate down again to wherever I stopped before sending the block. It would be very convenient if the option slime_preserve_curpos also applied for SlimeRegionSend. Thanks!

@jpalardy
Copy link
Owner

Hi @fredrikekre

You can check the issues and pull requests … similar ideas have been proposed (for example)

If that's not what you meant, we can discuss alternatives.

If you have an example of the behavior you would be prefer, send me

  • a text sample
  • where the cursor started
  • what binding was invoked
  • where the cursor ended up

Thanks

@fredrikekre
Copy link
Author

fredrikekre commented Dec 22, 2022

Thanks for the reference, I don't know why I didn't find that in my search.

The suggestion in #353 (comment) is pretty close to what I had in mind, although that is annoying if you select your visual block "backwards", e.g. moving up.

What I had in mind is to have the cursor "stay", meaning that I would like the cursor to end up at the same position after SendRegion as it does when simply Escaping the same visual mode selection. I hope this explanation make sense, I can construct a concrete example if not.

When selecting multiple paragraphs, perhaps even multiple screen-sizes, to send it is IMO pretty disorienting when the file scrolls back to the beginning of the region and you have to navigate back down again. This is what I expected slime_preserve_curpos to mean when I found that option, and it is already how it SendParagraph works with that option.

@jpalardy
Copy link
Owner

Tricky…

One possible workaround, use o (:help v_o) to toggle the cursor position before sending the region (esp. in the case of selecting backwards). And then using '> ?

I don't think that covers all your use cases though 🤔

  • if you select down, '> will take you back to the bottom of the selection
  • if you select up, the cursor lands at the top (where you were?)

ctrl-o can also help

...

if that doesn't work, send me an example — maybe I still don't understand the before-and-after

@clpan
Copy link

clpan commented Mar 10, 2023

Hi! I have a little workaround that moves cursor to the line below the visual block. You can easily modify it to make the cursor stays at the last line of your visual block. This works for backward selecting as well.

vnoremap <silent> <C-A-CR> :<C-u>silent execute("'<,'>SlimeSend") \| let lnum=line("'>") \| execute("silent normal! " . (lnum+1) . "G")<CR>

or use <Plug>SlimeRegionSend still

vnoremap <silent> <C-A-CR> :<C-u>silent execute("normal! \<Plug>SlimeRegionSend") \| let lnum=line("'>") \| execute("silent normal! " . (lnum+1) . "G")<CR>

@stale
Copy link

stale bot commented May 21, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label May 21, 2023
@fredrikekre
Copy link
Author

Was reminded of this issue and I just wanted to post my solution for this problem in Neovim in case someone is curious:

local function slime_send_region()
    local keys = ":<C-u>call slime#send_op(visualmode(), 1)<CR>"
    local mode = "x"
    vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(keys, true, true, true), mode, true)
    return
end

vim.keymap.set(
    "x", "<S-CR>",
    function()
        local loc = vim.api.nvim_win_get_cursor(0)
        slime_send_region()
        vim.api.nvim_win_set_cursor(0, loc)
    end
)

@stale stale bot removed the wontfix label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants