error: *E486* Pattern not found
Note that for the `:global` command, you get a normal message "Pattern not
found", for Vi compatibility.
For the |:s| command the "e" flag can be used to avoid the error message
|:s_flags|.
*search-offset* *{offset}*
These commands search for the specified pattern. With "/" and "?" an
additional offset may be given. There are two types of offsets: line offsets
and character offsets.
The offset gives the cursor position relative to the found match:
[num] [num] lines downwards, in column 1
+[num] [num] lines downwards, in column 1
-[num] [num] lines upwards, in column 1
e[+num] [num] characters to the right of the end of the match
e[-num] [num] characters to the left of the end of the match
s[+num] [num] characters to the right of the start of the match
s[-num] [num] characters to the left of the start of the match
b[+num] [num] identical to s[+num] above (mnemonic: begin)
b[-num] [num] identical to s[-num] above (mnemonic: begin)
;{pattern} perform another search, see |//;|
If a '-' or '+' is given but [num] is omitted, a count of one will be used.
When including an offset with 'e', the search becomes inclusive (the
character the cursor lands on is included in operations).
Examples:
pattern cursor position ~
/test/+1 one line below "test", in column 1
/test/e on the last t of "test"
/test/s+2 on the 's' of "test"
/test/b-3 three characters before "test"
If one of these commands is used after an operator, the characters between
the cursor position before and after the search is affected. However, if a
line offset is given, the whole lines between the two cursor positions are
affected.
An example of how to search for matches with a pattern and change the match
with another word: >
/foo<CR> find "foo"
c//e<CR> change until end of match
bar<Esc> type replacement
//<CR> go to start of next match
c//e<CR> change until end of match
beep<Esc> type another replacement
etc.
<
*//;* *E386*
A very special offset is ';' followed by another search command. For example: >
/test 1/;/test
/test.*/+1;?ing?
The first one first finds the next occurrence of "test 1", and then the first
occurrence of "test" after that.
This is like executing two search commands after each other, except that:
- It can be used as a single motion command after an operator.
- The direction for a following "n" or "N" command comes from the first
search command.
- When an error occurs the cursor is not moved at all.
*last-pattern*
The last used pattern and offset are remembered. They can be used to repeat
the search, possibly in another direction or with another count. Note that
two patterns are remembered: One for "normal" search commands and one for the
substitute command ":s". Each time an empty pattern is given, the previously
used pattern is used. However, if there is no previous search command, a
previous substitute pattern is used, if possible.
The 'magic' option sticks with the last used pattern. If you change 'magic',
this will not change how the last used pattern will be interpreted.
The 'ignorecase' option does not do this. When 'ignorecase' is changed, it
will result in the pattern to match other text.
All matches for the last used search pattern will be highlighted if you set
the 'hlsearch' option.
To clear the last used search pattern: >
:let @/ = ""
This will not set the pattern to an empty string, because that would match
everywhere. The pattern is really cleared, like when starting Vim.
The search usually skips matches that don't move the cursor. Whether the next
match is found at the next character or after the skipped match depends on the
'c' flag in 'cpoptions'. See |cpo-c|.
with 'c' flag: "/..." advances 1 to 3 characters
without 'c' flag: "/..." advances 1 character
The unpredictability with the 'c' flag is caused by starting the search in the
first column, skipping matches until one is found past