Wanting to create a function which will add me python logger at each function define I came up on macro:
nnoremap <leader>L :%s/\(\s*\)def \(\w\S*\)\(self.*\):/\0\r\1\tlogging.info(\'\2)\')/g<cr>
It works, but I need eddited filename too, so I added to macro: in \=expand("%p")
. Now macro looks like that:
nnoremap <leader>L :%s/\(\s*\)def \(\w\S*\)\(self.*\):/\0\r\1\tlogging.info(\' \=expand("%p") \2)\')/g<cr>
Which doesn't work, because it prints whole =expand("%p")
as a text, not as a file name.
It seems to me that in general in text substitution I can use expand if I do not use regex.
I would be terribly grateful for correct macro and explanation why didn't it work.