This page is designed to help you get Vim to help you!
Vim has a long history and a massive amount of commands, keyboard shortcuts, and more.
This guide brings to you the most commonly used and most useful commands for writing C/C++ code in vim.
All of the commands here are case-sensitive, so watch your Shift key and Caps Lock.
If you've taken CSE 391, then you may remember that there is a file called .bashrc
which lives in your home directory and contains commands that are run whenever you log in.
The .vimrc
file is similar to this, except it contains vim commands that will be run whenever you open a file in vim.
These commands can do things like change the color theme, turn on line numbers and enable syntax highlighting.
If you run the command below on attu or the CSE VM, you can download a .vimrc
file that has been created by the TAs that should make your vim experience a lot better.
You can read the comments in the file to see exactly what each command is doing.
Additionally, this command will place another configuration file in the folder ~/.vim/after/ftplugin/c.vim
which contains commands that will only be run when you open a C or C++ file.
.vimrc
:curl -o ~/.vimrc https://courses.cs.washington.edu/courses/cse333/20wi/vim/vimrc.txt && curl --create-dirs -o ~/.vim/after/ftplugin/c.vim https://courses.cs.washington.edu/courses/cse333/20wi/vim/c_vim.txt
.vimrc
:F9
to run make (you can also just do :make
).
Then, you can run :copen
to see the output alongside your code.
Vim will even take you to the lines that have compiler problems.
:Man <page number> <function>
.'ron'
.
Instructions for changing this are in the .vimrc
file.
i |
– | Enter 'input mode', which allows you to edit text but you can't run commands |
Esc |
– | Exit 'input mode' or 'visual mode' (see v ) |
:w |
– | Save the changes you have on the current file |
:q |
– | Close the file you are currently editing |
:wq or ZZ |
– | Save the changes you have on the current file and close it |
:q! |
– | Close the file you are currently editing without saving |
:! <command> |
– | Run <command> in your current shell |
:<number> or <number>G |
– | Go to line <number> |
u |
– | Undo the last change |
Ctrl+r |
– | Redo the last undo |
v |
– | Start highlighting by character ('visual mode' or 'selection mode') |
V |
– | Start highlighting by line |
y |
– | Copy/yank current selection |
yy |
– | Copy/yank current line |
d |
– | Cut/delete current selection |
dd |
– | Cut/delete current line |
p |
– | Paste the last thing that was cut/copied after the cursor |
P |
– | Paste the last thing that was cut/copied before the cursor |
/<regular expression> |
– | Search for occurrences of <regular expression> |
n |
– | Go to the next occurrence of the search term |
N |
– | Go to the previous occurrence of the search term |
:noh |
– | Stop highlighting occurrences of the current search term |
:e <filename> |
– | Open <filename> in the current window |
:split <filename> or :sp <filename> |
– | Split the current window in two, horizontally, and open <filename> in the new window |
:vsplit <filename> or :vs <filename> |
– | Split the current window in two, vertically, and open <filename> in the new window |
Ctrl+w Ctrl+w |
– | Move clockwise to the next window |
Ctrl+w → or Ctrl+w l |
– | Move to the window to the right of the current one |
Ctrl+w ↑ or Ctrl+w k |
– | Move to the window above the current one |
Ctrl+w ← or Ctrl+w h |
– | Move to the window to the left of the current one |
Ctrl+w ↓ or Ctrl+w j |
– | Move to the window below the current one |
Ctrl+w x |
– | Exchange the current window with the next one in the current row/column |
Ctrl+w L |
– | Move the current window to occupy the right side of the screen |
Ctrl+w K |
– | Move the current window to occupy the top of the screen |
Ctrl+w H |
– | Move the current window to occupy the left side of the screen |
Ctrl+w J |
– | Move the current window to occupy the bottom of the screen |
Ctrl+w = |
– | Have all windows take up an equal space of their row/column |
<number> Ctrl+w + |
– | Increase window height by <number> |
<number> Ctrl+w - |
– | Decrease window height by <number> |
<number> Ctrl+w > |
– | Increase window width by <number> |
<number> Ctrl+w < |
– | Decrease window width by <number> |