Useful Vim Commands
A practical note for commonly used vim commands.
Common file opening and navigation commands
:e <file_path>: Open a file in the current window.:tabnew <file_path>: Open a file in a new tab.:vnew <file_path>: Open a file in a new vertical split.:new <file_path>: Open a file in a new horizontal split.vim <file_path>: Open a file directly from the command line.:Exor:Explore: Open the file explorer to navigate and open files.gf: Open the file under the cursor (useful for opening files linked in code, e.g., header files in C/C++).:find <file_name>: Search for a file in the current path and open it if found.:tabfind <file_name>: Search for a file in the current path and open it in a new tab if found.:vsplit <file_name>: Search for a file in the current path and open it in a vertical split if found.:split <file_name>: Search for a file in the current path and open it in a horizontal split if found.<C-]>: Jump to the definition of the tag under the cursor (requires ctags to be set up).:b <buffer_number>: Switch to a specific buffer by its number.:lsor:buffers: List all open buffers and their numbers for easy navigation.:tabnextor:tabn: Move to the next tab.:tabprevor:tabp: Move to the previous tab.:tabfirst: Move to the first tab.:tablast: Move to the last tab.:w <file_path>: Save the current file with a new name or path.:wa: Save all open files.:q: Quit the current window.:qa: Quit all windows and exit Vim.:wq: Save the current file and quit.:x: Save the current file and quit (same as:wq).:wqa: Save all open files and quit.:tabclose: Close the current tab.:tabonly: Close all tabs except the current one.:bd: Close the current buffer (useful for closing files without closing the window).:bwipeout: Close the current buffer and remove it from the buffer list.
reading and loading external configuration file from .vimrc
source <full_file_path>: Load and execute Vim commands from an external file. This requires the file to be in Vim script format.so <file_path>: This is a shorthand forsource.runtime <file_name>: Load a file from Vim’s runtime path, which is useful for loading plugins or configuration files that are placed in standard locations (e.g.,~/.vim/or/usr/share/vim/).- automatic loading at startup if the file is placed in the
~/.vim/plugin/directory. Do not need asourcecommand in yourvimrc.
This post is licensed under
CC BY 4.0
by the author.