0

In gvim normal mode, the * key searches for the word under the cursor.

Say I have a file with the following lines:

life
alifexea a_life_xea
a life x
a=life
life=a
b=life;
c=b?life:a;
life?
?life

The cursor is in first line. I press * in normal mode. I expect and want all "life" to get highlighted except the 2nd line which has "alifexea a_life_xea". But it doesn't highlight the last 3 lines since the ? is probably considered a normal character. If I search using /life then all lines get highlighted which I do not want. Is there a way around (some setting) to make sure my expectation is satisfied when I search using *?.

  • What output do you get from this command? :se isk? – DJMcMayhem Jan 3 at 16:32
  • I get the following iskeyword=@,48-57,_,192-255 – Narasimhan Jan 3 at 16:34
  • Hmmm... That's really strange. I can not reproduce this behavior, unless I specifically add ? to the iskeyword option, which is about what I'd expect. But if you do not have ? in your iskeyword option, then it should work fine for you. Could you post your .vimrc? – DJMcMayhem Jan 3 at 16:40
  • Thanks. You are correct. I checked it on another machine and it works as expected. My .vimrc(copied from some website) is huge. I will try to debug tomorrow and get back if the issue persists. – Narasimhan Jan 3 at 19:11
  • 2
    You can use :verbose to see where an option was last set. e.g. :verbose set isk?. See :h :set-verbose for more help. – Peter Rincker Jan 3 at 23:53
0

This comes from your isk setting. This tells vim what is considered part of a word and what isn't, which is important for the asterisk command since searches for the word under the cursor. If isk includes ? or 63 (The code point of ?), then ? is treated just like letters, so life is a different word from life? just as lifex would be different.

By default, the setting of isk is "@,48-57,_,192-255". Which doesn't include ?. However, if you open up a new file with the .sv extension, and you have filetype plugin on, then vim will know what kind of file .sv is. Presumably, in this type of file, ? are treated different with this filetype, so vim adds it to isk.

To get around this, add the following line to your .vimrc:

au BufRead,BufNewFile *.sv set isk=@,48-57,_,192-255,#
  • For .sv file. iskeyword=@,48-57,63,_,192-255 As you mentioned since 63 is present the issue is coming. filetype plugin is on. However it is strange that vim assumed it that way for .sv and related files(verilog). In verilog language(like say c language) we cannot define variable as life?x but we can define life_x. So it makes sense not to put ? as part of the isk. Anyway thanks your workaround works(I didn't add #). – Narasimhan Jan 10 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.