Module: VER::Methods::Delete

Included in:
VER::Methods
Defined in:
lib/ver/methods/delete.rb

Instance Method Summary collapse

Instance Method Details

#change_line(count = 1) ⇒ Object

Wrapper for [kill_line] that starts insert mode after killing count lines.

Parameters:

  • count (#to_i) (defaults to: 1)

    Number of lines to kill

See Also:



66
67
68
69
# File 'lib/ver/methods/delete.rb', line 66

def change_line(count = 1)
  kill_line(count)
  start_insert_mode
end

#change_motion(motion, count = 1) ⇒ Object



4
5
6
7
# File 'lib/ver/methods/delete.rb', line 4

def change_motion(motion, count = 1)
  delete_motion(motion, count)
  start_insert_mode
end

#delete(*indices) ⇒ Object

Delete text between indices



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/ver/methods/delete.rb', line 78

def delete(*indices)
  indices_size = indices.size
  return if indices_size == 0

  undo_record do |record|
    if indices_size == 1
      record.delete(indices.first)
    else
      indices.each_slice(2) do |from, to|
        next if from == to
        record.delete(from, to)
      end
    end
  end
end

#delete_line(count = 1) ⇒ Object

Delete current line and upto count subsequent lines.

Parameters:

  • count (#to_i) (defaults to: 1)

    Number of lines to delete

See Also:



39
40
41
42
43
44
# File 'lib/ver/methods/delete.rb', line 39

def delete_line(count = 1)
  from = index('insert linestart')
  count = count.abs - 1
  to = index("#{from.y + count}.#{from.x} lineend + 1 char")
  delete(from, to)
end

#delete_motion(motion, count = 1) ⇒ Object

Given a motion, this method will execute a virtual movement with the count argument and [delete] the corresponding indices.

Parameters:

  • motion (Symbol String)

    name of a method acceptable for [virtual_movement]

  • count (#to_i) (defaults to: 1)

See Also:

  • #delete
  • VER::Move#virtual_movement


17
18
19
# File 'lib/ver/methods/delete.rb', line 17

def delete_motion(motion, count = 1)
  delete(*virtual_movement(motion, count))
end

#delete_trailing_whitespaceObject

Tag and delete all trailing whitespace in the current buffer.



72
73
74
75
# File 'lib/ver/methods/delete.rb', line 72

def delete_trailing_whitespace
  tag_all_trailing_whitespace
  execute :delete, *tag_ranges('invalid.trailing-whitespace').flatten
end

#kill(*indices) ⇒ Object

Copy text between indices and delete it.

Parameters:

  • indices (Array<Text::Index, String, Symbol>)

    one or more indices within the buffer, must be an even number of indices if more than one.



99
100
101
102
103
104
105
106
107
108
# File 'lib/ver/methods/delete.rb', line 99

def kill(*indices)
  if indices.size > 2
    deleted = indices.each_slice(2).map{|left, right| get(left, right) }
  else
    deleted = get(*indices)
  end

  copy(deleted)
  delete(*indices)
end

#kill_line(count = 1) ⇒ Object

Copy current line and upto count subsequent lines and delete them.

Parameters:

  • count (#to_i) (defaults to: 1)

    Number of lines to kill

See Also:



52
53
54
55
56
57
# File 'lib/ver/methods/delete.rb', line 52

def kill_line(count = 1)
  from = index('insert linestart')
  count = count.abs - 1
  to = index("#{from.y + count.to_i}.#{from.x} lineend + 1 char")
  kill(from, to)
end

#kill_motion(motion, count = 1) ⇒ Object

Given a motion, this method will execute a virtual movement with the count argument and [kill] the corresponding indices.

Parameters:

  • motion (Symbol String)

    name of a method acceptable for [virtual_movement]

  • count (#to_i) (defaults to: 1)

See Also:

  • #kill
  • VER::Move#virtual_movement


29
30
31
# File 'lib/ver/methods/delete.rb', line 29

def kill_motion(motion, count = 1)
  kill(*virtual_movement(motion, count))
end