move a range of text to address?

47 views
Skip to first unread message

BartlebyScrivener

unread,
Nov 13, 2012, 12:01:30 PM11/13/12
to vim...@googlegroups.com
I see this command when I do :h :move

:[range]m[ove] {address} *:m* *:mo* *:move* *E134*

Move the lines given by [range] to below the line given by {address}.

But when I try it by setting mark a and b and then try moving the text to the end of the file:

:a,bm $

I get a trailing characters error.

rick

Tim Chase

unread,
Nov 13, 2012, 12:13:32 PM11/13/12
to vim...@googlegroups.com, BartlebyScrivener
On 11/13/12 11:01, BartlebyScrivener wrote:
> But when I try it by setting mark a and b and then try moving the text to the end of the file:
>
> :a,bm $
>
> I get a trailing characters error.

You want to reference the marks as marks:

:'a,'bm$

as show in

:help :'

(part of ":help :range") Otherwise, it thinks you're trying to do
an :append command, which is the origin or the peculiar error.

-tim


BartlebyScrivener

unread,
Nov 13, 2012, 12:16:58 PM11/13/12
to vim...@googlegroups.com, BartlebyScrivener
Thank you, Tim.

I've been yanking and putting my whole life and stumbled on "move" this morning by accident.

Could be quite useful.

Thanks again.

rick

Tim Chase

unread,
Nov 13, 2012, 12:25:38 PM11/13/12
to vim...@googlegroups.com, BartlebyScrivener
On 11/13/12 11:16, BartlebyScrivener wrote:
> Thank you, Tim.

Glad to help

> I've been yanking and putting my whole life and stumbled on "move" this morning by accident.
>
> Could be quite useful.

If you've been *yanking*, you'll want the :copy (also known as :t)
command, too. :-) Behaves pretty much identically, except it copies
rather than moves the line (which you'd get by *deleting*-then-putting).

I've got my fingers hard-wired with

:m+

to move the current line down one, which I use because
yanking/deleting tromps my scratch register when it's often useful
to preserve it when your intent is just "move this line down one".

The :t and :m commands are also helpful for gathering lines in a :g
command such as

:g/pattern/t$
:g/pattern/m$

which will either copy the lines to the bottom of the file for
review, or move the lines to the bottom of the file for
reviewing/ignoring purposes. I use both regularly, especially when
dealing with CSV files.

-tim


sc

unread,
Nov 13, 2012, 12:49:04 PM11/13/12
to vim...@googlegroups.com
On Tue, Nov 13, 2012 at 11:25:38AM -0600, Tim Chase wrote:
> On 11/13/12 11:16, BartlebyScrivener wrote:
> > Thank you, Tim.

> Glad to help

> > I've been yanking and putting my whole life and stumbled on "move" this morning by accident.
> >
> > Could be quite useful.

> If you've been *yanking*, you'll want the :copy (also known as :t)
> command, too. :-) Behaves pretty much identically, except it copies
> rather than moves the line (which you'd get by *deleting*-then-putting).

> I've got my fingers hard-wired with

> :m+

> to move the current line down one, which I use because
> yanking/deleting tromps my scratch register when it's often useful
> to preserve it when your intent is just "move this line down one".

I use that so much I've devoted F8 and S-F8 to that very function with

nnoremap <silent> <F8> :m+<CR>
inoremap <silent> <F8> <ESC>:m+<CR>gi
vnoremap <silent> <F8> :m'>+<CR>
nnoremap <silent> <S-F8> :m-2<CR>
inoremap <silent> <S-F8> <ESC>:m-2<CR>gi
vnoremap <silent> <S-F8> :m-2<CR>

sc

Christian Brabandt

unread,
Nov 13, 2012, 2:12:29 PM11/13/12
to vim...@googlegroups.com
Hi Tim!

On Di, 13 Nov 2012, Tim Chase wrote:

> The :t and :m commands are also helpful for gathering lines in a :g
> command such as
>
> :g/pattern/t$
> :g/pattern/m$
>
> which will either copy the lines to the bottom of the file for
> review, or move the lines to the bottom of the file for
> reviewing/ignoring purposes. I use both regularly, especially when
> dealing with CSV files.

Since you mentioning CSV files, I thought I'll add the CSV plugin. It
let's you dynamically filter lines for certain patterns and folds away
all non-matching lines. I especially use this technique to review
records (while e.g. keeping a header line). Plus it adds some nice
syntax highlighting and can arrange your data into a spreadsheet look.

regards,
Christian
--
Komik entsteht, wenn man Trag�dien anschaut und dabei ein Auge
zukneift.
-- Eug�ne Ionesco

BartlebyScrivener

unread,
Nov 13, 2012, 4:45:44 PM11/13/12
to vim...@googlegroups.com, toot...@swbell.net
As long as there are so many :m wizards around.

The instructions for the address suggest that you could move the text to 'T but it doesn't seem to work if 'T is in another buffer.

For example

:'a,'bm 'T

Is there a way to do this using :m ?

rick

Tim Chase

unread,
Nov 13, 2012, 5:06:00 PM11/13/12
to vim...@googlegroups.com, BartlebyScrivener, toot...@swbell.net
I don't think there's a way to move a line to another buffer/file.
I believe the destination has to be within the same file. So you can do

:10ka
:20kb
:30kc
:'a,'b m 'c

to move lines 10-20 to after line 30 all within the same buffer.

Looking at

:help :m

it gives the syntax as ":[range]m[ove] {address}", so looking at the
help for

:help {address}

which states "when the mark is in another file it cannot be used in
a range". It might be better clarified to include "or as a
destination for a :move or :copy".

-tim



Reply all
Reply to author
Forward
0 new messages