Adam Incera
Adam Incera

Reputation: 117

Moving right twice in vim?

I'm trying to get into Vim and remapping keys and whatnot, and I've stumbled across a weird issue. I've remapped hjkl to jkl; because that's more intuitive to me, but now whenever I press ; it moves to the right twice. Not sure I really mind it, since it counteracts the fact that my pinkie is weaker than the rest of my fingers, but if a Vim ninja wouldn't mind reading through this, I'd really like to know why this happens.

Here's my .vimrc (the bottom portion, marked Jae's Vim settings, is excerpted from one of my professor's vim settings):

" jj => esc
:imap jj <Esc>

"remap navigation keys

:nnoremap ; l 
:nnoremap l k
:nnoremap k j
:nnoremap j h

" highlight search
set hlsearch

"left-to-right wrapping
set whichwrap+=<,>,h,l,[,]

"Jae's Vim settings
"

" Line numbers
set number

" Syntax
syntax on
execute pathogen#infect()
filetype plugin indent on

" Buffer switching using Cmd-arrows in Mac and Alt-arrows in Linux
:nnoremap <D-Right> :bnext<CR>
:nnoremap <M-Right> :bnext<CR>
:nnoremap <D-Left> :bprevious<CR>
:nnoremap <M-Left> :bprevious<CR>
" and don't let MacVim remap them
if has("gui_macvim")
   let macvim_skip_cmd_opt_movement = 1
endif

" When coding, auto-indent by 4 spaces, just like in K&R
" Note that this does NOT change tab into 4 spaces
" You can do that with "set tabstop=4", which is a BAD idea
set shiftwidth=4

" Always replace tab with 8 spaces, except for makefiles
set expandtab
autocmd FileType make setlocal noexpandtab

" My settings when editing *.txt files
"   - automatically indent lines according to previous lines
"   - replace tab with 8 spaces
"   - when I hit tab key, move 2 spaces instead of 8
"   - wrap text if I go longer than 76 columns
"   - check spelling
autocmd FileType text setlocal autoindent expandtab softtabstop=2 textwidth=76 spell spelllang=en_us

" Don't do spell-checking on Vim help files
autocmd FileType help setlocal nospell

" Prepend ~/.backup to backupdir so that Vim will look for that directory
" before littering the current dir with backups.
" You need to do "mkdir ~/.backup" for this to work.
set backupdir^=~/.backup

" Also use ~/.backup for swap files. The trailing // tells Vim to incorporate
" full path into swap file names.
set dir^=~/.backup//

" Ignore case when searching
" - override this setting by tacking on \c or \C to your search term to make
"   your search always case-insensitive or case-sensitive, respectively.
set ignorecase

"
" End of Jae's Vim settings

Upvotes: 0

Views: 220

Answers (1)

resueman
resueman

Reputation: 10613

The problem is because your mapping is wrong. You currently have

nnoremap ; l<space>

The extra space at the end is treated as part of the mapping. Since <space> is, by default, movement to the right, this results in moving two spaces. Remove that extra space and it should work fine.

Upvotes: 6

Related Questions