How to open a file in VIM and move cursor to the search result

You can position the cursor on the first match using the -s (script) option. According to the vim manual:

-s {scriptin}
The script file {scriptin} is read. The characters in the file are interpreted as if you had typed them. The same can be done with the command ":source! {scriptin}". If the end of the file is reached before the editor exits, further characters are read from the keyboard.

You could use a temporary file with the keystrokes, or even (if you are using bash) process substitution. For example:

#!/bin/bash
vim -s <(printf '/c\n') tmp.txt

This approach works with more complicated searches than a single character.

Tags:

Vim

Search

Cursor