0

I can't scratch my head around why my keymaps in C++ file buffer are getting overwritten by rules for in file. I though BufRead executes after opening new file, right?

I have the following vimrc configuration:

autocmd FileType cpp
    \  nnoremap <buffer> <f5> :up<cr>:!g++ -Wall -Wextra -Wshadow -Wno-sign-conversion -O2 -o a.out % && ./a.out < in<cr>
    \| nnoremap <buffer> <f6> :split in<cr>

autocmd BufRead,BufNew in
    \  nnoremap <buffer> <f5> :up<cr>:!./a.out < in<cr>
    \| nnoremap <buffer> <f6> :wq<cr>
    \| echom "in file loaded " . winbufnr(0)

Output in vim after F6 (:mess):

in file loaded 1
in file loaded 2

Output in Nvim after F6:

in file loaded 1

There is no output before pressing F6.

When I open file in from test.cpp (either through F6 or direct :sp), C++ keymaps are no longer there, from test.cpp:

:nnoremap <buffer>

n  <F6>        *@:wq<CR>                                               
n  <F5>        *@:up<CR>:!./a.out < in<CR>

My other F5 keymaps for other files are working just fine. Any help is appreciated

Drdilyor
  • 1,250
  • 1
  • 12
  • 30

1 Answers1

0

Replaced BufNew with BufNewFile event and it works as expected

Drdilyor
  • 1,250
  • 1
  • 12
  • 30