简体   繁体   中英

Vim <leader> command works, but beeps error sound and moves the cursor

I have the following configuration in my .vimrc in OSX under MacVim.

let mapleader = ','
nnoremap <leader>af :Autoformat<CR>         " autoformat document
nnoremap <leader>ig :IndentGuidesToggle<CR> " indent guides toggle
nnoremap <leader>nt :NERDTreeToggle<CR>     " nerd tree toggle
nnoremap <leader>tb :TagbarToggle<CR>       " tagbar toggle

The commands work fine, but when I use them, the terminal beeps the sound for error and the cursor moves position about 4 lines. This happens both when using Vim in iTerm2 and in GVim.

Any idea why this is happening and how to fix it?

Do not put comments on the same line as your mappings as the comments will be executed.

let mapleader = ','
" autoformat document
nnoremap <leader>af :Autoformat<CR>
" indent guides toggle
nnoremap <leader>ig :IndentGuidesToggle<CR>
" nerd tree toggle
nnoremap <leader>nt :NERDTreeToggle<CR>
nnoremap <leader>tb :TagbarToggle<CR> 

You may want to look at idiomatic-vimrc for basic do's and don't's for your vimrc .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM