or in an autocmd to get the name of the file or the buffer number for which the autocommand is executed. For more information, read :help : :help : :help : 23.5. How do I automatically save all the changed buffers whenever Vim loses focus? You can define an autocommand for the FocusLost event which will save all the modified buffers whenever Vim loses focus: :autocmd FocusLost * wall For more information, read :help FocusLost :help :wall 23.6. How do I execute/run a function when Vim exits to do some cleanup? You can use VimLeave autocmd event to execute a function just before Vim exists. For example, :autocmd VimLeave * call MyCleanupFunction() For more information, read :help VimLeave ============================================================================= SECTION 24 – SYNTAX HIGHLIGHT 24.1. How do I turn off/on syntax highlighting? By default, the Vim syntax highlighting is turned off. To enable the syntax highlighting, you can use one of the