1

I'm not a big fan of the command line readline keyboard shortcuts so I'm hoping to remap C-Right/C-Left to navigate one word back/forward and C-BS and C-Del to delete one word back/forward. However, after reading the documentation and forumns, I'm not able to figure out how to do this.

Currently, when C-left/C-right are typed in the command line, the cursor doesn't move and instead keycodes are inserted (C-left = [1;5D, C-right = [1;5C). I've tried many remappings but the mappings that I would think would work best for this are:

cmap <C-right> <A-f>
cmap <C-left> <A-b>

I was able to figure out how to delete one word back using the following mappings (on further review there is documentation in the VIFM manual regarding mapping BS):

cnoremap <BS> <C-w>
cnoremap <C-h> <C-w>

However, I'm still uncertain on how to map delete one word forward using C-Del. When I use the following remapping for C-Del, the result is that one character to the left of the cursor is deleted. Note, when I use other C-* combinations for delete word forward the remappings actually works making me think that it may not be possible to remap C-Del:

cmap <C-Del> <A-d>

I'm using VIFM version 0.12 on Arch Linux. Any suggestions?

Kevin Duff
  • 27
  • 4

1 Answers1

1

List of keys that are supported by angle-bracket notation is available in the documentation. And combinations of Ctrl with arrow keys are not there.

See this GitHub issue for a discussion of why and an example of how to work around it:

" ctrl-right
cnoremap <esc>[1;5C <a-f>
" ctrl-left
cnoremap <esc>[1;5D <a-b>
" ctrl-del
cnoremap <esc>[3;5~ <a-d>

At this point I'm still not sure that these sequences are common enough among different terminal types to be hard-coded and not cause trouble.

xaizek
  • 5,098
  • 1
  • 34
  • 60
  • Thanks for your reply! I wasn't able to originally find this post. Happy that you were able to point me in the right direction. :) I was able to figure out C-BS mappings to delete one word backward (I updated my original post), however, I'm still uncertain on how to delete one word forward with C-Del. I've marked your post as not answered because the explanation was only a partial answer (still wondering about delete one word forward). Thanks for your input! – Kevin Duff Mar 07 '22 at 22:27
  • 1
    @KevinDuff I think Alt+D is what you're looking for, updated answer with it. – xaizek Mar 07 '22 at 23:51
  • Thanks for taking the time to reply. This actually still isn't working on my setup. Not sure why, however, I'm having similar issues remapping c-del in other terminal programs (e.g. nvim) so thinking this is an issue on my side rather than with VIFM. I'll mark your answer correct assuming this solution will work for most individuals looking for similar remappings. – Kevin Duff Mar 08 '22 at 01:59
  • 1
    @KevinDuff Type Ctrl+V Ctrl+Del in a shell or Vim's command-line mode to see sequence for your terminal. – xaizek Mar 08 '22 at 10:41
  • Thanks again for your help! Don't know if I have something going on in one of my configs somewhere but this still isn't working. When I type C-v followed by C-Del what reurns is . This is also what is returned when I type C-v followed by BS. So it seems that C-Del and BS are both mapped to the same sequence? I tried remapping BS to A-d but, as expected this changes the behavior of both BS and C-Del to delete one word forward. Not sure if you have any other suggestions? Maybe I need to do some remappings in .initrc (currently I don't have an .initrc). – Kevin Duff Mar 09 '22 at 23:10
  • This post was intersting showing the complexity of the enter/return and backspace/delete keys: [Keyboard Enter/Return and Backspace/Delete](https://gist.github.com/CMCDragonkai/e45d062aad3be6a3be26da76694fdfbf) – Kevin Duff Mar 09 '22 at 23:13
  • 1
    @KevinDuff It is a nice post. Results in such tests are likely to depend on the teminal emulator that you're using and the value of `$TERM` (if you're using a terminal multiplexer then there are two values of `$TERM` (inside and outside of the multiplexer) and both should be correct). – xaizek Mar 12 '22 at 10:03