1234
1234

Reputation: 579

Change default search criteria in Vim

I'm looking for a way to change the default criteria pattern Search in Vim

For example: You can search the word under the cursor

Shift-*

My problem:

When there is a string "my_name" in my file and if "name" is under my cursor in a different string and I do the search in Vim with Shift-*

Substring "name" is not highlighted in "my_name"

It seems to me Vim default criteria pattern matching is not included '_' as a word character, please correct me if I'm wrong.

What I did so far.

I read some help Doc. such as [:h hlsearch] and [:h search]. But I still can't figure out how to change the default search pattern.

Any suggestion would be appreciated

Upvotes: 2

Views: 196

Answers (2)

Christian Brabandt
Christian Brabandt

Reputation: 8258

I would advise not to change the iskeyword setting. Instead use the g* command, that will find also submatches and does not restrict the match to be at the word boundary. So while * searches for \<name\> g* searches for name and will therefore find submatches.

Upvotes: 1

Umang
Umang

Reputation: 5266

You can set the following in your .vimrc

set iskeyword+=_

Upvotes: 4

Related Questions