0

I want to search date format like 2019-07-12 11:22:33.

but, in vi mode, :/2019-07-12 11:22:33 is not executed by white space.

how can I search 2019-07-12 11:22:33?

(other format is not pretty)

2
  • 1
    Why are you typing a colon before the slash in your search? Leave the colon out and it should work.
    – Wildcard
    Jul 12, 2019 at 1:52
  • What does “is not executed by white space” mean? Jul 12, 2019 at 3:52

2 Answers 2

1

If :/2019-07-12 11:22:33 fails to match the whitespace, it is likely an indication that the whitespace in the date you're trying to match isn't a plain space but rather a tab or something. Try

:/2019-07-12\s11:22:33

to match any single whitespace character or

:/2019-07-12\s*11:22:33

to match any amount of whitespace (including zero).

(And as an aside, not that you don't need to drop to the colon prompt to search, you could search directly from command mode by just starting your search with a slash. -- From the colon, the search will place your cursor at the start of the line where the match was found, from command mode, the search will place your cursor at the start of the match.)

0

"\ " will work.

Use backslash followed by white space.

e.g. looking for "cat del",

  • /cat\ del
3
  • 2
    In all vi implementations I know of, simply /cat del + Enter works for finding all cat del occurrences in the file. No need of backslash + space.
    – user313992
    Jul 12, 2019 at 11:04
  • 1
    Also, the :/cat del (starting with a colon, / in command mode) works to move to the start of the next line where the cat del pattern occurs. I guess that may be OP's problem -- the cursor is put to the start of the line, not the start of the match. So your change to the Q which corrected the :/ into / wasn't appropriate; I will revert it.
    – user313992
    Jul 12, 2019 at 11:13
  • mosvy is right. It works for my system also. But I remember sometimes it didn't work in my memory. If some meta characters such as white space, slash, * make problem in looking for a string, it would be good try to add backslash before the meta characters. Jul 15, 2019 at 5:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .