2

I want to disable my VIM-arrows in VIM, to get used to move the cursor using hjkl. I have tried a lot of different approaches found on this forum, however, i can't seem to disable the up and down buttons in 'Insert Mode'.

Heres my .vimrc:

set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line


" Removes preview window in YCM.
set completeopt-=preview

" Set clipboard to system clipboard
set clipboard=unnamedplus

" Enable pathogen
execute pathogen#infect()

" F# syntax on .fsi files. (.fsx and .fs are supported automaticly by plugin)
autocmd BufNewFile,BufRead *.fsi set syntax=fsharp

" Set numbers on side.
" 
set number

" Disables arrow keys.
" Remove newbie crutches in Command Mode
cnoremap <Down> <Nop>
cnoremap <Left> <Nop>
cnoremap <Right> <Nop>
cnoremap <Up> <Nop>

" Disable Arrow keys in Insert mode
inoremap <Up> <Nop>
inoremap <Down> <Nop>
inoremap <Left> <Nop>
inoremap <Right> <Nop>
" Remove newbie crutches in Normal Mode
nnoremap <Down> <Nop>
nnoremap <Left> <Nop>
nnoremap <Right> <Nop>
nnoremap <Up> <Nop>

" Remove newbie crutches in Visual Mode
vnoremap <Down> <Nop>
vnoremap <Left> <Nop>
vnoremap <Right> <Nop>
vnoremap <Up> <Nop>

Arrow remapping is found in the bottom of .vimrc. Alongside inoremap, i have tried imap and this solution:

 noremap  <Up> ""
 noremap! <Up> <Esc>
 noremap  <Down> ""
 noremap! <Down> <Esc>
 noremap  <Left> ""
 noremap! <Left> <Esc>
 noremap  <Right> ""
 noremap! <Right> <Esc>

Found on https://stackoverflow.com/questions/23548932/how-do-i-disable-the-arrow-keys-in-insert-mode.

Rn everything but Up and Down in 'Insert mode' is disabled.

Keyboard layout: Danish, Ubuntu 18.04 Vim: 8.0.1453

  • What's the output of :verbose imap <Up> after you open Vim? – Rich Sep 26 at 13:29
  • Copy pasted: <Up> * pumvisible() ? "\<C-P>" : "\<Up>" Last set from ~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim As far as i understand, YCM (autocompleter) is mapping <Up> after I'm calling noremap <Up> in .vimrc? – Oliver Bak Sep 26 at 13:33
2

As discussed in the comments, YouCompleteMe is overwriting your mapping with its own.

Normally, you can overwrite a setting that a plugin has made by using the .vim/after directory but in this instance, YouCompleteMe is actually creating the mapping even later on, via an autoload function.

You might like to check the YouCompleteMe documentation to see if it's possible to stop it doing so. At a guess, it's the g:ycm_key_list_select_completion and g:ycm_key_list_previous_completion options you'll need to change.

Otherwise, you could try recreating your mappings whenever you enter insert mode:

augroup SeriouslyNoInsertArrows
  autocmd!
  autocmd InsertEnter * inoremap <Up> <nop>
  autocmd InsertEnter * inoremap <Down> <nop>
augroup END

Or, if you want to continue using the arrows in YCM's autocomplete menus, you might prefer something like (untested):

augroup SeriouslyNoInsertArrows
  autocmd!
  autocmd InsertEnter * inoremap <expr> <Up> pumvisible() ? "\<C-P>" : ""
  autocmd InsertEnter * inoremap <expr> <Down> pumvisible() ? "\<C-N>" : ""
augroup END
  • This script (1st) works flawlessly! I will test 2nd script in a minute, thanks a lot for your help! – Oliver Bak Sep 26 at 14:02
  • I modified second Script to include: autocmd InsertEnter * inoremap <expr> <Down> pumvisible() ? "\<C-N>" : "". It worked! – Oliver Bak Sep 26 at 14:08
  • @OliverBak Glad I could help! I updated the answer to correct the oversight. – Rich Sep 26 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.