Vimrc is the config file for Vim. Customizations in the config file to make using Vim a little nicer. The vimrc file can be found at ~/.vimrc.

Starting Fresh[4]

If things aren't working how you like, don't be afraid to start over with a fresh install by renaming your original .vimrc file and your .vim directory to .vimrc-bak and .vim-bak respectively, and creating a new blank file and empty directory in their place.


Command Effect
syntax on Turn on syntax highlighting
set number Use line numbers
set number relativenumber Use current line number and relative numbers for others


Remapping is where you can expand one keystroke into another keystroke or set of keystrokes. There are multiple types of remapping:

An example that would be in a vimrc file:

map j gg           (moves cursor to first line)
map Q j            (moves cursor to first line)
noremap W j        (moves cursor down one line)

The effect of this would be that:


map and noremap have different modes they can apply to:

An example being nnoremap will make a non-recursive mapping that only applied to normal mode.

Custom Commands[5]

A command is used in the command mode, which is accessed through :. A custom command is made using this format:

command[!] [CapitalizedCustomCommand] [vim command that will be run]

For example, if I wanted to create a custom command that would edit my global todo file, I could write command TODO e ~/.tod. This will execute e ~/.tod when I write :TODO while in command mode in Vim.


Vim will use it's own unnamed register unless specified to use the system clipboard. You can tell it to use the system clipboard on yank and paste by prefacing either with "+.[1]

To make Vim always use the system clipboard, you can add this to your ~/.vimrc file[1,2]:

# Non-Mac
set clipboard=unnamedplus
# Mac
set clipboard=unnamed

Language Specific Options[7,8]

You can set language specific options within the ~/.vim/ftplugin/ folder. For instance, a Python options file would be the file ~/.vim/ftplugin/python.vim. If the filetype is not initially recognized by Vim, you can add it to the ftdetect folder[11].

If you want to associate one format with another language, you can use the following to associate them:

" Make sure all types of *.txt are rendered with markdown syntax
autocmd BufNewFile,BufRead *.txt set ft=markdown

Trim Trailing Whitespace on Save[3]

Before writing the buffer to file on any file (*), search and replace all whitespace characters (\s) at the end of a given line with nothing. Do not show any error messages if no matches exist (e flag).

" Trim trailing whitespace on save
autocmd BufWritePre * :%s/\s\+$//e

Other Plugins and Packages



Last modified: 202208011808