move cursor to next line after input from filter command in vim
In vim I filter, say the current single line, using !! through a Unix command. To achieve this I defined the following shortcut in .vimrc
:map <Enter> !!mycommand<CR>:,+1<CR>
Pressing <Enter>
this takes me to the line below the current if mycommand
replaces my single input line be exactly one output line. If the output has more lines (number of lines unknown before command execution) it will still take me to the line below the curre开发者_运维知识库nt.
Now, I would like to know how I can always get to the first line below the inserted output of mycommand
.
The modified shortcut would then allow me to 'execute' the text file line by line using just <Enter>
displaying the output each time.
If there is no way to do this without any previous knowledge of the output of mycommand
, maybe there is one knowing say the first character of each output line.
Thanks a lot!
You can use the special marks '[
and ']
, which mark the start and end of the last changed (or yanked) text. Change your map to:
:map <Enter> !!mycommand<CR>']+
Note that I'm using + in place of your ex command. This will jump to the first non-blank character in next line. If that's not what you want, you may try simply j or, use a shorter version of your original map:
:map <Enter> !!mycommand<CR>']:+1<CR>
You don't really need the comma, to make this a range. This command is just a simplified :#
, where #
is a line number to jump. Here you can use .
meaning "current line", and then :.+1
moves to the next line. But you can omit the dot, and that's why :+1
does the same.
精彩评论