Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In my .vimrc file, I have the following two lines:

noremap! <C-PageDown> :bnext <CR>
noremap! <C-PageUp>   :bprev <CR>

but they do not work! In insert mode, typing

<C-v><C-PageDown>

returns

<C-PageDown>

(literally) and similarly so for <C-PageUp> and if I try to execute the command I get

:bnext

(plus a newline). In normal mode there's no effect. Thus, I know that the key map isn't being gobbled up by X or my shell but what else could be the problem? Other key maps work fine.

share|improve this question
add comment

3 Answers 3

Solved!

noremap  <C-PageDown>           :bnext <CR>
noremap  <C-PageUp>             :bprev <CR>
inoremap <C_PageDown> <C-\><C-O>:bnext <CR>
inoremap <C_PageUp>   <C-\><C-O>:bprev <CR>

In insert mode, anything on the RHS of the key mapping is inserted literally so we need to use <C-O> which enters normal mode for a single command. The <C-\> prevents the cursor from moving leftward which occurs when invoking <C-O> at the end of a line.

Also note that you can't have a space between <C-O> and :bnext else it will be eaten by <C-O>.

share|improve this answer
add comment

Could it be, because this keys are already used by vim for switching tab pages? See the description in vims documentation

share|improve this answer
1  
Well, not according to this (c.f. second paragraph under Unused Keys). –  gvkv Sep 27 '10 at 10:38
add comment

The n in :noremap is for normal mode, so it won't work in insert mode. If you want it to work in insert mode, use :imap. If you were trying to use <C-V> to make it work in insert mode, I think you were looking for <C-O>.

share|improve this answer
    
No. That would be :nnoremap; two ns. –  gvkv Sep 27 '10 at 10:26
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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