VIM: disabling the cursor/arrow keys, but only for navigation
VimVim Problem Overview
inoremap
This is what I use to disable cursor navigation, to help me stick to hjkl :)
But it also disables the cursor on the command bar... normally the arrow keys let you cycle through the history
Is it possible to disable the cursor keys ONLY for navigation, and not for the history?
Vim Solutions
Solution 1 - Vim
Add the following in your .vimrc
file:
" Disable Arrow keys in Normal mode
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
" Disable Arrow keys in Insert mode
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
Solution 2 - Vim
You can cycle through the history using C-n
and C-p
(Ctrl+n and Ctrl+p, respectively).
Solution 3 - Vim
The code you have posted should not disable history navigation in command line mode, are you sure you don't have cnoremap <Up> <Nop>
or noremap! <Up> <Nop>
somewhere? Try verbose cmap <Up>
it should show you whether <Up>
key is redefined for command line mode.
If when saying «command bar» you meant command-line window, you could try the following:
nnoremap <expr> <Up> ((bufname("%") is# "[Command Line]")?("\<Up>"):(""))
Solution 4 - Vim
For me, this works:
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
Taken from: https://github.com/garybernhardt/dotfiles/blob/master/.vimrc#L148
Solution 5 - Vim
Use q:
to open a split window of your command line. You can navigate within it normally, as it's a regular vim window using hjkl
and the other usual vim motions, and hit enter to run the command under cursor.
Don't use the arrow keys to navigate in the command line history.
Incidentally, you can also access your search history using q/
or q?
.
Solution 6 - Vim
You may also consider remapping them to move between the split windows. This disables the arrow keys for directional movement inside the file but lets you move between the split windows.
noremap <up> <C-w><up>
noremap <down> <C-w><down>
noremap <left> <C-w><left>
noremap <right> <C-w><right>
Solution 7 - Vim
Change noremap
to nnoremap
to apply the mappings to normal mode, otherwise they're global all-modes mappings.