-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathgamslist.vim
More file actions
226 lines (215 loc) · 5.18 KB
/
Copy pathgamslist.vim
File metadata and controls
226 lines (215 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
" ABOUT
" -----
"
" vim script to process GAMS listing files
" the main objective is to help reviewing solver output of large models
" by hiding (folding) large parts of the listing file
"
" (the script builds on Antonio Colombo's f.vim script)
"
" :call MODLIST()
" Everything is folded except variables, equation and parameters
" => you get a quick overview of the model structure and are able
" to jump to the relevant positions. Then simply unfold the relevant
" parts.
"
" :cal MOREX()
" You can add additional search term that will not be folded.
" Example: search for a country name then single equations and variables
" defined for that country remain visible
"
" INSTALLATION
" ------------
"
" :so gamslist.vim
"
" You can map the functions to a function key in your vimrc file:
" map <F6> :call MOREX() <CR>
"
" [you can find me on github: trialsolution]
" :call F()
" This function lets you see all the lines in a file
" that contain a given regular-expression.
"
" The remaining lines are folded with the manual method,
" and can be opened to see some 'nearby' line.
"
" If no regular expression is specified, the last regular expression
" speicified for search is utilized.
"
" The idea comes from the mainframe ISPF editor.
"
" zo to open a fold a bit
" zozj to open a fold a bit and leave the cursor on the fold line
" zO to open a fold completely
" zE to open all folds
"
" zf{motion} to close folders 'a bit more' (or to create folders)
" If you have 2 adjacent folders, zf<ENTER> will 'merge' them.
" In the same way a visible line can be 'added' to a nearby folder.
"
" :call FA()
" This function is similar to F() above, except instead of typing in
" a regular expression, the current word the cursor is over is used as
" the regular expression.
"
" The function FA() has been prepared and added by:
" Ken Huisman - ken.huisman@gmail.com
"
" Suggested mappings:
" :map <F5> :call F()<CR>
" :map <F6> :normal zozj<CR>
" :set backspace=indent,eol,start
" the above setting allows you to go back/forward with "w","b" etc.
" thus opening "a bit" a nearby folder
"
" :map <F1> :call FA()<CR>
" :map <F2> zR
" useful for finding all instances of the current word quickly and then
" opening all the folds when you are done.
"
" :<Up> to recall the macro after having executed it once
" giving <Up> as an argument, last searches can be repeated/modified
"
" try giving as an expression nfold
" try giving as an expression as
" try giving as an expression as [that is: ' as' ]
" try giving as an expression let
" try giving as an expression ^":
" try giving as an expression :fun\|:endf
" try giving as an expression :endf
" try giving as an expression ^:endf
"
" for remarks, complaints, etc. write to: azc100@gmail.com
" Thanks to Michael Fitz (Wien -AT), Jean-Marc Frigerio
" Alexander Langer, and Paul Wei
" for corrections, suggestions and enhancements.
" version 05051001
:fun! s:Foldft(from,to) range
"makes folds from "a:from" to "a:to"
":echo a:from a:to "fold"
:let range=a:to-a:from
:if ( range<0 )
:retu
:en
:if ( range<3 )
:exe a:from "," a:to "fold"
:retu
:en
:let center=range/2
:wh ( center>=0 )
:let f=a:from+center
:let t=a:to-center
":echo range center f t
:exe f "," t "fold"
:if ( center>999 )
: let center=center-500
:else
: if ( center>=99 )
: let center=center-50
: else
: if ( center>=9 )
: let center=center-5
: else
: let center=center-1
: en
: en
:en
:endw
:endf
:fun! F2(larg) range
:let arg=a:larg
exec "normal /" . arg . "/"
":nohl
" for use inside :help
set foldenable
set foldmethod=manual
set foldminlines=0
set foldtext=
let idx=0
let lastline= line("$")
let nfold=0
let nFound=0
let nLines=0
norm G$
norm zE
let fromline=1
while idx<lastline
if ( idx==0 )
let num=search(arg)
else
let num=search(arg,"W")
endif
" search gives back the column number...
if ( num==0 )
break
endif
if ( num!=0 )
let nFound=1
let toline=num-1
if toline>=fromline
call s:Foldft(fromline,toline)
let nfold=nfold+1
en
let fromline=num+1
":echo "line" num "found" arg "at col" col(".")
":echo "----+----1----+----2----+----3----+----4----+----5----+----6----+-----7"
":p
let nLines=nLines+1
norm $
let idx=line(".")
endif
endwhile
if fromline<=lastline && fromline!=1
let toline=lastline
call s:Foldft(fromline,toline)
let nfold=nfold+1
en
norm 1G
if (nFound)
call histadd("/",arg)
exec "normal" "/" . arg . "/"
exec "match Search /\\c" . arg . "/"
if (!nfold)
echo "Expression on each line:" arg
endif
if ( nLines>1 )
echo nLines "lines found"
else
echo nLines "line found"
endif
return ("/" . arg . "/")
else
echo "Expression not found:" arg
return ("")
endif
:endf
:fun! FA() range
:let arg=expand("<cword>")
:let linenum=line(".")
:let colnum=col(".")
call F2(arg)
call cursor(linenum,colnum)
:endf
:fun! MODLIST() range
:let arg="^---- VAR\\|^---- EQU\\|PARAMETER\\|SOLVE"
if strlen(arg)<1
:let arg=@/
endif
call F2(arg)
:endf
:fun! F() range
:let arg=input("Which expression? ")
if strlen(arg)<1
:let arg=@/
endif
call F2(arg)
:endf
:fun! MOREX() range
:let arg=input("Which expression? ")
if strlen(arg)<1
:let arg=@/
endif
:let arg="^---- VAR\\|^---- EQU\\|PARAMETER\\|SOLVE\\|" . arg
call F2(arg)
:endf