Quantcast

Multiple cursors in vim, is it possible?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Multiple cursors in vim, is it possible?

Asis Hallab-2
Dear Vimers,

I just watched a screencast about Submile Text 2, a much buzzed about new text editor.
It has a very neat feature called multiple cursors, where the user just selects different positions in the current buffer and every editing done is applied to those multiple cursor positions.

In some cases I am convinced this feature is easier and quicker to use than macros.
In a way the visual block mode does what multiple cursors do. Only they do more..

I have to say, there is already an emacs plugin for multiple cursor support:

So now my question:
Could this be implemented as a plugin for vim?
Could that be written in VimL or needed to be compiled into Vim itself?

Looking forward to your ideas.

Cheers!
Asis

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Salman Halim
On Sun, Aug 5, 2012 at 9:12 AM, Asis Hallab <[hidden email]> wrote:

> Dear Vimers,
>
> I just watched a screencast about Submile Text 2, a much buzzed about new
> text editor.
> It has a very neat feature called multiple cursors, where the user just
> selects different positions in the current buffer and every editing done is
> applied to those multiple cursor positions.
> http://www.youtube.com/watch?v=o5bPRhFHEz0
>
> In some cases I am convinced this feature is easier and quicker to use than
> macros.
> In a way the visual block mode does what multiple cursors do. Only they do
> more..
>
> I have to say, there is already an emacs plugin for multiple cursor support:
> https://github.com/emacsmirror/multiple-cursors
>
> So now my question:
> Could this be implemented as a plugin for vim?
> Could that be written in VimL or needed to be compiled into Vim itself?
>
> Looking forward to your ideas.
>
> Cheers!
> Asis

As you can imagine, this doesn't exist already. I can envision a
plugin that can do this, though, for the most part. A few questions:

1. Is one of those marked locations considered the primary one (you
can only type in that one and have it copy) or are all of those open
for editing with mirroring?
2. What happens if you start typing on another line that's not part of
the marked cursors? Do the cursor lines move down as you press enter,
etc., or do they get reset if you start typing elsewhere?
3. Is the entire line considered "cursored" or is it specific to the
actual column? For example, line 3, column 2 and line 10, column 5 or
just lines 3 and 10, in their entirety?

To get a plugin:

1. Need a way to mark multiple locations in the file as "cursor"
locations; I envision the use of placed signs to indicate this.
2. One can either map all keys that change the buffer in insert mode
and apply changes to all the other marked spots with each keypress
(non-trivial) or, instead, observe that insert mode was entered on one
of the marked lines and then wait until exit and then go to each of
the other cursor locations just repeat (the equivalent of hitting .).
3. From what I understand, Sublime and Emacs are, compared to Vim,
modeless: in Vim, you could enter insert mode by typing R, s, i, a,
cw, etc. That'd be pretty hard to pick up on and duplicate, unless you
go with the "wait till end and then just hit . on the marked
locations" bit.

Just a quick think; I'm sure there are many facets I'm missing here.

--
سلمان حلیم

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Tony Mechelynck
In reply to this post by Asis Hallab-2
On 05/08/12 15:12, Asis Hallab wrote:

> Dear Vimers,
>
> I just watched a screencast about /Submile Text 2/, a much buzzed about
> new text editor.
> It has a very neat feature called *multiple cursors*, where the user
> just selects different positions in the current buffer and every editing
> done is applied to those multiple cursor positions.
> http://www.youtube.com/watch?v=o5bPRhFHEz0
>
> In some cases I am convinced this feature is easier and quicker to use
> than macros.
> In a way the visual block mode does what multiple cursors do. Only they
> do more..
>
> I have to say, there is already an emacs plugin for multiple cursor support:
> https://github.com/emacsmirror/multiple-cursors
>
> So now my question:
> Could this be implemented as a plugin for vim?
> Could that be written in VimL or needed to be compiled into Vim itself?
>
> Looking forward to your ideas.
>
> Cheers!
> Asis
>

Vim does not apply the same changes implicitly to more than one
location. Implementing it in vimscript might be possible, but probably
inefficient (I mean, you may have to wait a measurable time before you
see each character), especially if your "multiple cursors" are in one
window but farther away from each other than the window height. I
imagine that one would either map every key in Insert mode, or intercept
all keys are they are typed.

Concerning implementation in C code, I believe that it would be both
hard to code in a bugfree manner on top of the existing Vim source, and
contrary to the "Vim philosophy" — but I'm no prophet about the latter.

The nearest thing to multiple cursors that I can imagine which is easy
to do, would be to have your "several locations" (in one file or in
several files) open in parallel split windows in a single tab. Vim
remembers the cursor position for each window (even for two or more
windows on a single file) and switching windows would bring you from one
location to the next. After typing some text at the first location, you
could "yank" it, then change windows (e.g. with Ctrl-W w) and "put" it
at the next location (you know, don't you, that yank and put are Vim
terminology for copy and paste respectively?). See also :help
'scrollbind' about scrolling two (or more) windows in parallel. Oh, and
see :help q about remembering keyboard actions (including cursor moves)
to have Vim replay them later.

Oh, and if you want to make Vim "more like emacs", I think you will find
extremely little enthusiasm in these groups. Just an opinion, worth no
more than my 0.02 €.


Best regards,
Tony.
--
ARTHUR:  I did say sorry about the `old woman,' but from the behind you
          looked--
DENNIS:  What I object to is you automatically treat me like an inferior!
ARTHUR:  Well, I AM king...
                                   The Quest for the Holy Grail (Monty
Python)

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Dominique Pellé
In reply to this post by Asis Hallab-2
On Sun, Aug 5, 2012 at 3:12 PM, Asis Hallab <[hidden email]> wrote:

> Dear Vimers,
>
> I just watched a screencast about Submile Text 2, a much buzzed about new
> text editor.
> It has a very neat feature called multiple cursors, where the user just
> selects different positions in the current buffer and every editing done is
> applied to those multiple cursor positions.
> http://www.youtube.com/watch?v=o5bPRhFHEz0
>
> In some cases I am convinced this feature is easier and quicker to use than
> macros.
> In a way the visual block mode does what multiple cursors do. Only they do
> more..
>
> I have to say, there is already an emacs plugin for multiple cursor support:
> https://github.com/emacsmirror/multiple-cursors
>
> So now my question:
> Could this be implemented as a plugin for vim?
> Could that be written in VimL or needed to be compiled into Vim itself?
>
> Looking forward to your ideas.
>
> Cheers!
> Asis

Hi Asis

Someone thought about multi-editing with Vim already. See:

http://blog.felixriedel.com/2012/06/multi-editing-in-vim/

-- Dominique

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Tim Chase
In reply to this post by Tony Mechelynck
On 08/05/12 12:25, Tony Mechelynck wrote:
> On 05/08/12 15:12, Asis Hallab wrote:
>> It has a very neat feature called *multiple cursors*, where the
>> user just selects different positions in the current buffer and
>> every editing done is applied to those multiple cursor
>> positions.
>
> The nearest thing to multiple cursors that I can imagine which is
> easy to do, would be to have your "several locations"

The first thing that occurred to me was the use of the :g command
which performs one or more Ex commands on every line that matches a
pattern.  In a way, "ed" allowed for editing at multiple "cursor"
locations decades ago. :-)

-tim




--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Tony Mechelynck
On 05/08/12 20:12, Tim Chase wrote:

> On 08/05/12 12:25, Tony Mechelynck wrote:
>> On 05/08/12 15:12, Asis Hallab wrote:
>>> It has a very neat feature called *multiple cursors*, where the
>>> user just selects different positions in the current buffer and
>>> every editing done is applied to those multiple cursor
>>> positions.
>>
>> The nearest thing to multiple cursors that I can imagine which is
>> easy to do, would be to have your "several locations"
>
> The first thing that occurred to me was the use of the :g command
> which performs one or more Ex commands on every line that matches a
> pattern.  In a way, "ed" allowed for editing at multiple "cursor"
> locations decades ago. :-)
>
> -tim
>

Ah, right, but not interactively, and in only one file at a time.


Best regards,
Tony.
--
"I had to censor everything my sons watched ... even on the Mary Tyler
Moore show I heard the word 'damn'!"
                -- Mary Lou Bax

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Tim Chase
On 08/05/12 13:20, Tony Mechelynck wrote:
> On 05/08/12 20:12, Tim Chase wrote:
>>>> It has a very neat feature called *multiple cursors*,
>>>
>>> The nearest thing to multiple cursors that I can imagine which is
>>> easy to do, would be to have your "several locations"
>>
>> The first thing that occurred to me was the use of the :g command
>
> Ah, right, but not interactively, and in only one file at a time.

Interactively, no.  More than one file?  Just prefix it with
windo/bufdo/argdo/tabdo :-D

Additionally, I've found that judicious use of my editing commands
allows me to just use the period (".") to replay a given edit

-tim


--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Davido
In reply to this post by Tim Chase
Tim Chase <[hidden email]> wrote, on dim 05 aoû 2012, 13:12 :

> On 08/05/12 12:25, Tony Mechelynck wrote:
> > On 05/08/12 15:12, Asis Hallab wrote:
> >> It has a very neat feature called *multiple cursors*, where the
> >> user just selects different positions in the current buffer and
> >> every editing done is applied to those multiple cursor
> >> positions.
> >
> > The nearest thing to multiple cursors that I can imagine which is
> > easy to do, would be to have your "several locations"
>
> The first thing that occurred to me was the use of the :g command
> which performs one or more Ex commands on every line that matches a
> pattern.  In a way, "ed" allowed for editing at multiple "cursor"
> locations decades ago. :-)
>
> -tim

You can also use "windo" to perform the same action in all the windows
of the current tab. For instance, to add "hello" in all windows :

:windo norm ahello

It works with one or more files

> --
> 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

--
Davido

--
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Multiple cursors in vim, is it possible?

Terry Ma
In reply to this post by Asis Hallab-2
On Sunday, August 5, 2012 6:12:20 AM UTC-7, Asis Hallab wrote:

> Dear Vimers,
>
>
> I just watched a screencast about Submile Text 2, a much buzzed about new text editor.
> It has a very neat feature called multiple cursors, where the user just selects different positions in the current buffer and every editing done is applied to those multiple cursor positions.
>
> http://www.youtube.com/watch?v=o5bPRhFHEz0
>
>
> In some cases I am convinced this feature is easier and quicker to use than macros.
>
> In a way the visual block mode does what multiple cursors do. Only they do more..
>
>
> I have to say, there is already an emacs plugin for multiple cursor support:
> https://github.com/emacsmirror/multiple-cursors
>
>
>
> So now my question:
> Could this be implemented as a plugin for vim?
> Could that be written in VimL or needed to be compiled into Vim itself?
>
>
> Looking forward to your ideas.
>
>
>
> Cheers!
> Asis

Just want to mention that I just created a Vim plugin that tries to emulate Sublime Text's multiple selection behavior: https://github.com/terryma/vim-multiple-cursors. Check it out and see if it fits your need.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Loading...