Reputation: 8260
I'm trying to script a simple set of vim commands, and can use this sequence of commands interactively to do what I want. For example, given the following file contents
#if 0
#include "foo.h"
#include "goo.h"
a <<< HERE >>>
b
c
#endif
when positioned on the line 'a', after the #include lines, I can do:
:,/endif/-1 d
:$
:p
:w
However, when I put these commands in a file ('a_vim_script'), and run:
:source a_vim_script
vim reports:
3 fewer lines
"f" 5L, 68C written
Press ENTER or type command to continue
and produces:
#if 0
#include "foo.h"
#include "goo.h"
#endif
instead of what I get when I do these commands interactively:
#if 0
#include "foo.h"
#include "goo.h"
#endif
a
b
c
The delete, move and write commands all execute, but the paste gets skipped mysteriously?
I can do this task other ways. For example, this script does what I want (and then moves to the next selection in my vim -q list) :
:,$!echo '\#endif\n' && grep -v '\#endif'
:w
:cn
However, why is it that the 'p' paste command in the first little vim script gets skipped?
Upvotes: 0
Views: 57
Reputation: 45117
:p
is not short for :put
it is short for :print
. Please use :put
or :pu
for short.
Additionally you should probably be using the :move
command instead of :delete
and :put
.
:,/endif/-m $
For more information see:
:h :p
:h :pu
:h :m
Upvotes: 1