How do I create multiple cursors from search result?


I use Atom on Ubuntu 17.10 with wayland window manager.

I can create multiple cursors with CTRL+Mousclick or with CTRL+d so select the next same string.

But how can I for example mark some lines and create a cursor at the start of each line?

Also would be great to use search and find-all to select lots of results in a text to create a cursor at all these results.

I workaround at the moment by selecting the line-break and use CTL+d to select the next linebreaks too with extra cursors , then go one left and Pos1 to have the cursors at the start of each line.


This isn’t a solution, but why not just use the replace functionality? You can use capture groups with $n syntax. For example, I find "(\w+)": and replace it with $1: to remove quotes from CSON keys. It also supports \n and \t etc. in the replacement.


You can always write a command in that uses editor.scan() to find locations and then editor.addCursorAtBufferPosition() for each match.


I use Atom version 1.23.3



Yes that is possible.
You can use the
(1)"find all" with the search tool then
(2) press Alt + Enter to create cursors at all the found locations.

Using ^(?=.+) as a (regular expression) search term and then press Alt + Enter, would place cursor at all lines that has text in them. Combine this with the “only in selection” and the range is reduced to be inside the original selected text.

If you want to convert selections to cursors you can try the following codes:

###   ###

# ****************************************************
# ****************************************************
atom.commands.add 'atom-text-editor', 'custom:convert-selections-to-cursors', (e) ->
  _result = false
  if _editor = atom.workspace.getActiveTextEditor()
    if _editor.getSelectedText().length > 0
      # _checkpoint = _editor.createCheckpoint()
      for _range in _editor.getSelectedBufferRanges()
        for _row in [_range.start.row.._range.end.row]
          if not _result
            _result = true
      # _editor.groupChangesSinceCheckpoint(_checkpoint)

  unless _result # procedure was aborted
###   keymap.cson   ###

# ****************************************************
# ****************************************************
  'ctrl-k ctrl-c': 'custom:convert-selections-to-cursors'

With those hints I can leave you in the good company of the forum friends.


Thanks for the thorough answer!

This is what I was searching for. it is missing in the manual:

I added it in a stackexchange post, so I hope others will find it this way: