# vim - Mapping :tabn to a key



## kpedersen (Apr 9, 2010)

Hello All,

I am having some trouble with vim and I have looked all over google and the only examples I have found do not work.

I am trying to create a shortcut so when I press 'n' (for example) it goes to the next tab.

What google tells me to do is...


```
:map n :tabn<CR>
```

This is almost close but vim simply tries to run


```
:tabn<CR>
```

So it is printing <CR> rather than simulating pressing of that key which is pretty annoying.

I have tried <CR> <Return> <Enter> but they all just print out rather than pressing the key

Any Vim experts about?


----------



## graudeejs (Apr 9, 2010)

Here's how I do it (not exactly what you asked, but it's a working example)

```
nmap <C-A>n :next<cr>
nmap <C-A>p :previous<cr>
nmap <C-A>0 :buffer 0<cr>
nmap <C-A>1 :buffer 1<cr>
nmap <C-A>2 :buffer 2<cr>
nmap <C-A>3 :buffer 3<cr>
nmap <C-A>4 :buffer 4<cr>
nmap <C-A>5 :buffer 5<cr>
nmap <C-A>6 :buffer 6<cr>
nmap <C-A>7 :buffer 7<cr>
nmap <C-A>8 :buffer 8<cr>
nmap <C-A>9 :buffer 9<cr>
```


----------



## kpedersen (Apr 9, 2010)

Cool thanks, its good to know that it *should* work.

I tried your commands (using buffers) on a selection of vims...

vims from win32 and Debian had no luck. It cannot even find the <C-A> because it wants me to be pressing < + C + - + A + > keys all at the same time (Which is daft)

I am going to try a fresh compile of vim.

The vim from freebsd packages works as it should, and your commands worked fine.


----------



## kpedersen (Apr 9, 2010)

Hmm, its still not working.. it literally does not actually send the enter key press.. just prints out <cr>... argh!

I tried vi too and it does the same.


----------



## kpedersen (Apr 10, 2010)

kpedersen said:
			
		

> Hmm, its still not working.. it literally does not actually send the enter key press.. just prints out <cr>... argh!
> 
> I tried vi too and it does the same.



Edit:

Ok, when I put it in the .vimrc, it works fine.

It seems that when mapping key sequences on the fly (i.e using :map, :nmap etc...) the <cr> is not translated into a simulated keypress... i.e it doesnt show up in blue either when you list all the key mappings.

But thats all good. It is working nicely now,

Thanks for your help killasmurf86!


----------



## graudeejs (Apr 10, 2010)

you can check my config, if you like 
http://github.com/killasmurf86/ks86-dotfiles/blob/master/.vimrc


----------

