2

I'm trying to create a zsh alias that will start vim and search backwards from the end of the file for a given string. I learnt about +normal and can do something like this to start vim at the end of the file:

vim "+normal G" log

But I'm not able to follow that by an incremental search. The following does work (with a literal CR) from the command line:

vim "+normal G?TEST^M" log

But I can't get this to work with an alias, probably because of the literal carriage return.

jogloran
  • 123
  • 4

2 Answers2

2

I would recommend breaking this up into multiple commands. This works for me:

vim log -c "normal G" -c "?TEST"

This doesn't need a carriage return since "?test" is treated as an ex command, not a normal mode command.

DJMcMayhem
  • 17,581
  • 5
  • 53
  • 85
1

You don't need "normal" at all, as Ex-"?" takes an address.

vim log '+$?TEST'

because of the literal carriage return

When you really want a carriage return, you can use "execute". The following is much longer but also works:

vim log '+exe "normal! G?TEST\<CR>"'
Matt
  • 20,685
  • 1
  • 11
  • 24