junegunn / fzf.vim

fzf :heart: vim
MIT License
9.65k stars 584 forks source link

Match exact searched word/phrase #1062

Open vaklinzi opened 4 years ago

vaklinzi commented 4 years ago

I would like to find exact matches for a searched word. For example if I search for $user I would like to find only these results but have others like $userData, $username...:

image

image

I tried with ' '$user but still there are some other results.

Konfekt commented 3 years ago

It seems that the search term is in Vim always put in single quotes, since

$FZF_DEFAULT_OPTS 

containing --exact or -x only yields exact matches. That is why in my vimrc I added

let $FZF_DEFAULT_OPTS=substitute($FZF_DEFAULT_OPTS, '\V--exact\|-x', '', 'g')

Regarding this exact issue,

let $FZF_DEFAULT_OPTS .= ' -x '

should achieve what you look for.

junegunn commented 3 years ago

I tried with ' '$user but still there are some other results.

It's working as expected. It's only showing results that contain the exact $user, not matching something like $someuser or $ultracondenser.

What you're looking for is a word-boundary anchor (\b in regex), but fzf doesn't support it.