I have a hotkey that runs python of the first buffer when I press F8 and outputs the outputs to the bottom.

However, this hotkey does not work when I switch buffers... it only works when I am on the first buffer.. Why would this be the case?

nnoremap <buffer> <F8> :! python3 #1<cr>

2 Answers 2


The modifier <buffer> means the mapping is only effective for the buffer in which the command was run.

This is heavily used in ftplugins to create local mappings; e.g., you might want F8 to run :!python3 % in python buffers but :make in C buffers. You can make a single function that does this and bind it globally, but then you have to keep updating the function for new filetypes you work with.

Instead, bind F8 with a <buffer> mapping in the relevant ftplugins. Then each new filetype gets its own binding, and the binding is located with all the other file-type specific settings.


Ok... removing <buffer> seems to do the trick... I am not sure I had it there in the first place...(I copied it from a code snippet)

nnoremap <F8> :! python3 #1<cr>

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.