misc/vim: update README file
[nit.git] / misc / README.md
1 # gtksourceview (gedit and other GTK editors)
2 To install in your home, just link (or copy) the language definition file in ~/.local/share/gtksourceview-2.0/language-specs
3
4 # syntaxhighlighter
5
6 Nit brush for the Alex Gorbatchev's JS syntaxhighlighter.
7
8 To install the JS syntaxhighlighter, please refer to http://alexgorbatchev.com/SyntaxHighlighter/
9
10 Then can add the brush to your html page:
11
12         <script type="text/javascript" src="shBrushNit.js"></script>
13
14 # Vim
15
16 Vim is a powerful text editor and a favorite of the Nit team.
17 The `misc/vim` directory provides Vim support for Nit source files.
18
19 ## Install
20
21 The simpler way to install nit for vim is with [pathogen][1].
22
23     cd ~/.vim/bundle
24     ln -s /full/path/to/nit/misc/vim nit
25
26 Ensure that `~/.vimrc` contains
27
28     call pathogen#infect()
29     syntax on
30     filetype plugin indent on
31
32   [1]: https://github.com/tpope/vim-pathogen
33
34 ## Features
35
36  * Syntax highlighting
37  * Automatic indentation
38  * Syntax checker (require [Syntastic][2]).
39  * Autocomplete for whole projects using module importations
40  * Show documentation in preview window
41  * Search declarations and usages of the word under the cursor
42
43   [2]: https://github.com/scrooloose/syntastic
44
45 ## Autocomplete
46
47 The Nit plugin offers two kinds of autocompletion: complete and omnifunc.
48
49 You can use both completion at the same time. They each have their own strengths and weaknesses.
50
51 ### Complete
52
53 The Nit plugin can configure the `complete` option by scanning all projects in the
54 current directory, and their dependencies.
55
56 Add the following code to `~/.vimrc`, then use `ctrl-n` to open the
57 autocomplete popup.
58
59 ~~~
60 " Compute Nit module dependencies for autocomplete on loading our first Nit module
61 autocmd Filetype nit call NitComplete()
62
63 " Map reloading Nit module dependencies to F2
64 map <F2> :call ForceNitComplete()<enter>
65 ~~~
66
67 The plugin is compatible with, and optimized for, [AutoComplPop][3].
68
69 Look at the functions defined in `misc/vim/plugin/nit.vim` for all possible
70 usages.
71
72   [3]: http://www.vim.org/scripts/script.php?script_id=1879
73
74 ### Omnifunc
75
76 The Nit plugin also defines an omnifunc which uses metadata files produced by nitpick which
77 is called by syntastic.
78 It is activated by default when editing a Nit source file, launch it using `ctrl-x ctrl-o`.
79 It will suggest entities names from the current context and display the corresponding documentation.
80 Once the correct completion has been selected, you can close the documentation preview window with `:pc`.
81
82 The omnifunc applies a simple heuristic to recognize what kind of entities to display:
83 (This is a simplification some behaviors are missing.)
84
85 * If the cursor follows `import`, it will list known modules.
86 * If it follows `new` it will list known classes with their constructors.
87 * If it follows `super`, `class`, `isa` or `as` it will list known classes.
88 * If it follows a `.`, it will list properties.
89 * If on an extern method declaration, it will list classes and properties.
90 * Otherwise, it will list keywords and properties.
91
92 Make sure to save your Nit module if using syntastic or to manually call nitpick the generate
93 the metadata files before using the omnifunc. If there is no locally available metadata, it
94 will use general metadata in the plugin directory.
95
96 The metadata files from nitpick are stored in `~/.vim/nit/`. This location can be customized with
97 the environment variable `NIT_VIM_DIR`.
98
99 ## Documentation in preview window
100
101 The command `:Nitdoc` searches the documentation for the word under the cursor.
102 The results are displayed in the preview window in order of relevance.
103 You can search for any word by passing it as an argument, as in `:Nitdoc modulo`.
104 The Nitdoc command uses the same metadata files as the omnifunc.
105 You may want to map the function to a shortcut by adding the following code to `~/.vimrc`.
106
107 ~~~
108 " Map displaying Nitdoc to Ctrl-D
109 map <C-d> :Nitdoc<enter>
110 ~~~
111
112 ## Search declarations and usages of the word under the cursor
113
114 The function `NitGitGrep` calls `git grep` to find declarations and usages of the word under the cursor.
115 It displays the results in the preview window.
116 You may want to map the function to a shortcut by adding the following code to `~/.vimrc`.
117
118 ~~~
119 " Map the NitGitGrep function to Ctrl-G
120 map <C-g> :call NitGitGrep()<enter>
121 ~~~