How to input ordered number in multi line mode?


#1

when in multi line mode
i want to get this result:

|1
|2
|3
|4

how could i get this?


#2

There isn’t a built-in way to do that. You could add this to your init.coffee to create a command that would do it:

atom.commands.add 'atom-workspace',
  'custom:insert-numbers': ->
    editor = atom.workspace.getActiveTextEditor()
    count = 0
    for selection in editor.getSelections()
      count += 1
      selection.insertText("#{count}")

You could create a keybinding for this using the normal methods once you restart Atom. You do have to be careful to create the multiple cursors in the correct order because it inserts the numbers in the order of the selections.


#3

I made some modifications to the script above to squeeze a bit more functionality out:

atom.commands.add 'atom-workspace',
	'custom:insert-numbers': ->
		editor = atom.workspace.getActiveTextEditor()
		selections = editor.getSelections()
		[num, incBy, radix] = selections[0].getText().split(" ")
		if not num? or num == ""
			num = 0
		if not incBy? or incBy == ""
			incBy = 1
		if not radix? or radix == ""
			radix = 10

		num = parseInt(num)
		incBy = parseInt(incBy)
		radix = parseInt(radix)

		for selection in selections
			numText = num.toString(radix)
			selection.insertText("#{numText}")
			num += incBy

Highlight the arguments with the first cursor to optionally change the starting number, the quantity by which it is incremented, and the output radix. Separate the arguments with a space

Hope this helps someone!


How to add image file to the project?