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/22sp/resources/vimrc.txt && curl --create-dirs -o ~/.vim/after/ftplugin/c.vim https://courses.cs.washington.edu/courses/cse333/19au/resources/c_vim.txt
(or download the file using the link on the course resources web page).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’, allows you to edit text but you can’t run commands
exc
- Exit ‘input mode’/’selection 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>
- go to line <number>
u
- Undo the last change
ctr+r
- Redo the last change the last undo
v
- Start highlighting by character ('selection mode')
V
- Start highlighting by line
y
- Copy current selection
yy
- Copy current line
d
- Delete/Cut current selection
dd
- Delete/Cut current line
p
- Past the last thing that was cut/copied
P
- Paste the last thing that was cut/copied before the cursor
/<regular expression>
- Search for occurrences of
<regular expressions>
n
- Go to the next occurrence of the search term
N
- Go to the previous occurrence of the search team
:noh
- Stop highlighting ocurrences of the current search term
:sp <filename>
- Split the current window in two,
horizontally, and open <filename>
in the new window
:sp <filename>
- Split the current window in two,
vertically, and open <filename>
in the new window
ctr+w ctr+w
- Move clockwise to the next window
ctr+w →
or ctr+w l
- Move to the
window to the right of the current one
ctr+w ↑
or ctr+w k
- Move to the
window above the current one
ctr+w ←
or ctr+w h
- Move to the
window to the left of the current one
ctr+w ↓
or ctr+w j
- Move to the
window below the current one
ctr+w x
- Exchange the current window with the next one
in the current row/column
ctr+w L
- Move the current window to occupy the right
side of the screen
ctr+w K
- Move the current window to occuppy the top
of the screen
ctr+w H
- Move the current window to occupy the left
side of the screen
ctr+w J
- Move the current window to occupy the bottom
of the screen
ctr+w =
- Have all windows take up an equal space of
their row/column
<number> ctr+w +
- Increase window height by
<number>
<number> ctr+w -
- Decrease window height by
<number>
<number> ctr+w >
- Increase window width by
<number>
<number> ctr+w <
- Decrease window width by
<number>