0

I am using a Raspberry Pi for learning C. I use NeoVim and Mingw-GCC on the Pi over SSH. Building is done with a custom script named build. Initial builds were done by calling ./build from the command mode of nvim.

I want to map Ctrl-B to call the build script. Currently I am using this

noremap <C-b> :w | !./build

but everytime I run vim, it seems to be running the build script.

result of running nvim on terminal

Removing the w | seems to solve the problem but then I have to manually save the file before running.

I want it to just startup normally. And save before building.

4
  • See :help map-bar.
    – romainl
    Commented Dec 24, 2022 at 19:58
  • There isn't any help for map-bar Commented Dec 25, 2022 at 12:26
  • Oh yes, there is. In Vim at least.
    – romainl
    Commented Dec 25, 2022 at 12:58
  • Okay I ran vim and checked the help. Thanks a lot Commented Dec 25, 2022 at 16:08

1 Answer 1

1

The bar | is used to separate {lhs} and {rhs}. Thus it reads the next command as a command to run. To use a <bar> in keymaps:

   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
2
  • FWIW, text is easier to use than screenshots.
    – D. Ben Knoble
    Commented Dec 25, 2022 at 22:55
  • Will surely remember next time. Commented Dec 28, 2022 at 17:32

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.