tree: e101371fc5f8348808082bb52171cc9dd0481222 [path history] [tgz]
  1. auto/
  2. GvimExt/
  3. if_perl_msvc/
  4. libvterm/
  5. os_mac_rsrc/
  6. po/
  7. proto/
  8. tee/
  9. testdir/
  10. VisVim/
  11. xdiff/
  12. xpm/
  13. xxd/
  14. alloc.h
  15. arabic.c
  16. ascii.h
  17. autocmd.c
  18. beval.c
  19. beval.h
  20. bigvim.bat
  21. bigvim64.bat
  22. blob.c
  23. blowfish.c
  24. buffer.c
  25. channel.c
  26. charset.c
  27. config.h.in
  28. config.mk.dist
  29. config.mk.in
  30. configure
  31. configure.ac
  32. create_cmdidxs.vim
  33. crypt.c
  34. crypt_zip.c
  35. dehqx.py
  36. dict.c
  37. diff.c
  38. digraph.c
  39. dimm.idl
  40. dlldata.c
  41. dosinst.c
  42. dosinst.h
  43. edit.c
  44. eval.c
  45. evalfunc.c
  46. ex_cmdidxs.h
  47. ex_cmds.c
  48. ex_cmds.h
  49. ex_cmds2.c
  50. ex_docmd.c
  51. ex_eval.c
  52. ex_getln.c
  53. feature.h
  54. fileio.c
  55. findfile.c
  56. fold.c
  57. getchar.c
  58. glbl_ime.cpp
  59. glbl_ime.h
  60. globals.h
  61. gui.c
  62. gui.h
  63. gui_at_fs.c
  64. gui_at_sb.c
  65. gui_at_sb.h
  66. gui_athena.c
  67. gui_beval.c
  68. gui_dwrite.cpp
  69. gui_dwrite.h
  70. gui_gtk.c
  71. gui_gtk_f.c
  72. gui_gtk_f.h
  73. gui_gtk_res.xml
  74. gui_gtk_vms.h
  75. gui_gtk_x11.c
  76. gui_mac.c
  77. gui_motif.c
  78. gui_photon.c
  79. gui_w32.c
  80. gui_w32_rc.h
  81. gui_x11.c
  82. gui_x11_pm.h
  83. gui_xmdlg.c
  84. gui_xmebw.c
  85. gui_xmebw.h
  86. gui_xmebwp.h
  87. gvim.exe.mnf
  88. gvimtutor
  89. hangulin.c
  90. hardcopy.c
  91. hashtab.c
  92. if_cscope.c
  93. if_cscope.h
  94. if_lua.c
  95. if_mzsch.c
  96. if_mzsch.h
  97. if_ole.cpp
  98. if_ole.h
  99. if_ole.idl
  100. if_perl.xs
  101. if_perlsfio.c
  102. if_py_both.h
  103. if_python.c
  104. if_python3.c
  105. if_ruby.c
  106. if_tcl.c
  107. if_xcmdsrv.c
  108. iid_ole.c
  109. indent.c
  110. infplist.xml
  111. insexpand.c
  112. INSTALL
  113. install-sh
  114. INSTALLami.txt
  115. INSTALLmac.txt
  116. installman.sh
  117. installml.sh
  118. INSTALLpc.txt
  119. INSTALLvms.txt
  120. INSTALLx.txt
  121. iscygpty.c
  122. iscygpty.h
  123. json.c
  124. json_test.c
  125. keymap.h
  126. kword_test.c
  127. link.390
  128. link.sh
  129. list.c
  130. macros.h
  131. main.c
  132. Make_all.mak
  133. Make_bc5.mak
  134. Make_cyg.mak
  135. Make_cyg_ming.mak
  136. Make_dice.mak
  137. Make_dvc.mak
  138. Make_ivc.mak
  139. Make_manx.mak
  140. Make_ming.mak
  141. Make_mint.mak
  142. Make_morph.mak
  143. Make_mvc.mak
  144. Make_sas.mak
  145. Make_vms.mms
  146. Makefile
  147. mark.c
  148. mbyte.c
  149. memfile.c
  150. memfile_test.c
  151. memline.c
  152. menu.c
  153. message.c
  154. message_test.c
  155. misc1.c
  156. misc2.c
  157. move.c
  158. msvc2008.bat
  159. msvc2010.bat
  160. msvc2015.bat
  161. msvcsetup.bat
  162. msys32.bat
  163. msys64.bat
  164. mysign
  165. nbdebug.c
  166. nbdebug.h
  167. netbeans.c
  168. normal.c
  169. ops.c
  170. option.c
  171. option.h
  172. os_amiga.c
  173. os_amiga.h
  174. os_beos.c
  175. os_beos.h
  176. os_beos.rsrc
  177. os_dos.h
  178. os_mac.h
  179. os_mac.rsr.hqx
  180. os_mac_conv.c
  181. os_macosx.m
  182. os_mint.h
  183. os_mswin.c
  184. os_qnx.c
  185. os_qnx.h
  186. os_unix.c
  187. os_unix.h
  188. os_unixx.h
  189. os_vms.c
  190. os_vms_conf.h
  191. os_vms_fix.com
  192. os_vms_mms.c
  193. os_w32exe.c
  194. os_win32.c
  195. os_win32.h
  196. osdef.sh
  197. osdef1.h.in
  198. osdef2.h.in
  199. pathdef.sh
  200. popupmnu.c
  201. proto.h
  202. protodef.h
  203. pty.c
  204. quickfix.c
  205. README.md
  206. regexp.c
  207. regexp.h
  208. regexp_nfa.c
  209. screen.c
  210. search.c
  211. sha256.c
  212. sign.c
  213. spell.c
  214. spell.h
  215. spellfile.c
  216. structs.h
  217. syntax.c
  218. tag.c
  219. tearoff.bmp
  220. term.c
  221. term.h
  222. terminal.c
  223. termlib.c
  224. textprop.c
  225. toolbar.phi
  226. toolcheck
  227. tools.bmp
  228. typemap
  229. ui.c
  230. undo.c
  231. uninstal.c
  232. userfunc.c
  233. version.c
  234. version.h
  235. vim.def
  236. vim.h
  237. vim.ico
  238. vim.rc
  239. vim.tlb
  240. vim_alert.ico
  241. vim_error.ico
  242. vim_icon.xbm
  243. vim_info.ico
  244. vim_mask.xbm
  245. vim_quest.ico
  246. vimio.h
  247. vimrun.c
  248. vimtutor
  249. which.sh
  250. winclip.c
  251. window.c
  252. xpm_w32.c
  253. xpm_w32.h
src/README.md

Vim Logo

Vim source code

Here are a few hints for finding your way around the source code. This doesn't make it less complex than it is, but it gets you started.

You might also want to read :help development.

Jumping around

First of all, use :make tags to generate a tags file, so that you can jump around in the source code.

To jump to a function or variable definition, move the cursor on the name and use the CTRL-] command. Use CTRL-T or CTRL-O to jump back.

To jump to a file, move the cursor on its name and use the gf command.

Most code can be found in a file with an obvious name (incomplete list):

File nameDescription
autocmd.cautocommands
buffer.cmanipulating buffers (loaded files)
diff.cdiff mode (vimdiff)
eval.cexpression evaluation
fileio.creading and writing files
findfile.csearch for files in 'path'
fold.cfolding
getchar.cgetting characters and key mapping
indent.cC and Lisp indentation
insexpand.cInsert mode completion
mark.cmarks
mbyte.cmulti-byte character handling
memfile.cstoring lines for buffers in a swapfile
memline.cstoring lines for buffers in memory
menu.cmenus
message.c(error) messages
ops.chandling operators ("d", "y", "p")
option.coptions
quickfix.cquickfix commands (":make", ":cn")
regexp.cpattern matching
screen.cupdating the windows
search.cpattern searching
sign.csigns
spell.cspell checking
syntax.csyntax and other highlighting
tag.ctags
term.cterminal handling, termcap codes
undo.cundo and redo
window.chandling split windows

Debugging

If you have a reasonable recent version of gdb, you can use the :Termdebug command to debug Vim. See :help :Termdebug.

When something is time critical or stepping through code is a hassle, use the channel logging to create a time-stamped log file. Add lines to the code like this:

ch_log(NULL, "Value is now %02x", value);

After compiling and starting Vim, do:

:call ch_logfile('debuglog', 'w')

And edit debuglog to see what happens. The channel functions already have ch_log() calls, thus you always see that in the log.

Important Variables

The current mode is stored in State. The values it can have are NORMAL, INSERT, CMDLINE, and a few others.

The current window is curwin. The current buffer is curbuf. These point to structures with the cursor position in the window, option values, the file name, etc. These are defined in structs.h.

All the global variables are declared in globals.h.

The main loop

This is conveniently called main_loop(). It updates a few things and then calls normal_cmd() to process a command. This returns when the command is finished.

The basic idea is that Vim waits for the user to type a character and processes it until another character is needed. Thus there are several places where Vim waits for a character to be typed. The vgetc() function is used for this. It also handles mapping.

Updating the screen is mostly postponed until a command or a sequence of commands has finished. The work is done by update_screen(), which calls win_update() for every window, which calls win_line() for every line. See the start of screen.c for more explanations.

Command-line mode

When typing a :, normal_cmd() will call getcmdline() to obtain a line with an Ex command. getcmdline() contains a loop that will handle each typed character. It returns when hitting CR or Esc or some other character that ends the command line mode.

Ex commands

Ex commands are handled by the function do_cmdline(). It does the generic parsing of the : command line and calls do_one_cmd() for each separate command. It also takes care of while loops.

do_one_cmd() parses the range and generic arguments and puts them in the exarg_t and passes it to the function that handles the command.

The : commands are listed in ex_cmds.h. The third entry of each item is the name of the function that handles the command. The last entry are the flags that are used for the command.

Normal mode commands

The Normal mode commands are handled by the normal_cmd() function. It also handles the optional count and an extra character for some commands. These are passed in a cmdarg_t to the function that handles the command.

There is a table nv_cmds in normal.c which lists the first character of every command. The second entry of each item is the name of the function that handles the command.

Insert mode commands

When doing an i or a command, normal_cmd() will call the edit() function. It contains a loop that waits for the next character and handles it. It returns when leaving Insert mode.

Options

There is a list with all option names in option.c, called options[].

The GUI

Most of the GUI code is implemented like it was a clever terminal. Typing a character, moving a scrollbar, clicking the mouse, etc. are all translated into events which are written in the input buffer. These are read by the main code, just like reading from a terminal. The code for this is scattered through gui.c. For example, gui_send_mouse_event() for a mouse click and gui_menu_cb() for a menu action. Key hits are handled by the system-specific GUI code, which calls add_to_input_buf() to send the key code.

Updating the GUI window is done by writing codes in the output buffer, just like writing to a terminal. When the buffer gets full or is flushed, gui_write() will parse the codes and draw the appropriate items. Finally the system-specific GUI code will be called to do the work.

Debugging the GUI

Remember to prevent that gvim forks and the debugger thinks Vim has exited, add the -f argument. In gdb: run -f -g.

When stepping through display updating code, the focus event is triggered when going from the debugger to Vim and back. To avoid this, recompile with some code in gui_focus_change() disabled.

Contributing

If you would like to help making Vim better, see the CONTRIBUTING.md file.

This is README.md for version 8.1 of the Vim source code.