Closed bavo96 closed 1 year ago
Not sure I understand the question. Are you looking for a loop that sets BufferGoto instead of repeating the mapping 10 times?
Yeah I think I need a loop to set or maybe is there any way to help me do like vim.keymap.set('n', '<leader>num', '<Cmd>BufferGoto num<CR>', opts)
according to user's number. Just like we hit 10G
and it goes to line 10 :D In case I have to open like 20 files and I need to enter <Space>20
to go to file 20.
I'd recommend using a for loop and setting the end index to the number of buffers you want to support. You can use string.format('<cmd>BufferGoto %i<CR>, i)
to generate the mapping command.
Yeah I think I need a loop to set or maybe is there any way to help me do like
vim.keymap.set('n', '<leader>num', '<Cmd>BufferGoto num<CR>', opts)
according to user's number. Just like we hit10G
and it goes to line 10 :D In case I have to open like 20 files and I need to enter<Space>20
to go to file 20.
You can use vim.v.count
instead of doing it manually. When doing 50gg
, vim.v.count
is 50
. Something like:
vim.keymap.set('n', 'YOUR MAPPING', function()
vim.cmd.BufferGoto(vim.v.count) -- or `vim.api.nvim_command('BufferGoto ' .. vim.v.count)`
end)
I've tried both solutions and it seems like @Iron-E 'solution got a delay (about 2 secs) when switching to another buffer. @romgrk 's solution brings me to another buffer like immediately (don't know why). Besides, it makes me feel normal when I press <Space>number
so i'll stick with the for loop. Thank you guys <3
I want to move around buffers using its index. Right now I have to setup keymaps as below image:
Is there any oneline code that helps me not to set the keymaps manually for buffer index ? (like moving from 1 to n buffer).