Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Create keymap to open new file adjacent to current file #92

Closed
justb3a opened this issue Jan 14, 2022 · 6 comments
Closed

Create keymap to open new file adjacent to current file #92

justb3a opened this issue Jan 14, 2022 · 6 comments

Comments

@justb3a
Copy link

justb3a commented Jan 14, 2022

Hi,

I'm struggeling a while now with this and tried serveral solutions. My goal is to use the edit command with the path of the currently edited file filled in:

nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <CR>
vim.api.nvim_set_keymap('n', '<leader>e', '<cmd>e ???<cr>', {silent = true, noremap = true})

Using it directly just works as expected.

I tried to wrap <C-R> in the termcodes function and several other ways, but none of them worked. Maybe there is even a better way to solve this with lua. Any help is appreciated 🙏🏻

@nanotee
Copy link
Owner

nanotee commented Jan 14, 2022

Hi,

Try replacing <Cmd> with a :. <Cmd> executes the command directly without changing modes which is why <C-R> doesn't work.

(As a sidenote, questions like these are more likely to get an answer on dedicated support forums like the Neovim Discourse)

@justb3a
Copy link
Author

justb3a commented Jan 14, 2022

Tried this as well, didn't work at first glance. Now I tried it again, I was waiting for the path being shown so that I could extend it. Now I discovered that only if you type something, the path will appear and then it works. Thanks.

(Thanks for the sidenote link ;) )

@gegoune
Copy link

gegoune commented Jan 14, 2022

You shouldn't have to type anything apart of the keymap itself. I suspect you have another keymap for <leader>e<something> and nvim waits for more input. Try: :nmap <leader>e to see what mappings you have set up.

@nanotee
Copy link
Owner

nanotee commented Jan 14, 2022

Now I discovered that only if you type something, the path will appear and then it works.

Does removing silent = true fix it?

@clason
Copy link

clason commented Jan 14, 2022

PSA: There's a full Lua API now (vim.keymap.*), so I'd probably focus on just that now.

@justb3a
Copy link
Author

justb3a commented Jan 17, 2022

I use a custom keymap function, silent = true was set by default 🤦🏻‍♀️. Thanks for your help! 🚀

@justb3a justb3a closed this as completed Jan 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants