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