Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mapping control followed by two characters in vim

Tags:

vim

vi

I like switching my focus back and forth between the NERDTREE pane and a file and the command Ctrl-ww accomplishes this. I'd like to map this to <Leader>w but variations of map <Leader>w <C-ww><CR> in my .vimrc are not working for me. Any thoughts on how to accomplish this mapping?

like image 810
Matt Avatar asked Oct 06 '11 07:10

Matt


People also ask

How do I map a key in Vim?

Vim supports several editing modes - normal, insert, replace, visual, select, command-line and operator-pending. You can map a key to work in all or some of these modes. The general syntax of a map command is: {cmd} {attr} {lhs} {rhs} where {cmd} is one of ':map', ':map!'

What is Ctrl in Vim?

You can put your cursor on the word and CTRL-] will jump to the function definition. To get this functionality you need some external program to generate a tags file on the code so that vim can know where the definitions are. It's also used to jump to help file locations.

What is the silent key in Vim?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.

What is XMAP Vim?

xmap creates a mapping for just Visual mode whereas vmap creates one for both Visual mode and Select mode. As far as I understand, the intent of Select mode was to make Vim behave just like every other non-modal editor when text is selected, i.e., typing anything immediately replaces the selection with the typed text.


1 Answers

It's not <C-ww>, it's <C-w>w or <C-w><C-w>.

That's either Ctrl+w then w or Ctrl+w then Ctrl+w.

So your mapping should be nnoremap <Leader>w <C-w>w or nnoremap <Leader>w <C-w><C-w>.

Note that you can use <C-w>p to move to the previous window and effectively toggle between NERDTree and your active window.

See :help window for more infos on windows in Vim.

like image 198
romainl Avatar answered Nov 03 '22 01:11

romainl