Hello! This is the markdown transcript for a presentation held on October 13th. You can view the writeup in PDF format here.
Note that the first section discussing why Vim? and History were cut due to recording errors. Sorry about that!
Why Vim?
ex
command line text
editor.vim
) was created by Bram Moolenaar in 1988
as a clone of vi
.vim
is a superset of vi
, introducing new
features such as syntax highlighting, undo/redo, screen splitting, and
plugin support.vi
, vim
has also been ported to a
wide range of OS’s.vim
and its derivatives make up one of the most
most popular text editor families.We will try to learn:
vim
vim
without restarting your computer...1Modes vim
is known for a modal editing
scheme.
What is modal editing?
In vim
, various things that you typically do while
editing text is split into different modes.
Mode | Purpose | How to Enter |
---|---|---|
Normal | Move around and manipulate existing text | Default, can return to by pressing in other modes |
Insert | Allows you to type text like in any standard editor | i , a ,
x , c , o , among others in Normal
mode |
Visual | Allows you to select regions of text as if you were using a mouse | v , Shift + v ,
Ctrl + v in Normal mode |
Command | Allows you to execute commands like save and exit | : in Normal mode |
There are other additional modes that vim
has
out-of-the-box, but these are the basics.
Why should editing be split into modes?
Modes allow for vim
perform actions using simple and
easy to remember keystroke sequences! These are known as motions!
Navigating can be done with h
, j
,
k
, l
in Normal mode. These corrispond to
<Left>
, <Down>
,
<Up>
, <Right>
respectively.2
This allows you to keep your hands on the home-row of your keyboard (especially good if you are a touch-typist)!
Additionally, an arbitrary number can be prefixed to modify motions.
One usecase is 5 + j
, which moves down 5 lines in one
input sequence.
How can you easily remember these keybinds?
Most keybinds are mnemonics for their corrisponding action.
i
nsert enters Insert modea
ppend is the same as insert, but starts inserting at
the character after the cursorx
-out deletes a single characterd
elete takes your selection and deletes itc
hange deletes your selection and enters Insert
modeThere are a billion keybinds in vim
, so don’t fret about
learning all of them at once. Learning as you go is the method here!
vim
motions are extremely powerful. They let you
condense the work of selecting text and changing it into easy to
remember input sequences!
cc
lets you delete a line and start retyping text in one
shot (c
hange a line)! Double pressing most actions will
allow you to apply it to the line your cursor is on.
Before
This is a sentence!
The cursor is below this line.
_Emacs users are stinky :(
another wacky line!
After
This is a sentence!
The cursor is below this line.
|
another wacky line!
dw
lets you d
elete a w
ord.
The works to specify your selection after any action! So, this will work with too!
Before
This is a sentence!
The cursor is below this line.
_Emacs users are stinky :(
another wacky line!
After
This is a sentence!
The cursor is below this line.
_users are stinky :(
another wacky line!
Commands can be chained too! 2k
and dip
Lets you move 2
up (k
) and d
elete
the i
nner p
aragraph.
Before
This is a sentence!
The cursor is below this line.
_Emacs users are stinky :(
another wacky line!
After
_
Other useful actions include (but not all)...
o
and O
which creates a new line
below/above the current line respectivelygg
and G
which puts the cursor at the
top/bottom of the filezz
which centers the editing windowb
and e
goes to the b
eginning
and e
nd of the word your cursor is currently on.y
to copy (d
cuts) and p
to
pasteu
and Ctrl + r
to undo and redo.<<
and >>
to change
indentation levels in code.There are lots of commands in vim
, just like actions,
but we’ll just go over a few. To enter Command mode, just prepend a
:
before typing it!
:write
or :w
saves your file3:quit
or :q
quits Vim4:%s/<regex>/<regex>/gc
lets you find and
replace:help <command>
brings up the help-page for any
Vim commandYou can also chain commands, so :wq
for example saves
your file and exits in one shot.
Also, /
and ?
let you search within your
document.5 n
and N
let you go backwards/forwards through your search results.
Lets try a hands-on demo!
Firstly, open a terminal!
Windows
Open one of the following:
You’ll need to ssh
into
malware.cs.uic.edu
.
Syntax: ssh userXX@malware.cs.uic.edu
, where XX is a number between
1-25.
MacOS
Simply go to Applications > Utilities > Terminal
and
type vim
, its included by default!
Linux
Open your terminal of choice, install vim
if you need to
(tho it should be included by default...), and run
vim
.
Challenge!
I want you to create a simple C program using vim
and
sucessfully compile it! It can be as simple as "Hello, World!" if you’d
like!
#include <stdio.h>
int main(int argc, char **argv) {
("Hello World!\n");
printf}
If thats too easy for you, try these extra challenges:
vim
at any point when writing the
programClosing Remarks
vim
.vim
, try out
vimtutor
which is a guided tutorial to learn Vim.Me :3
The information in this presentation will be made available on our
website!
https://lug.cs.uic.edu
Join our Discord!
October 13, 2023