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
    Commented Jul 8, 2015 at 11:20
  • @lcd047 oh yeah that is right. thanks for that
    – Alex
    Commented Jul 8, 2015 at 11:26

3 Answers 3


You can do this with \| on unix in the .vimrc file, or with <bar> on windows in the _vimrc file.


" 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

  • 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
    Commented Jul 8, 2015 at 11:08
  • Why doesn't | work in Windows? Commented Jul 8, 2015 at 12:45
  • | doesn't work, you either need \| or <bar>.
    – romainl
    Commented Jul 8, 2015 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
    Commented Jul 8, 2015 at 12:49
  • 1
    This answer is very much incorrect. Even without escaping \| for nnoremap, it would only work if columns+=1 was a command, but it's actually a setting. set lines+=1 columns+=1 would be correct (changing multiple settings from the same :set command.
    – filbranden
    Commented Dec 26, 2020 at 17:14

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
  • 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
    Commented Jul 8, 2015 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
    Commented Jul 8, 2015 at 13:51
  • oh yes you are right.
    – Alex
    Commented Jul 8, 2015 at 23:17

I was mapping two commands to one F-key to execute 2 plugin commands and none of the above worked for me. The only option that worked for me was with to <CR>:

nnoremap <F10> :Doctest <CR> :lwindow<CR>
  • That's because user-commands such as :Doctest typically don't accept | as a separator (they take it as an argument.) See :help :bar which explains a lot of that. One solution is to use :execute: nnoremap <F10> :execute 'Doctest' \| lwindow<CR>. But yeah using two separate <CR>s would work for sure.
    – filbranden
    Commented Dec 26, 2020 at 16:16
  • Thx this helped! Commented Jul 28, 2021 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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