I would like to search using current filename in this file. I already know getting current filename using :call expand("%:p:h"). So i’d like to using some command like /call expand("%:p:h") to search. I tried this but failed, because vim parse this function call literally.
I would like to search using current filename in this file. I already know
Share
Generally, to insert in command-line (or just in insert mode) a value, returned by some function, you should use the following:
Ctrl+R=function_name()Enter
By the way, you said that
expand("%:p:h")returns current filename, but this is wrong: actually it returns full path to current file, without filename. To get just a filename without a path, you should useexpand("%:t"). Please read:help expandto get more info.EDITED: In your case, you can use solution with search register
@/that @ib suggested: this is a safer way. But if i need just to find filename in the buffer, and if my filename does not contain some special characters, I would use Ctrl+R= instead.So, the whole expression to search current filename, is:
/\VCtrl+R=expand('%:t')EnterEnterP.S.
\Vat the beginning of the search pattern means “very nomagic” mode. You can read about it here::help \V