My own configuration and cheatsheet for vim, feel free to copy and make suggestions.
- Copy the .vimrc into your home directory (i.e. ~/) or symlink with
ln -s /path/to/vim-config/.vimrc ~/.vimrc
, - Install Vundle by running
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
, - Run
vim +PluginInstall +qall
in shell, or ":PluginInstall" in vim, to install all of the plugins with Vundle, - Symlink the language-dependent configurations (e.g. rb.vim or py.vim) to ~/.vim/ftplugin/LANGUAGE.vim,
- (Optional) Reload live vim sessions with the command
:source ~/.vimrc
.
I use this in conjunction with iTerm and Visual Studio Code's theme
In order for YouCompleteMe to work, follow the installation instructions on their Github page for your system. On MacOS, the plugin only works with MacVim, which can be installed with Brew - trying to open the plugin directly will freeze the terminal. To install MacVim, run brew install macvim
, and alias vim
with alias vim="mvim -v"
.
Gutentags is used to generate ctags. In order for the plugin to run, must install ctag
on your machine (i.e. sudo apt install exuberant-ctags
).
See their Gihub page for information.
YouCompleteMe is a plugin for vim that has support for autocomplete. To enable it, run cd ~/.vim/bundle/YouCompleteMe && ./install.py --all
to complete setup. See their Github page for more information on setup.
When the autcomplete shows up, use TAB key to cycle through suggestions or shift + TAB to cycle backwards.
CtrlP is a "Full path fuzzy file, buffer, mru, tag, ... finder for Vim".
To check what a key is current mapped, use nmap
.
grep -rnw './parent_path' -e 'keywords'
- In current pane, use
:e FILE_NAME
NERDTree is a tool for browsing files in a tree similar to those of IDEs.
ctrl + n
- toggle NERDTree (a file tree browser), can be changed in the .vimrc file- I (shift + i) - to toggle showing hidden files
- To select,
v
to select characters,V
to select whole lines, or use the mouse to highlight when mouse mode is enabled, - To copy,
y
for "yank", - To cut,
d
, - To paste before cursor press
P
. to paste after cursor pressp
.
Alternatively, in visual mode CTRL-c
copies and CTRL-x
cuts.
MacVim on MacOS and vim-gtk (should uninstall vim and install vim-gtk) should allow yank and cut to copy to system clipboard.
zc
closes a foldzo
opens a fold
:w
writes the current changes to disk,<CTRL> z
is a shortcut that writes changes to disk and changes back to normal mode.
In normal mode:
:u
or simply pressu
will undo a previous changectrl + r
will redo the previously undone change
:tabnew FILE_NAME
- open FILE_NAME in new tab:tabmove N
- move tab to Nth position, if argument is not provided, moves tab to the last position
vs filename
- open in new vertical splitsp filename
- open in new horizontal split
Resizing:
resize +5
to increase the height of the panevertical resize +5
to increase the width of the pane
Alternatively, ctrl-w +
and ctrl-w -
to resize the height of the current window, ctrl+w >
and ctrl+w <
to resize the width of the current window. To resize all windows, ctrl-w =
.
\ c <SPACE>
toggles commenting/uncomment of lines.
- Enter the command
:/
(forward) or:?
(backward), type in the search query, then hit to search. Hit to search for the next forward instance, and to search for the next backward instance :noh
clears the highlighted search terms- (Not specific to VIM, but helpful) Examples searching for files ending in ".erb" for the term "card-panel" -
grep -R --include "*.erb" "card-panel" .
These resources below are used as references to customize this .vimrc.