Please explain Regex

14 views
Skip to first unread message

vicky b

unread,
Jan 9, 2013, 7:25:27 AM1/9/13
to v...@vim.org
Hello All,

  Recently i cam across this command :g /^/m0   which   reverses order o line can any body explain how  this works

  Once more doubt i have is CTRL_0 i think this should copy object  what is it really please  explain



--
Thanks & Regards
 Vickyb


David Fishburn

unread,
Jan 9, 2013, 7:38:56 AM1/9/13
to vim_use



On Wed, Jan 9, 2013 at 7:25 AM, vicky b <vicky...@gmail.com> wrote:
Hello All,

  Recently i cam across this command :g /^/m0   which   reverses order o line can any body explain how  this works

:g without a range specified will operate on each line in the buffer starting at the top and moving to the bottom.

The pattern /^ says match at the start of a line, so it will match every line in the buffer.

/m0 says, "m"ove the line I am on to line 0 (the top of the buffer).

So, line 1 moves to the top.
line 2 moves to the top.
line 3 moves to the top.

Eventually, the file is reversed.

HTH,
David

Karthick Gururaj

unread,
Jan 9, 2013, 7:40:30 AM1/9/13
to vim_use, v...@vim.org
On Wed, Jan 9, 2013 at 5:55 PM, vicky b <vicky...@gmail.com> wrote:
Hello All,

  Recently i cam across this command :g /^/m0   which   reverses order o line can any body explain how  this works
Google "vim reverse lines" - the first hit is: http://vim.wikia.com/wiki/Reverse_all_lines 

  Once more doubt i have is CTRL_0 i think this should copy object  what is it really please  explain
 Don't understand - why do you think CTRL-0 should copy a text object? 




--
Thanks & Regards
 Vickyb


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Tim Chase

unread,
Jan 9, 2013, 7:59:36 AM1/9/13
to vicky b, v...@vim.org
On 01/09/13 06:25, vicky b wrote:
> Recently i cam across this command :g /^/m0 which reverses
> order o line can any body explain how this works

The :g command takes a pattern (in this case "^", or the
start-of-line which matches on every line) and performs an Ex
command on it (in this case "m0" which means move the line to become
the first line in the file). So it matches the 1st line, moves it
to the top (a noop), matches the 2nd line, moves it to the top (now
above what was the 1st line), matches the 3rd line, moves it to the
top (now above line 2 which was above line 1), etc, for every line
in the file.

You can read more at

:help :g
:help :move

> Once more doubt i have is CTRL_0 i think this should copy object
> what is it really please explain

Do you mean control+{capital-oh} or control+zero? You typed
control+zero which I don't believe that Vim recognizes (let alone
copies a text object...I'm not sure why you think this should
happen). However, in Insert mode, you can use control+oh to issue
one Normal mode command and then return to insert mode. I often do
this to scroll up or down, using something like

{control+o}10{control+Y}


As an aside, I don't know if it's a bug, but i_CTRL-\_CTRL-o is
supposed to act like i_CTRL-o without moving the cursor, but in at
least my stock Debian 7.2.445, doing

{ctrl-\}{ctrl-o}yis

in the middle of a sentence moves the cursor to the beginning of the
sentence. Can somebody running a more recent version test this for me?

-tim




Kazuo Teramoto

unread,
Jan 9, 2013, 8:06:59 AM1/9/13
to vim...@googlegroups.com
On 09 Jan 2013 at 10:59:36 -0200, Tim Chase wrote:
> As an aside, I don't know if it's a bug, but i_CTRL-\_CTRL-o is
> supposed to act like i_CTRL-o without moving the cursor, but in at
> least my stock Debian 7.2.445, doing
>
> {ctrl-\}{ctrl-o}yis
>
> in the middle of a sentence moves the cursor to the beginning of the
> sentence. Can somebody running a more recent version test this for
> me?

The same for me, i.e., {ctrl-\}{ctrl-o}yis move the cursor to the same
place yis moves the cursor.

I have vim 7.3.754 from Arch Linux.

Regards,
Kazuo Teramoto
signature.asc

Tim Chase

unread,
Jan 9, 2013, 8:32:41 AM1/9/13
to vim...@googlegroups.com, Kazuo Teramoto
Bram, et al.,

According to ":help i_CTRL-\_CTRL-O", it should not move the cursor.
However, as demonstrated above using

^\^Oyis

the cursor does end up moving, even in fairly recent builds as
confirmed by Kazuo.

-tim



vicky b

unread,
Jan 9, 2013, 8:37:18 AM1/9/13
to vim...@googlegroups.com
in insert mode i tried CTRL-o2CTRL-y  it  should have moved scroll up but it  dint i  am using vim 7.3  on window

Tim Chase

unread,
Jan 9, 2013, 8:46:51 AM1/9/13
to vim...@googlegroups.com, vicky b
On 01/09/13 07:37, vicky b wrote:
> in insert mode i tried CTRL-o2CTRL-y it should have moved scroll up but
> it dint i am using vim 7.3 on window

It should have scrolled *down* (shown text that was previously off
the top of the screen), assuming there was any text off the screen.
You can try using CTRL-e instead of CTRL-y to scroll in the
opposite direction (show more text off the bottom of the screen).

-tim




Bram Moolenaar

unread,
Jan 9, 2013, 8:53:07 AM1/9/13
to Tim Chase, vim...@googlegroups.com, Kazuo Teramoto
It's not the CTRL-\ CTRL-O that moves the cursor, it is the command that
follows that moves the cursor.
It would not be useful to disallow moving the cursor, e.g., CTRL-\ CTRL-O W
would not do anything.

The main difference with CTRL-O is when the cursor is past the end of
the line.


--
If you're sending someone Styrofoam, what do you pack it in?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Tim Chase

unread,
Jan 9, 2013, 9:31:31 AM1/9/13
to Bram Moolenaar, vim...@googlegroups.com
On 01/09/13 07:53, Bram Moolenaar wrote:
> Tim Chase wrote:
>>>> {ctrl-\}{ctrl-o}yis
>
> It's not the CTRL-\ CTRL-O that moves the cursor, it is the command that
> follows that moves the cursor.
> It would not be useful to disallow moving the cursor, e.g., CTRL-\ CTRL-O W
> would not do anything.

My reading of it was "like CTRL-O (execute one command, return to
Insert mode) but don't move the cursor", was something like
"<esc>{one Normal-mode command}gi" to resume insertion where you
left off. My example above shows a useful example (as you state "it
would not be useful"), where I wanted to yank the current
word/sentence/paragraph into a register (for subsequent insertion
with i_CTRL-R), resuming insertion where I left off.

So if it is truly just a matter of behavior when the cursor is past
the EOL, perhaps the docs should reflect that narrow definition. It
might also be worth noting any behavior changes with various 've'
settings.

-tim



Reply all
Reply to author
Forward
0 new messages