1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vim「\<」と「\>」とを利用するとき初心者がはまる落とし穴

Last updated at Posted at 2020-04-29

普段「\<」と「\\>」とを利用ワードの完全一致を検索できる
例えば下記の例(内容は気にしないで)で「seat」だけのワードを「table」に置き換えたいとする。

seatAvailable = seat.no; 
:s/\<seat\>/table 

無事に置き換えできた。

seatAvailable = table.no; 

では同様に、seat{j}をseat[i]にも置き換えてみる。

max_dis_seat[1] = seat{j}.no
:s/\<seat{j}\>/seat[i] 
E486: パターンは見つかりませんでした: \<seat{j}\>

あれ?波括弧にエスケープ必要ないはず
どこかで間違えているだろう。
けど、「\>」を利用しないと、置換できた。

:s/\<seat{j}/seat[i] 
max_dis_seat[1] = seat[i].no;

ネットで調べると、中括弧自体はワード文字ではないので、今回のように「]」は「>」が受け付けないようだ。
https://vi.stackexchange.com/questions/20433/inserting-a-square-bracket-as-part-of-search-and-replace

結局括弧といったワード文字ではないキャラクタで始まる検索パターンに対して、「\<」と「\\>」が使えないようだ。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?