I sometimes make shortcuts for myself, which run some external command on the current buffer, such as
nnoremap <C-f> :%!clang-format -style=file<C-m>
which formats the buffer with clang's formatter.
However, this makes the cursor jump to the beginning of the file. Is there some way to avoid this? I understand it would be difficult finding the correct line after reformatting, but just the same line number would be good. I assume one could set and use marks in the mapping somehow, but any smarter solution would also be appreciated.