kevinhwang91 / rnvimr

Make Ranger running in a floating window to communicate with Neovim via RPC
BSD 3-Clause "New" or "Revised" License
804 stars 17 forks source link

Custom Filetype for ranger buffer #66

Closed Chaitanyabsprip closed 3 years ago

Chaitanyabsprip commented 3 years ago

Is your feature request related to a problem? Please describe. I have jk and kj bound to escape into normal mode for terminal mode and insert mode. As Ranger works in terminal mode this adds a delay when I am browsing files.

Describe the solution you'd like If the terminal buffer in which ranger is working will have a custom filetype or some indentification it will be easy to make custom and conditional key bindings for ranger in nvim.

kevinhwang91 commented 3 years ago

After creating the ranger buffer, rnvimr will set ft=rnvimr, I think you can remap key for the escape key for terminal mode.

Chaitanyabsprip commented 3 years ago
autocmd Filetype rnvimr inoremap jk <nop>
autocmd Filetype rnvimr inoremap kj <nop>
autocmd Filetype rnvimr tnoremap jk <nop>
autocmd Filetype rnvimr tnoremap kj <nop>

these commands should work but aren't.

kevinhwang91 commented 3 years ago
autocmd Filetype rnvimr tnoremap <buffer><nowait> j j
autocmd Filetype rnvimr tnoremap <buffer><nowait> k k
Chaitanyabsprip commented 3 years ago

@kevinhwang91 I tried the mappings you suggested and those are not working as required. It doesn't seem to be doing anything, I get an error message saying the mapping doesn't exist

kevinhwang91 commented 3 years ago

What does :tmap say in rnvimr? Before pressing :tmap, make sure that you are at normal mode in rnvimr buffer.

Chaitanyabsprip commented 3 years ago
t  jk          * <C-\><C-N>
t  kj          * <C-\><C-N>
t  <M-o>       * <C-\><C-N>:RnvimrToggle<CR>
t  <M-i>       * <C-\><C-N>:RnvimrResize<CR>
t  <M-[>       * <C-\><C-N>
kevinhwang91 commented 3 years ago
autocmd Filetype rnvimr tnoremap <buffer><nowait> j j
autocmd Filetype rnvimr tnoremap <buffer><nowait> k k

The above snippet work for me, please add it into your init.vim. Or run them before ranger started.

Chaitanyabsprip commented 3 years ago
vim.api.nvim_set_keymap('t', 'jk', '<c-\\><c-n>', {noremap=true, silent=true})
vim.api.nvim_set_keymap('t', 'kj', '<c-\\><c-n>', {noremap=true, silent=true})

This is how I've set the keymap

augroup ranger
    autocmd! Filetype rnvimr tnoremap <buffer><nowait> j j
    autocmd! Filetype rnvimr tnoremap <buffer><nowait> k k
augroup end

and this is how I used your snippet and it is not working, when I open ranger an error message pops saying Error detected while processing FileType Autocommands for "rnvimr": E31: No such mapping

kevinhwang91 commented 3 years ago
augroup ranger
    au!
    autocmd Filetype rnvimr tnoremap <buffer><nowait> j j
    autocmd Filetype rnvimr tnoremap <buffer><nowait> k k
augroup end
Chaitanyabsprip commented 3 years ago

works now, thank you.