38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/vice/parser.rb', line 38
def parsechar_command(vice, current_buffer, char)
buffer = vice.buffers[current_buffer]
raise 'parsechar called from command mode' unless vice.mode == :command
if @trail == ['m']
buffer.addmark char
vice.alert "added mark '" + char + "'"
@trail = []
return
elsif @trail == ["'"]
vice.alert 'mark not set' unless buffer.gotomark char
@trail = []
return
end
case char
when 'j'
buffer.cursor_down
when 'k'
buffer.cursor_up
when 'l'
buffer.cursor_right
when 'h'
buffer.cursor_left
when 'w'
if !@trail.empty?
if (@trail[0] == 'd' || @trail[0] == 'c') && buffer.currentline != ''
line_edited = buffer.currentline
slice_start = buffer.cursor.col
slice_end = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
amount = slice_end - buffer.cursor.col
amount += 1 if slice_end == buffer.currentline.length - 1
line_edited.slice! slice_start, amount
buffer.setline buffer.cursor.line, line_edited
end
vice.mode = :insert if @trail[0] == 'c'
@trail = []
else
buffer.cursor.col = Vice::Movement.w(buffer.currentline, buffer.cursor.col)
end
when 'W'
buffer.cursor.col = Vice::Movement.W(buffer.currentline, buffer.cursor.col)
when 'b'
buffer.cursor.col = Vice::Movement.b(buffer.currentline, buffer.cursor.col)
when 'B'
buffer.cursor.col = Vice::Movement.B(buffer.currentline, buffer.cursor.col)
when '$'
buffer.cursor.col = Vice::Movement.dollar buffer.currentline
when '0'
buffer.cursor.col = Vice::Movement.zero
when 'I'
buffer.cursor.col = 0
vice.mode = :insert
when 'i'
vice.mode = :insert
when 'A'
buffer.cursor.col = buffer.cols
vice.mode = :insert
when 'a'
buffer.cursor.col += 1 if buffer.cursor.col < buffer.cols
vice.mode = :insert
when 'O'
buffer.newline buffer.cursor.line
buffer.cursor.col = 0
vice.mode = :insert
when 'o'
buffer.newline buffer.cursor.line + 1
buffer.cursor_down
vice.mode = :insert
when 'x'
buffer.rmchar
buffer.cursor.col -= 1 if buffer.cursor.col > 0
when 'c'
if !@trail.empty? && @trail[0] == 'c'
buffer.setline buffer.cursor.line, ''
buffer.cursor.col = 0
vice.mode = :insert
@trail = []
else
@trail.push 'c'
end
when 'd'
if !@trail.empty? && @trail[0] == 'd'
if buffer.lines == 1
buffer.setline 0, ''
else
buffer.rmline
end
buffer.cursor.line -= 1 if buffer.lines <= buffer.cursor.line
buffer.cursor.col = 0
@trail = []
else
@trail.push 'd'
end
when 'g'
if !@trail.empty? && @trail[0] == 'g'
buffer.cursor.line = 0
buffer.cursor.col = 0
else
@trail.push 'g'
end
when 'G'
buffer.cursor.line = buffer.lines - 1
buffer.cursor.col = 0
when 'm'
@trail.push 'm' if @trail.empty?
when 't'
vice.next_buffer if !@trail.empty? && @trail[0] == 'g'
@trail = []
when 'T'
vice.prev_buffer if !@trail.empty? && @trail[0] == 'g'
@trail = []
when ';', ':'
vice.mode = :prompt
when "'"
@trail.push "'" if @trail.empty?
end
end
|