2

I've recently decided to improve my multiple-pane Vim workflow, so I'm adding some new mappings to avoid the awkward <C-W> command. Here's what I have currently:

" split-pane navigation remaps                                                   
nnoremap <c-j> <c-w>j                                                            
nnoremap <c-k> <c-w>k                                                            
nnoremap <c-h> <c-w>h                                                            
nnoremap <c-l> <c-w>l                                                            
nnoremap <c-|> :vsplit<cr>                                                     
nnoremap <c-_> :split<cr>                                                        
set splitbelow                                                                   
set splitright  

Right now, everything works except the <c-|> vertical split. It is my understanding that the syntax would normally be <c-|>, but since | is a special character, it must be escaped. Here's what I found through :help map_bar

Since the '|' character is used to separate a map command from the next          
command, you will have to do something special to include  a '|' in {rhs}.       
There are three methods:                                                         
   use       works when                    example      ~                        
   <Bar>     '<' is not in 'cpoptions'     :map _l :!ls <Bar> more^M             
   \|        'b' is not in 'cpoptions'     :map _l :!ls \| more^M                
   ^V|       always, in Vim and Vi         :map _l :!ls ^V| more^M               

(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you     
cannot use the <> notation "<C-V>" here).

Unfortunately, I've tried the following and none of them seem to work:

nnoremap <c-|> :vsplit<cr>    
nnoremap <c-\|> :vsplit<cr>    
nnoremap <c-<bar>> :vsplit<cr>    
nnoremap <c-^V|> :vsplit<cr>    

And yes, I got ^V by holding Control and double-tapping V, not by typing Caret V. Thanks, any ideas would be appreciated!

4
  • 1
    What kind of keyboard are you using? Oh my macbook, the \ key requires a shift press and I don't think CTRL+SHIFT mappings are possible. Also, have you tried escaping \<bar>?
    – Jay Dorsey
    Jun 29, 2019 at 2:35
  • 2
    I'm using a standard US keyboard layout on my Ubuntu 16.04 laptop. I just tried \<bar>, that didn't work either.
    – TimD1
    Jun 29, 2019 at 2:41
  • 1
    The correct syntax would've been <c-bar>. Unfortunately, <bar> usually doesn't work with control key Vim: vim_faq.txt
    – otter.pro
    Jul 1, 2019 at 19:05
  • Thanks for a definitive answer! Too bad it's a no.
    – TimD1
    Jul 2, 2019 at 1:40

1 Answer 1

2

Use <c-\>, which despite the backslash doesn't need to be escaped in maps.

Alternatively, <c-bslash> is the same, useful in cases such as strings where the backslash has meaning.

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.