tags:

views:

55

answers:

2

code sameple:

for file in files:
  do_something(root+file)

"file" is warned as "redefined symbol", so now I want to replace file to f but I must keep files

usually I use below command:

:%s/file/f/gcI

but it will match files, is there any way to match only whole word, and notice the (root+file) syntax.

A: 

Does this do it?

%s/\bfile\b/f/gcI

Thomas
No it doesn't. In vim regex `\b` matches the backspace character.
Dave Kirby
@Dave Kirby: Ah, thanks. Noted.
Thomas
+6  A: 

Use \< and \> to match the beginning and the end of a word:

:%s/\<file\>/f/gcI
livibetter
`\<` and `\>` is not a vim specific thing. Its a common regex notation to denote full words.
jeffjose