]> Dogcows Code - chaz/vimcoder/blob - README.md
add gitignore file
[chaz/vimcoder] / README.md
1
2 Vim + TopCoder = VimCoder
3 =========================
4
5 ![VimCoder Logo](http://chazmcgarvey.github.com/vimcoder/img/vimcoder.png)
6
7 This plug-in makes it easy to use [Vim](http://www.vim.org/) as your
8 text editor in the [TopCoder Competition Arena](http://topcoder.com/tc).
9 It aims to be minimal in comparison to other editors such as
10 [KawigiEdit](http://topcoder.yajags.com/) or
11 [CodeProcessor](http://www.topcoder.com/tc?module=Static&d1=applet&d2=plugins)
12 plug-in chains while also providing enough functionality to also be useful.
13
14 Features
15 --------
16
17 * Works on any platform that the TopCoder Arena applet itself supports.
18 * Works with any language supported by TopCoder.
19 * Keeps track of your code files locally so you always have a copy.
20 * Downloads and stores a copy of the problem statement with your code for
21 off-line viewing.
22 * Has support for simple templates (default templates provided only for C++
23 and Java).
24 * Test-case "drivers" can be generated locally with the example test-case data
25 (currently C++ only).
26
27 License
28 -------
29
30 This software is licensed according to the terms and conditions of the
31 [BSD 2-Clause License](http://www.opensource.org/licenses/bsd-license.php).
32 Please see the COPYING file for more information.
33 This project is neither supported nor endorsed by TopCoder, Inc.
34
35 Download
36 --------
37
38 The latest VimCoder jar file can be downloaded from the
39 [vim.org script page](http://www.vim.org/scripts/script.php?script_id=3321).
40
41 Install
42 -------
43
44 Unfortunately, installation is a bit cumbersome, but it is what it is:
45
46 1. Download the latest version of the VimCoder jar file.
47 2. Run the TopCoder Arena applet and log in.
48 3. Click the "Options" menu and select "Editor" to show the editor
49 preferences.
50 4. Click the "Add" button to bring up a new window.
51 5. For "Name," type "Vim" or whatever you want to represent this plug-in.
52 6. For "EntryPoint," type "com.dogcows.VimCoder" without the quotes.
53 7. For "ClassPath," click on "Browse" and locate the VimCoder jar file. The
54 third field should now have the path to the jar file.
55 8. Click "OK" to close the window with the three fields.
56 9. Click "Save."
57
58 You should now be able select "Vim" (or whatever you entered the first
59 field) as your editor from the pull-down list on any problem statement
60 window.
61
62 Configure
63 ---------
64
65 Depending on your preference or system attributes, you may want or need to
66 first configure the plug-in so that it will work how you want it to. You can
67 bring up the plug-in preferences window by following these steps:
68
69 1. Run the TopCoder Arena applet and log in.
70 2. Click the "Options" menu and select "Editor."
71 3. In the new window, make sure the entry for VimCoder is selected from the
72 list, and click the "Configure" button.
73
74 ![VimCoder Preferences](http://chazmcgarvey.github.com/vimcoder/img/prefs.png)
75
76 ##### Storage Directory
77
78 VimCoder saves the problem files and the code you're working on in
79 a particular directory you can set. By default, this directory is `.vimcoder`
80 in your home directory. This is an "invisible" directory on most systems.
81 Within this storage directory are several sub-directories, one for each
82 problem you open. Each sub-directory is named after the problem identifier
83 and contains your source code and other files related to the problem.
84
85 If you want to change the storage directory, click the "Browse" button in the
86 VimCoder preferences window and navigate to the directory you would like to
87 use. If you have already saved some problems to the previous storage
88 directory, you may also want to actually move the directory to the new
89 location so that VimCoder can find the work you've already done.
90
91 ##### Vim Command
92
93 By default, VimCoder tries to invoke Vim using the `gvim` command (or
94 `C:\WINDOWS\gvim.bat` on Windows). This will typically work just fine unless
95 you don't have gvim in your PATH (or your installation of Vim on Windows
96 didn't include the wrappers for the command line). If you get errors about
97 the vim process not being able to run and no Vim session comes up when you use
98 the VimCoder plug-in, you need to either make sure the Vim command exists in
99 your PATH, or else change the Vim command in the VimCoder preferences window
100 to something else.
101
102 You may use an absolute path to your vim executable, such as
103 `/usr/local/bin/gvim` or `C:\Program Files\Vim\vim73\gvim.exe`
104 or wherever your actual Vim executable is. You may also invoke vim through
105 some other command (e.g. `xterm -e vim`).
106
107 The xterm example demonstrates using Vim without the GUI, running in
108 a terminal emulator. You can enter any elaborate command you want as long Vim
109 ultimately gets executed with the arguments that will be appended to the
110 command when it is invoked. After changing this value and saving your
111 preferences, the command you enter will be used the next time you open
112 a problem.
113
114 Usage
115 -----
116
117 To use VimCoder once it is installed and configured, go to a room in the
118 TopCoder Arena applet and open one of the problems. If you have set VimCoder
119 as your default editor, you will see the usual problem statement window come
120 up as well as a Vim editor window. Otherwise, you can change the editor from
121 the problem statement window, and the Vim editor window will come up. You
122 will see that the area usually devoted to editor will be used for log
123 messages; you will do your actual coding in the Vim window that comes up.
124
125 Just enter your code into the Vim window and use the regular TopCoder Arena
126 applet buttons to compile, test, and submit your code.
127
128 **Pro Tip:** If you accidentally close your Vim session, you can get it back
129 by switching to a different editor and then switching back to VimCoder.
130 Alternatively, the session will also reappear if you switch languages.
131
132 Storage Directory Structure
133 ---------------------------
134
135 Knowing about the files created by VimCoder is useful if you ever need to do
136 anything advanced with VimCoder.
137
138 When you open a problem, VimCoder will check to see if you have already opened
139 that problem by looking for the problem and solution files. If these files
140 are found, it will load your previous work. Otherwise, it will fill out the
141 templates based on the problem class name, parameter types, and so on, and
142 will create several files in a sub-directory of the main storage directory:
143
144 ##### `$CLASSNAME$`.`$LANGUAGE$`
145
146 This is the file where you write your solution code. If the class name for
147 the problem was BinaryCode and your language was Java, the name of this file
148 would be `BinaryCode.java`. When you open a problem, Vim will load this file
149 into a new buffer so that you can start coding. If there is a template for
150 the language you're using, that template will be used to fill in this file to
151 give you a reasonable place to start. When you save your code to TopCoder or
152 compile remotely, this is also the file that will be read to provide the code
153 for your solution.
154
155 ##### testcases.txt
156
157 This file contains the example test cases that are associated with the
158 problem. The format is pretty simple. For each test case, there is one line
159 for the expected return value followed by each of the method parameters, each
160 on its own line. This file is typically read by the driver program (more on
161 this later) in order to run the test cases against your code. While you are
162 coding a solution, you may also want to add additional test cases to make sure
163 your code is doing what you think it is and to make sure your code doesn't
164 mess up on edge cases for which an example test case was not provided.
165
166 ##### Problem.html
167
168 This file contains the problem statement which is what you see in the top half
169 of the problem window. You can load this in a browser to read the particulars
170 of the problem when you aren't running the TopCoder Arena applet. You
171 typically shouldn't edit this file.
172
173 ##### Makefile
174
175 If there exists a Makefile template for the selected language, it will also be
176 filled out and saved in the problem directory. The purpose of the Makefile is
177 to compile your code locally. You can execute targets in the Makefile using
178 Vim's `:make` command. You also shouldn't need to edit this file directly.
179 Exactly what happens when you use the `:make` command depends on the Makefile
180 template.
181
182 If you are using the default Makefile template for C++, typing ":make" without
183 any arguments will compile your code. Typing ":make run" will run all of the
184 test cases against your code. Typing ":make test" will also run the test
185 cases against your code, up until the first failed test at which point it will
186 abort.
187
188 A Makefile template is not yet provided for any other language, but you can
189 write one yourself if you are so inclined. Read on to learn how templates
190 work.
191
192 **Important:** Make sure you understand the difference between compiling
193 locally and compiling remotely (on the TopCoder servers). If you use the
194 Makefile to compile your solution (and maybe run the tests), you are not
195 interacting with the TopCoder servers at all. When you compile *remotely*,
196 you are sending a snapshot of your current solution to the servers for
197 processing. The distinction becomes important when it comes time for you to
198 submit your solution. When you push the "Submit" button, you are submitting
199 the **last version that was uploaded to the TopCoder servers** (by compiling
200 remotely), and that may be different from what is currently in your Vim
201 buffer, even if your Vim buffer was saved to disk. Therefore, it is very
202 important that you get into the habit of always pushing the "Compile" button
203 right before you submit your code. This point can't be overemphasized.
204
205 ##### driver.`$LANGUAGE$`
206
207 If there exists a driver template for the selected language, it will also be
208 filled out and saved in the problem directory. If the language was currently
209 set to C++, the driver code would be in the driver.cc file. You normally
210 don't have to do anything with this file. It just provides supporting code
211 for running the test cases against your code.
212
213 A default driver template is currently only provided for the C++ language.
214 You could write your own template if you wanted to.
215
216 ##### `$CLASSNAME$`
217
218 Sometimes the TopCoder Arena applet will pass back what source code it has
219 saved. This will be saved in a file named after the class, without any file
220 extension. You can open this file if you need to access this code for any
221 reason (say, you messed up some code and need to revert back to the last time
222 you saved from the TopCoder Arena applet).
223
224 Templates
225 ---------
226
227 VimCoder comes with default templates for C++ and Java, but you can create
228 your own customized templates for any language supported by TopCoder. To use
229 your own template, you need to add a file to the storage directory with a file
230 name depending on the language. The file name should start with the name of
231 the language and end with "Template" with no other file extension. For
232 example, if you wanted to create a C# template and your storage directory was
233 `/home/foo/.topcoder`, you would need to create the file
234 `/home/foo/.topcoder/C#Template`.
235
236 A template is like a regular source code file with special keywords that will
237 be replaced as the template is "filled out" whenever you open a new problem.
238 Keywords are surrounded by two dollar signs so they're not confused with other
239 parts of the source code. The template expansion process is rather
240 simplistic, so if you can't get the right format for the terms you need, you
241 might have to change the plug-in source code to get the effect you're trying
242 to achieve. Here are the possible keywords and replacement terms:
243
244 ##### `$CLASSNAME$`
245
246 This keyword is replaced by the name of the class you must use in your
247 solution to the problem.
248
249 ##### `$METHODNAME$`
250
251 This keyword is replaced by the name of the public method your class needs to
252 have.
253
254 ##### `$RETURNTYPE$`
255
256 This keyword is replaced by the type of the return variable of your public
257 method.
258
259 ##### `$METHODPARAMS$`
260
261 This keyword is replaced by a comma-separated list of method parameter types
262 and names.
263
264 ----
265
266 Other keywords are also available, but the rest are intended to be used in
267 driver or Makefile templates. You can also create these templates by adding
268 specially-named files to the storage directory. Driver templates are named
269 starting with the name of the language and ending with "Driver" with no other
270 file extension. Similarly, Makefile templates are named starting with the
271 name of the language and ending with "Makefile" with no other file extension.
272
273 Drivers provide additional code to implement running the test cases.
274 Currently, a default driver template is only provided for C++. Makefiles
275 should have the commands needed to compile the solution source code and/or
276 make a driver program that will perform the tests. Since there is only
277 a driver template for C++, there is similarly only a default Makefile template
278 provided for C++. If you want automatic building and testing for one of the
279 other languages, you will need to create a driver and Makefile template for
280 that language. Here are more keywords that may be useful for these types of
281 templates:
282
283 ##### `$METHODPARAMDECLARES$`
284
285 This keyword is replaced by C-style declarations of the method parameters. In
286 other words, each parameter is declared with its type on its own line
287 terminated by a semicolon.
288
289 ##### `$METHODPARAMNAMES$`
290
291 This keyword is replaced by a comma-separated list of only the method
292 parameter names.
293
294 ##### `$METHODPARAMSTREAMOUT$`
295
296 This keyword is replaced by a list of the method parameter names separated by
297 the C++ output stream operator (<<). The C++ driver template uses this to
298 display the input values of the test case data.
299
300 ##### `$METHODPARAMSTREAMIN$`
301
302 This keyword is replaced by a list of the method parameter names separated by
303 the C++ input stream operator (>>). The C++ driver template uses this to read
304 in the test case data from testcases.txt.
305
306 ----
307
308 To give you an idea of how this all fits together, here is an example template
309 for Java:
310
311 ```java
312 import static java.lang.Math.*;
313 import static java.math.BigInteger.*;
314 import static java.util.Arrays.*;
315 import static java.util.Collections.*;
316 import java.math.*;
317 import java.util.*;
318
319 public class $CLASSNAME$ {
320 public $RETURNTYPE$ $METHODNAME$($METHODPARAMS$) {
321 }
322 }
323 ```
324
325 Something like this should be saved in a filed named `JavaTemplate` in your
326 VimCoder storage directory.
327
328 Potential Pitfalls
329 ------------------
330
331 ##### Vim Client/Server
332
333 VimCoder requires Vim's client/server feature in order to work. If the log is
334 showing errors with the invocation of Vim or if it's just not working and has
335 other strange symptoms, make sure your version of Vim supports the
336 client/server feature. If you are unsure, use Vim's `:version` command and
337 look for "+clientserver" in the output. If you see "-clientserver" instead,
338 then you'll need to get yourself another version of Vim.
339
340 I think this feature was introduced in Vim 6.x, but I haven't done any testing
341 with any versions of Vim less than 7.2. If you're still on 6.x, you should
342 really upgrade anyway.
343
344 ##### Vim Settings Not Applied
345
346 The problem is that sometimes your settings (in your vimrc file) are not being
347 applied as you would expect. This may be because you are using `setlocal` in
348 your vimrc file rather than `set`. The `setlocal` command applies settings
349 only to the current buffer or window (see `:help setlocal` for more
350 information), but VimCoder works by first launching Vim and then loading
351 a brand new buffer.
352
353 The solution is to consider whether or not such settings should actually be
354 global; if they should be global, change `setlocal` to `set` in your vimrc
355 file. Alternatively, if you want certain settings to be set only for certain
356 kinds of buffers, you can use the `autocmd` command to selectively set
357 settings according to file path pattern and various events.
358 See `:help autocmd` for more information.
359
This page took 0.049283 seconds and 4 git commands to generate.