6

I'm trying to make Vim play nice with wrapped lines and I'm running into some problems. The following line

xnoremap <expr> k ((v:count == 0) || (mode() !=# "V") ? 'gk' : 'k')

gives me the following error when launching Vim

Error detected while processing /cygdrive/c/Users/Chad/.vimrc:
line   76:
E749: empty buffer

If I remove either of the conditions the map will work fine but I'd like to combine them. Any ideas? Thanks in advance.

1 Answer 1

7

See :h map_bar. The | is used also as a command separator in vim, so you are executing a map command:

xnoremap <expr> k ((v:count == 0) 

Then an empty command line, and after that a command:

(mode() !=# "V") ? 'gk' : 'k')

To use the | character in mappings, the two best options in my opinion are <Bar> or \|. Your mapping can be written as

xnoremap <expr> k ((v:count == 0) <Bar><Bar> (mode() !=# "V") ? 'gk' : 'k')

for example.

1
  • Ahh great! :help map_bar is what I needed. Thanks. That logic I posted is a little off for the behavior I want so I might have to end up using logical and instead but your solution does let me use || so I'll accept it as the answer. Commented Apr 11, 2015 at 15:07

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.