tree: 24d9586c9c91dadaa7f5b925228ac4dad251e692 [path history] [tgz]
  1. auto/
  2. GvimExt/
  3. libvterm/
  4. po/
  5. proto/
  6. tee/
  7. testdir/
  8. xdiff/
  9. xpm/
  10. xxd/
  11. alloc.c
  12. alloc.h
  13. arabic.c
  14. arglist.c
  15. ascii.h
  16. autocmd.c
  17. beval.c
  18. beval.h
  19. bigvim.bat
  20. bigvim64.bat
  21. blob.c
  22. blowfish.c
  23. buffer.c
  24. bufwrite.c
  25. change.c
  26. channel.c
  27. charset.c
  28. cindent.c
  29. clientserver.c
  30. clipboard.c
  31. cmdexpand.c
  32. cmdhist.c
  33. config.h.in
  34. config.mk.dist
  35. config.mk.in
  36. configure
  37. configure.ac
  38. create_cmdidxs.vim
  39. create_nvcmdidxs.c
  40. create_nvcmdidxs.vim
  41. crypt.c
  42. crypt_zip.c
  43. debugger.c
  44. dict.c
  45. diff.c
  46. digraph.c
  47. dlldata.c
  48. dosinst.c
  49. dosinst.h
  50. drawline.c
  51. drawscreen.c
  52. edit.c
  53. errors.h
  54. eval.c
  55. evalbuffer.c
  56. evalfunc.c
  57. evalvars.c
  58. evalwindow.c
  59. ex_cmdidxs.h
  60. ex_cmds.c
  61. ex_cmds.h
  62. ex_cmds2.c
  63. ex_docmd.c
  64. ex_eval.c
  65. ex_getln.c
  66. feature.h
  67. fileio.c
  68. filepath.c
  69. findfile.c
  70. float.c
  71. fold.c
  72. gc.c
  73. getchar.c
  74. globals.h
  75. gui.c
  76. gui.h
  77. gui_beval.c
  78. gui_dwrite.cpp
  79. gui_dwrite.h
  80. gui_gtk.c
  81. gui_gtk_f.c
  82. gui_gtk_f.h
  83. gui_gtk_res.xml
  84. gui_gtk_vms.h
  85. gui_gtk_x11.c
  86. gui_haiku.cc
  87. gui_haiku.h
  88. gui_motif.c
  89. gui_photon.c
  90. gui_w32.c
  91. gui_w32_rc.h
  92. gui_x11.c
  93. gui_x11_pm.h
  94. gui_xim.c
  95. gui_xmdlg.c
  96. gui_xmebw.c
  97. gui_xmebw.h
  98. gui_xmebwp.h
  99. gvimtutor
  100. hardcopy.c
  101. hashtab.c
  102. help.c
  103. highlight.c
  104. if_cscope.c
  105. if_lua.c
  106. if_mzsch.c
  107. if_mzsch.h
  108. if_ole.cpp
  109. if_ole.h
  110. if_ole.idl
  111. if_perl.xs
  112. if_perlsfio.c
  113. if_py_both.h
  114. if_python.c
  115. if_python3.c
  116. if_ruby.c
  117. if_tcl.c
  118. if_xcmdsrv.c
  119. iid_ole.c
  120. indent.c
  121. insexpand.c
  122. INSTALL
  123. install-sh
  124. INSTALLami.txt
  125. INSTALLmac.txt
  126. installman.sh
  127. installml.sh
  128. INSTALLpc.txt
  129. INSTALLvms.txt
  130. INSTALLx.txt
  131. iscygpty.c
  132. iscygpty.h
  133. job.c
  134. json.c
  135. json_test.c
  136. keymap.h
  137. kword_test.c
  138. linematch.c
  139. link.390
  140. link.sh
  141. list.c
  142. locale.c
  143. logfile.c
  144. macros.h
  145. main.c
  146. Make_all.mak
  147. Make_ami.mak
  148. Make_cyg.mak
  149. Make_cyg_ming.mak
  150. Make_ming.mak
  151. Make_mvc.mak
  152. Make_vms.mms
  153. Makefile
  154. map.c
  155. mark.c
  156. match.c
  157. mbyte.c
  158. memfile.c
  159. memfile_test.c
  160. memline.c
  161. menu.c
  162. message.c
  163. message_test.c
  164. misc1.c
  165. misc2.c
  166. mouse.c
  167. move.c
  168. msvc-latest.bat
  169. msvc2015.bat
  170. msvc2017.bat
  171. msvc2019.bat
  172. msvc2022.bat
  173. msys32.bat
  174. msys64.bat
  175. mysign
  176. nbdebug.c
  177. nbdebug.h
  178. netbeans.c
  179. normal.c
  180. nv_cmdidxs.h
  181. nv_cmds.h
  182. ops.c
  183. option.c
  184. option.h
  185. optiondefs.h
  186. optionstr.c
  187. os_amiga.c
  188. os_amiga.h
  189. os_dos.h
  190. os_haiku.h
  191. os_haiku.rdef.in
  192. os_mac.h
  193. os_mac_conv.c
  194. os_macosx.m
  195. os_mswin.c
  196. os_qnx.c
  197. os_qnx.h
  198. os_unix.c
  199. os_unix.h
  200. os_unixx.h
  201. os_vms.c
  202. os_vms_conf.h
  203. os_vms_fix.com
  204. os_vms_mms.c
  205. os_w32dll.c
  206. os_w32exe.c
  207. os_win32.c
  208. os_win32.h
  209. osdef.sh
  210. osdef1.h.in
  211. osdef2.h.in
  212. pathdef.sh
  213. popupmenu.c
  214. popupwin.c
  215. profiler.c
  216. proto.h
  217. protodef.h
  218. pty.c
  219. quickfix.c
  220. README.md
  221. regexp.c
  222. regexp.h
  223. regexp_bt.c
  224. regexp_nfa.c
  225. register.c
  226. screen.c
  227. scriptfile.c
  228. search.c
  229. session.c
  230. sha256.c
  231. sign.c
  232. sound.c
  233. spell.c
  234. spell.h
  235. spellfile.c
  236. spellsuggest.c
  237. strings.c
  238. structs.h
  239. syntax.c
  240. tabpanel.c
  241. tag.c
  242. tearoff.bmp
  243. term.c
  244. termdefs.h
  245. terminal.c
  246. termlib.c
  247. testing.c
  248. textformat.c
  249. textobject.c
  250. textprop.c
  251. time.c
  252. toolbar.phi
  253. toolcheck
  254. tools.bmp
  255. tuple.c
  256. typemap
  257. typval.c
  258. ui.c
  259. undo.c
  260. uninstall.c
  261. usercmd.c
  262. userfunc.c
  263. version.c
  264. version.h
  265. vim.h
  266. vim.ico
  267. vim.manifest
  268. vim.rc
  269. vim.tlb
  270. vim9.h
  271. vim9class.c
  272. vim9cmds.c
  273. vim9compile.c
  274. vim9execute.c
  275. vim9expr.c
  276. vim9instr.c
  277. vim9script.c
  278. vim9type.c
  279. vim_alert.ico
  280. vim_error.ico
  281. vim_icon.xbm
  282. vim_info.ico
  283. vim_mask.xbm
  284. vim_quest.ico
  285. viminfo.c
  286. vimrun.c
  287. vimtutor
  288. wayland.c
  289. which.sh
  290. winclip.c
  291. window.c
  292. xpm_w32.c
  293. 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
alloc.cmemory management
arglist.chandling argument list
autocmd.cautocommands
blob.cblob data type
buffer.cmanipulating buffers (loaded files)
bufwrite.cwriting a buffer to file
change.chandling changes to text
cindent.cC and Lisp indentation
clientserver.cclient server functionality
clipboard.chandling the clipboard
cmdexpand.ccommand-line completion
cmdhist.ccommand-line history
debugger.cVim script debugger
diff.cdiff mode (vimdiff)
drawline.cdrawing a window line
drawscreen.cdrawing the windows
eval.cexpression evaluation
evalbuffer.cbuffer related built-in functions
evalfunc.cbuilt-in functions
evalvars.cvim variables
evalwindow.cwindow related built-in functions
fileio.creading and writing files
filepath.cdealing with file names and paths
findfile.csearch for files in 'path'
fold.cfolding
getchar.cgetting characters and key mapping
gc.cgarbage collection
help.cvim help related functions
highlight.csyntax highlighting
indent.ctext indentation
insexpand.cInsert mode completion
locale.clocale/language handling
map.cmapping and abbreviations
mark.cmarks
match.chighlight matching
float.cfloating point functions
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
mouse.chandling the mouse
ops.chandling operators ("d", "y", "p")
option.coptions
optionstr.chandling string options
popupmenu.cpopup menu
popupwin.cpopup window
profiler.cVim script profiler
quickfix.cquickfix commands (":make", ":cn")
regexp.cpattern matching
register.chandling registers
scriptfile.cruntime directory handling and sourcing scripts
screen.clower level screen functions
search.cpattern searching
session.csessions and views
sign.csigns
spell.cspell checking core
spellfile.cspell file handling
spellsuggest.cspell correction suggestions
strings.cstring manipulation functions
syntax.csyntax and other highlighting
tag.ctags
term.cterminal handling, termcap codes
testing.ctesting: assert and test functions
textformat.ctext formatting
textobject.ctext objects
textprop.ctext properties
time.ctime and timer functions
typval.cVim script type/value functions
undo.cundo and redo
usercmd.cuser defined commands
userfunc.cuser defined functions
viminfo.cviminfo handling
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 9.1 of the Vim source code.