blob: 05b864fa7e58aa812c130001bce1134956f614ad [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001README for the Vim source code
2
3Here are a few hints for finding your way around the source code. This
4doesn't make it less complex than it is, but it gets you started.
5
6You might also want to read ":help development".
7
8
9JUMPING AROUND
10
11First of all, use ":make tags" to generate a tags file, so that you can use
12the ":tag" command to jump around the source code.
13
14To jump to a function or variable definition, move the cursor on the name and
15use the CTRL-] command. Use CTRL-T or CTRL-O to jump back.
16
17To jump to a file, move the cursor on its name and use the "gf" command.
18
19Most code can be found in a file with an obvious name (incomplete list):
20 buffer.c manipulating buffers (loaded files)
21 diff.c diff mode (vimdiff)
22 eval.c expression evaluation
23 fileio.c reading and writing files
24 fold.c folding
25 getchar.c getting characters and key mapping
26 mark.c marks
27 memfile.c storing lines for buffers in a swapfile
28 memline.c storing lines for buffers in memory
29 menu.c menus
30 message.c (error) messages
31 mbyte.c multy-byte character handling
32 ops.c handling operators ("d", "y", "p")
33 option.c options
34 quickfix.c quickfix commands (":make", ":cn")
35 screen.c updating the windows
36 search.c pattern searching
37 tag.c tags
38 term.c terminal handling, termcap codes
39 undo.c undo and redo
40 window.c handling split windows
41
42
43IMPORTANT VARIABLES
44
45The current mode is stored in "State". The values it can have are NORMAL,
46INSERT, CMDLINE, and a few others.
47
48The current window is "curwin". The current buffer is "curbuf". These point
49to structures with the cursor position in the window, option values, the file
50name, etc. These are defined in structs.h.
51
52All the global variables are declared in globals.h.
53
54
55THE MAIN LOOP
56
57This is conveniently called main_loop(). It updates a few things and then
58calls normal_cmd() to process a command. This returns when the command is
59finished.
60
61The basic idea is that Vim waits for the user to type a character and
62processes it until another character is needed. Thus there are several places
63where Vim waits for a character to be typed. The vgetc() function is used for
64this. It also handles mapping.
65
66Updating the screen is mostly postponed until a command or a sequence of
67commands has finished. The work is done by update_screen(), which calls
68win_update() for every window, which calls win_line() for every line.
69See the start of screen.c for more explanations.
70
71
72COMMAND-LINE MODE
73
74When typing a ":", normal_cmd() will call getcmdline() to obtain a line with
75an Ex command. getcmdline() contains a loop that will handle each typed
76character. It returns when hitting <CR> or <Esc> or some other character that
77ends the command line mode.
78
79
80EX COMMANDS
81
82Ex commands are handled by the function do_cmdline(). It does the generic
83parsing of the ":" command line and calls do_one_cmd() for each separate
84command. It also takes care of while loops.
85
86do_one_cmd() parses the range and generic arguments and puts them in the
87exarg_t and passes it to the function that handles the command.
88
89The ":" commands are listed in ex_cmds.h. The third entry of each item is the
90name of the function that handles the command. The last entry are the flags
91that are used for the command.
92
93
94NORMAL MODE COMMANDS
95
96The Normal mode commands are handled by the normal_cmd() function. It also
97handles the optional count and an extra character for some commands. These
98are passed in a cmdarg_t to the function that handles the command.
99
100There is a table nv_cmds in normal.c which lists the first character of every
101command. The second entry of each item is the name of the function that
102handles the command.
103
104
105INSERT MODE COMMANDS
106
107When doing an "i" or "a" command, normal_cmd() will call the edit() function.
108It contains a loop that waits for the next character and handles it. It
109returns when leaving Insert mode.
110
111
112OPTIONS
113
114There is a list with all option names in option.c, called options[].
115
116
117THE GUI
118
119Most of the GUI code is implemented like it was a clever terminal. Typing a
120character, moving a scrollbar, clicking the mouse, etc. are all translated
121into events which are written in the input buffer. These are read by the
122main code, just like reading from a terminal. The code for this is scattered
123through gui.c. For example: gui_send_mouse_event() for a mouse click and
124gui_menu_cb() for a menu action. Key hits are handled by the system-specific
125GUI code, which calls add_to_input_buf() to send the key code.
126
127Updating the GUI window is done by writing codes in the output buffer, just
128like writing to a terminal. When the buffer gets full or is flushed,
129gui_write() will parse the codes and draw the appropriate items. Finally the
130system-specific GUI code will be called to do the work.
131
132
133DEBUGGING THE GUI
134
135Remember to prevent that gvim forks and the debugger thinks Vim has exited,
136add the "-f" argument. In gdb: "run -f -g".
137
138When stepping through display updating code, the focus event is triggerred
139when going from the debugger to Vim and back. To avoid this, recompile with
140some code in gui_focus_change() disabled.