how can anyone add the filename in the file in ex-mode? <C-R>% and "%p works only in normal mode:put %
Or, if you need to insert it at a particular place, :10s/$/\=' '.expand('%')will put it at the end of line #10. The basic idiom involves replacing something (EOL, BOL, or some offset in the line) with an evaluated expression that uses expand('%')
You can read more at :help sub-replace-special :help expand() -tim