Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim - Send tab keystroke in keymapping

Tags:

vim

tabs

My end goal is trying to make directory navigation in Vim easier, preferably without a plugin.

What I have so for in my .vimrc:

nmap <m-up> :cd ..<enter>:pwd<enter>
nmap <m-left> :cd -<enter>:pwd<enter>
nmap <m-down> :cd <tab>

The first two commands work great. I can easily go up/back a directory. The intention of the third command is to quickly get to a set of options that I can tab/arrow-key through to the desired subdirectory. However, the result is:

:cd ^I

i.e. it's putting in a tab/ctrl-I char instead of simulating the tab key press, which is the result I want. I have other commands that use <esc> ,backspace etc and they all work as desired, but <tab> is different. Any suggestions (besides just hitting tab after my macro)?

like image 310
Reaverer Avatar asked Mar 09 '23 04:03

Reaverer


2 Answers

You need to set the wildcharm option for that:

set wildcharm=<C-z>
nnoremap <m-down> :cd <C-z>

See :help wildcharm.

like image 135
romainl Avatar answered Mar 15 '23 00:03

romainl


I think it can't "Tab" as you expect it to, because it is interpreting it as part of the vim command, rather than an input for the (bash?) shell. My guess would be to map it to something along the lines of this, if you want to see what is in the working directory:

nnoremap <m-down> :!pwd

The no in nnoremap is to prevent any mapping from happening in the reverse direction, kind of a habit that you might want to get into. This will display what is currently in the directory.

like image 29
Gleland Avatar answered Mar 15 '23 01:03

Gleland