My question comes from this two commands I added on my _vimrc file:

nnoremap <C-[> :set columns+=1<CR>
nnoremap <C-]> :set lines+=1<CR>

As is known, it will resize your gvim (I am using gvim on windows) with one more column when you hit Ctrl-[, and one more line when you hit Ctrl-]. That is really cool since you can achieve that resizement as though you are using your mouse.

I wonder if I can map those two command with only one key to make it more comfortable.

  • Beware that <C-[> is the same as <ESC>. It's a really bad idea to mess with that. You might want to choose a different key combination. – lcd047 Jul 8 '15 at 11:20
  • @lcd047 oh yeah that is right. thanks for that – Alex Jul 8 '15 at 11:26

You can do this with | (on windows, in the _vimrc file, so you have to replace it with <bar>).


" unix
nnoremap <C-[> :set columns+=1 | lines+=1<CR> 
" windows
nnoremap <C-[> :set columns+=1 <bar> lines+=1<CR> 

See the documentation : :help :bar

ref: https://stackoverflow.com/a/3249303/2558252

| improve this answer | |
  • 1
    the | is good, but that doesn't work in _vimrc file. It would be ok if you replace it with <bar> (as the answer in stackoverflow suggest) – Alex Jul 8 '15 at 11:08
  • Why doesn't | work in Windows? – Martin Tournoij Jul 8 '15 at 12:45
  • | doesn't work, you either need \| or <bar>. – romainl Jul 8 '15 at 12:48
  • on the documentation, there is no mention of this incompatibility. But as @michaelmichael said on he's answer : NB: You may find that your ~/.vimrc doesn't support mapping |, or \|. In these cases, try using <bar> instead. – nobe4 Jul 8 '15 at 12:49

I would recommend you to use for example <C-P>, since <C-[> is the same as <Esc> and <C-]> is used to jump to a definition of the keyword under the cursor.

You can just do this:

nnoremap <C-P> <Esc>:set columns+=1 lines+=1<CR>

The another way is to use the command separator |, but you have to escape it or use <Bar> to use it as an argument for the nnoremap command, otherwise it would be recognized as command separator in the vimrc file, not in the mapping.

nnoremap <C-P> <Esc>:set columns+=1 \| set lines+=1<CR>

So when you press <C-P>, this command is executed:

set columns+=1 | set lines+=1
| improve this answer | |
  • But also note that the <C-p> is used to autocomplete text in vim, which is a built-in utility. I haved used a <M-p> instead. But anyway, the<Esc> in front of the command is a very good addition. – Alex Jul 8 '15 at 13:42
  • @Alex You have mapped it only in normal mode. So you can still use <C-P> in insert mode to autocomplete text. – MichalH Jul 8 '15 at 13:51
  • oh yes you are right. – Alex Jul 8 '15 at 23:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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