Fork me on GitHub
#vim
<
2022-08-06
>
Chase15:08:47

In nvim, how would I create a keybinding for only when I'm in the built in terminal and in normal mode (so not able to write text in the terminal prompt.) I'm trying to do something like this: tnoremap <leader>r iclj -M:repl<CR> but that only works when I'm in insert mode (so then having to take out the i part ofc). I don't want that though as it then pauses every time I hit my leader key. I only want it to work when in normal mode.

Martynas Maciulevičius19:08:54

:echo &filetype
I don't know what filetype is associated with terminal as it doesn't return anything. But this is a starting point. Then use this (replace clojure with what you get from the first cmd)
autocmd FileType clojure nnoremap <silent> <localleader>e1 :YourFn<CR>
P.S. I don't have Lua config and I have similar commands added to my nvim's init.vim

Chase15:08:32

With the help of the neovim gitter, here is how you accomplish it:

augroup terminal_normal_keybinds | au!
    autocmd TermOpen * nnoremap <buffer> <leader>r iclj -M:repl<cr>
augroup END
So I guess TermOpen is the "filetype". I don't think the 1st and 3rd lines are strictly necessary but I assume that's just a way to organize similar commands?

Martynas Maciulevičius16:08:04

No, TermOpen is the same as FileType so it's a completely different matcher.

Chase17:08:36

Ahh, got it. Anyways, it works!

Martynas Maciulevičius19:08:04

Wow. This is the command mode command editing that I wanted to have but didn't know it already existed....... 😮 https://stackoverflow.com/a/7189573

❤️ 4
sheluchin19:08:26

Yes, it's pretty handy. You can use it with Telescope and fzf.vim as well, so you get a fuzzy matcher over your history to find what you're looking for and then simple editing of your selection, if you need it. I've had this idea to use Telescope or fzf.vim to read your $HISTFILE, allow the same fuzzy search+editing behaviour, and then send it to the built-in nvim terminal using Neoterm. I'm kinda surprised I don't see an existing Telescope extension for that.

Martynas Maciulevičius19:08:16

Yes but for me it's not about the history but about the editing of the command that I type. So for example I could be renaming a variable and then press Ctrl+f. And then I can use normal mode. This is sooo good.