Hi 🙂
This post is about a small tip to search words in Vim / Neovim.
I sometimes wanted to ignore case after beginning to search some words; It was not applied under the default settings, noignorecase
and nosmartcase
(at least, in the OpenBSD 6.4's package).
It was difficult for me to customize a config file, aka ~/.vimrc
/ ~/.config/nvim/init.vim
then.
Moreover, I didn't like stopping the search to type :set ignorecase
which may have to be reset afterwards every time I meet the case.
Additionally, my life would have been harder if I had been accustomed to restart the program with reading a custom config file with -u
option as needed: vim -u %config-file%
/ nvim -u %config-file%
.
I found the way after all:
\c
/ \C
are the magic words 😊
\c
enables case insensitive search dynamically:
/\c%keyword(s)%
\C
is the opposite, i.e. sensitive search:
/\C%keyword(s)%
Remember these options are prior to the config settings.
For example, under noignorecase
and nosmartcase
environment:
(Keyword) | "coffeebreak" is | "CoffeeBreak" is | "COFFEEBREAK" is |
---|---|---|---|
coffeebreak |
hit | not hit * | not hit * |
CoffeeBreak |
not hit | hit | not hit |
\ccoffeebreak |
hit | hit | hit |
\cCoffeeBreak |
hit | hit | hit |
\Ccoffeebreak |
hit | not hit | not hit |
\CCoffeeBreak |
not hit | hit | not hit |
* Under ignorecase
and smartcase
, it's hit. (Thus, the combination of the settings may be useful when a custom config file is available.)
If you want to read about these options in the official document, type in Vim:
:help ignorecase
:help smartcase
The gate is open!
Thank you for your reading 😄
I wish your happy life with Vim.