0

In Vim it is trivial to open a file from the command line to a specific word in the document. For e.g. to open the file "Contacts.txt" to "Bob" one would type:

vim Contacts.txt +/Bob

In Emacs it seems that one can only to this with a line number and or column but not a word.

2

You can use:

$ emacs Contacts.txt --eval '(search-forward "Bob")'
| improve this answer | |
  • 3
    Was just posting a similar answer :) I'd just use '(search-forward "Bob" nil t)' to avoid an error if Bob isn't there. – VanLaser Jan 16 '19 at 14:07
  • 2
    Also to place point on match beginning: emacs Contacts.txt --eval '(when (search-forward "Bob" nil t)(goto-char (match-beginning 0)))' – muffinmad Jan 16 '19 at 14:09
  • 2
    By the way, you can also define a function in your init file and use it from command line, e.g., emacs Contacts.txt --eval '(+/ "Bob")'. Editing Lisp in command line is painful. – xuchunyang Jan 16 '19 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.