This started as a different problem which seemingly got resolved by its own, but also unveiled what appears to be a more persisting minor bug.
So the below doesn't really matter but I kept it for context or in case it goes wrong gain...
Initial issue, which got resolved
**Describe the issue:**
Cursor position added with ` (VM-Add-Cursor-At-Pos)` is off by one character.
https://github.com/user-attachments/assets/d577b2b6-95f9-482b-aecc-fc3badc21a3f
**Steps to reproduce**
1. Use `(VM-Add-Cursor-At-Pos) `
**Fix**
`\\\` Accurately adds cursor, so a simple custom rebind to that would probably be fine but just thought I'd point this one out. I'll try rebinding with an alternative method, but I kinda liked Plug cause it's simple to understand ahah
```lua
-- this will work
vim.keymap.set("n", "", "(VM-Add-Cursor-Down)", { noremap = true, silent = true })
vim.keymap.set("n", "", "(VM-Add-Cursor-Up)", { noremap = true, silent = true })
-- btw these^ are ever so slightly buggy, they might add an empty new line on the first use in a session.
-- Adding cursors, first cursor is added with [I]nitial key as to pause the keymap to navigate better.
vim.keymap.set("n", "C", "\\\\\\", { noremap = false, silent = true })
vim.keymap.set("n", "T", "\\\\", { noremap = false, silent = true })
vim.keymap.set("n", "I", "\\\\\\\\\\", { noremap = false, silent = true })
```
-----
- **Operating System**: Windows 11
- **Vim Version**: 0.10.1
- **commit SHA/branch**: 38b0e8d
EDIT : looks like a difficult keybind plugin, from reading other posts ... and, well, the code I showed as my fix just stopped working... It was completely fine, did not touch anything, doesn't work anymore 🤷
EDIT2: I am experiencing new behavior again where my initial example in the video seems to be working as intented, partially... will update.
EDIT3: So after going through the five stages of grief... It seems a stable solution has been found.
1. Initially, the of by one error was called whenever I called `(VM-Add-Cursor-At-Pos)`
2. Then remapping to the plugins defaults with some custom binds worked.
3. Then that stopped working with no changes.
4. Then calling `(VM-Add-Cursor-At-Pos)` seemed to not cause an off by one error, but calling ` (VM-Add-Cursor-At-Pos)(VM-Toggle-Mappings) ` in immediate succesion from one keybind did.
5. However, calling two keybinds which each trigger one of those actions in immediate succesion, will work, but will also trigger a displacement of the "live" cursor by 2 characters to the right after placing the "plugin" cursor.
6. ---> Actually, this is only true when using leader keys for the plug, which might maybe be because my leader is space.
7. Finally, the first keybind issued with `` will usually create a new emtpy new line on the first use of the session, if no additional cursor were spawned beforehand. This is true with `M-k` and `M-j` but also `m-t` or `m-b` etc.. so this is not related to being `j` or `k` and some up/down line interaction, I guess...
Therefore my (currently) working implementaion will be:
```lua
-- First cursor is added with [I]nitial key as to pause the keymap to navigate better.
-- avoid displacement issues by using I and not as initial bind
vim.api.nvim_set_keymap("n", "I", "", { noremap = false, silent = true })
-- Dropoff cursor at current position
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-At-Pos)", { noremap = true, silent = true })
-- Toggle cursors shifting with HJKL
vim.api.nvim_set_keymap("n", "", "(VM-Toggle-Mappings)", { noremap = true, silent = true })
-- Add cursors up/down
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-Up)", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-Down)", { noremap = true, silent = true })
```
Anyways, I'm very sorry for anybody who read all that... but the only surely garanteed bug that was detected here is that the first keybind issued with `M-m` to add a cursor, will add an empty newline.
TLDR
Actual current issue:
When no cursor was previously added, spawning a new cursor with a keybind involving M (as in alt, or option) will create an emtpy new line.
This started as a different problem which seemingly got resolved by its own, but also unveiled what appears to be a more persisting minor bug.
So the below doesn't really matter but I kept it for context or in case it goes wrong gain...
Initial issue, which got resolved
**Describe the issue:** Cursor position added with `(VM-Add-Cursor-At-Pos)` is off by one character.
https://github.com/user-attachments/assets/d577b2b6-95f9-482b-aecc-fc3badc21a3f
**Steps to reproduce**
1. Use `(VM-Add-Cursor-At-Pos) `
**Fix**
`\\\` Accurately adds cursor, so a simple custom rebind to that would probably be fine but just thought I'd point this one out. I'll try rebinding with an alternative method, but I kinda liked Plug cause it's simple to understand ahah
```lua
-- this will work
vim.keymap.set("n", "", "(VM-Add-Cursor-Down)", { noremap = true, silent = true })
vim.keymap.set("n", "", "(VM-Add-Cursor-Up)", { noremap = true, silent = true })
-- btw these^ are ever so slightly buggy, they might add an empty new line on the first use in a session.
-- Adding cursors, first cursor is added with [I]nitial key as to pause the keymap to navigate better.
vim.keymap.set("n", "C", "\\\\\\", { noremap = false, silent = true })
vim.keymap.set("n", "T", "\\\\", { noremap = false, silent = true })
vim.keymap.set("n", "I", "\\\\\\\\\\", { noremap = false, silent = true })
```
-----
- **Operating System**: Windows 11
- **Vim Version**: 0.10.1
- **commit SHA/branch**: 38b0e8d
EDIT : looks like a difficult keybind plugin, from reading other posts ... and, well, the code I showed as my fix just stopped working... It was completely fine, did not touch anything, doesn't work anymore 🤷
EDIT2: I am experiencing new behavior again where my initial example in the video seems to be working as intented, partially... will update.
EDIT3: So after going through the five stages of grief... It seems a stable solution has been found.
1. Initially, the of by one error was called whenever I called `(VM-Add-Cursor-At-Pos)`
2. Then remapping to the plugins defaults with some custom binds worked.
3. Then that stopped working with no changes.
4. Then calling `(VM-Add-Cursor-At-Pos)` seemed to not cause an off by one error, but calling ` (VM-Add-Cursor-At-Pos)(VM-Toggle-Mappings) ` in immediate succesion from one keybind did.
5. However, calling two keybinds which each trigger one of those actions in immediate succesion, will work, but will also trigger a displacement of the "live" cursor by 2 characters to the right after placing the "plugin" cursor.
6. ---> Actually, this is only true when using leader keys for the plug, which might maybe be because my leader is space.
7. Finally, the first keybind issued with `` will usually create a new emtpy new line on the first use of the session, if no additional cursor were spawned beforehand. This is true with `M-k` and `M-j` but also `m-t` or `m-b` etc.. so this is not related to being `j` or `k` and some up/down line interaction, I guess...
Therefore my (currently) working implementaion will be:
```lua
-- First cursor is added with [I]nitial key as to pause the keymap to navigate better.
-- avoid displacement issues by using I and not as initial bind
vim.api.nvim_set_keymap("n", "I", "", { noremap = false, silent = true })
-- Dropoff cursor at current position
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-At-Pos)", { noremap = true, silent = true })
-- Toggle cursors shifting with HJKL
vim.api.nvim_set_keymap("n", "", "(VM-Toggle-Mappings)", { noremap = true, silent = true })
-- Add cursors up/down
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-Up)", { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", "", "(VM-Add-Cursor-Down)", { noremap = true, silent = true })
```
Anyways, I'm very sorry for anybody who read all that... but the only surely garanteed bug that was detected here is that the first keybind issued with `M-m` to add a cursor, will add an empty newline.
TLDR
Actual current issue:
When no cursor was previously added, spawning a new cursor with a keybind involving
M
(as inalt
, oroption
) will create an emtpy new line.video:
https://github.com/user-attachments/assets/3bd7b042-3775-4929-9738-51eee3bef58f
EDIT: noticed it happens with C-n initiation too.