- use:
^
(shift + 6)
This moves the cursor to the first non-blank character of the current line.
_
(underscore)
This also moves the cursor to the first non-blank character on the same line the cursor is on.
By the way, the 0
command moves to the absolute start of the line, including any leading whitespace.
/\cYourSearchKeywords
-- case insensitive
/\CYourSearchKeywords
-- case sensitive, which is the default behaviour
A few other ideas:
\c
can appear anywhere in the pattern, so if you type a pattern and then decide you wanted a case-insensitive search, just add a \c
at the end.
- add
set ignorecase
for case-insensitive searching in my vimrc, and I can use \C
to do a case-sensitive search
- There's also
set smartcase
which will automatically switch to a case-sensitive search if you use any capital letters
- Remember!
set smartcase
applies only when set ignorecase
is already active
Reference
Yesterday, I need to replace a string ClassName
with List<ClassName>
many times in a few files, and the ClassName varies. Manually doing it again and again is tedious and mistake prone, which is what I hate. Here's the solution
First, record a macro,
- move cursor on any letter of the target ClassName
- qa
- ysiw>
- Insert
- List
- Esc
- q
Second, replay the macro, move cursor to another occurrence of ClassName,
@a
Third, replay the same macro as many times as you want: move cursor to any other occurrences, simply type
@@
The feeling is so good to let a computer do what you want it to do!
and here's the Reference where I learnt how to use vim macro. TL;DR;
I keep my config files on github, and I use hard-link for most of the config files. It's convenient, as I can check the new changes easily and submit some of the changes when necessary. However, the default behavior of vim troubles me. It always changed the inode when I save the config file!
tldr; the solution is: put the following line in your .vimrc
set backupcopy=yes
PS
Though this way fixed Vim's behavior, I sadly found that git pull
will change the config file's inode as well. So there is actually no feasible solution. I have abandoned this hard link approach. If you have better solutions to maintain all your config files in one repository, please let me know!