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

Allow setting of keybindings for moving between visual lines in soft wrapped mode. #24

Open
FruityCat opened this issue Dec 29, 2022 · 3 comments

Comments

@FruityCat
Copy link

Current Behaviour:
My current understanding is that when you set soft-wrapped mode, the keybindings for moving up and down lines (j, k) and moving between visual lines (gj, gk) are swapped so that (j, k) do visual lines and visa versa.

This doesn't work for if a user has rebound the H, J, K, L keybindings.

I use colemak for example, and these rebindings don't take place (or I'm somehow fundamentally misunderstanding that part of the plugin) because my movement keys are now on M, N, E, I.

Desired Behaviour:
I'd like it to default to switching (j, k) and (gj, gk) as normal, but allow an option in the settings for the plugin to say that I'd like my up and down keys in visual mode to be (n, e) instead of (j, k).

opts = {
    visual_line_up = "e",
    visual_line_down = "i".
}

use({
    "andrewferrier/wrapping.nvim",
    config = function()
        require("wrapping").setup(opts)
    end,
})

Then when enabling soft-mode wrapping those would be the bindings for moving visual lines and when disabling soft-mode wrapping, it would revert to what the bindings were before.

@andrewferrier
Copy link
Owner

@NiamhFerns thanks for your feedback. So that's not quite right - currently wrapping.nvim does not touch the alphabetic movement keys at all, it simply remaps the <Up> and <Down> arrow keys. Perhaps it should (?), but it doesn't.

I'm not sure of the best practices for using Colemak with Vim/NeoVim, so happy to take some advice on that, but I don't think wrapping.nvim should get involved in that since it doesn't currently remap alphabetic keys at all.

Also, I'm not sure I 100% understand your reference to visual mode? wrapping.nvim doesn't really have anything explicitly to do with visual mode. Do you maybe mean soft mode? Perhaps I don't understand what you're asking for.

@FruityCat
Copy link
Author

That makes sense. If it just remaps the up down keys then that doesn't really need to be corrected for colemak (or any keyboard for that matter).

As for whether it should rebind movement keys, it's something that would be nice but probably not worth the additional effort to add if it's not something that was already implemented.

The visual mode reference was just a clumsy description of the lines on screen. Actual lines being the lines that are created by including a newline character and 'visual' lines being the lines you can see on your screen.

1. # This is a heading
2. 
3. te ian ini enari i ie ni n iaresn n iten inaer i in iarns ne nairest n 
    ie i enair i earnisen nntieari isi airste earnst e narni seti earsitea
    airestna nan erntnanriestenn iear.

So the above would be 3 actual lines but 5 visual lines.

For now I just have a function to toggle soft-wrap and then rebind the keys appropriately. That works for me for now.

function SetWrapped()
    vim.cmd([[
        set wrap
        set linebreak
    ]])
    keymap("n", "n", "gj", noremap)
    keymap("n", "e", "gk", noremap)
    vim.opt.number = false
    vim.opt.rnu = false
end

function UnsetWrapped()
    vim.cmd([[
        set nowrap
    ]])
    keymap("n", "n", "j", noremap)
    keymap("n", "e", "k", noremap)
    vim.opt.number = true
    vim.opt.rnu = true
end

I'm happy to close for now and if someone else wants have this functionality as well they can reopen.

@andrewferrier
Copy link
Owner

andrewferrier commented Jan 1, 2023

@NiamhFerns I'm actually going to re-open this, as I think there are actually several useful capabilities you've highlighted which I could potentially add to wrapping.nvim:

  • The ability to remap (or not) the j, k keys (or Colemak equivalent) in soft wrap mode (probably true by default).
  • The ability to remap (or not) the gj, gk keys (or equiv.) in hard wrap mode (probably false by default).
  • The ability to support other keyboard layouts such as Colemak.
  • The ability to add user events such that other tasks (such as I note you like turning off/on number) can be easily supported - this is already covered by Provide plugin points for when hard/soft flip happens #9.

Incidentally, for your awareness, I think Vim calls what you are calling 'actual lines' just 'lines' and what you are calling 'visual lines' display lines. See :help gj.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants