Hosted by Robert Quitt
https://tinyurl.com/csuavimfa18
Computer Science Undergraduate Association (CSUA)
- Open to all people and majors interested in CS
- Dedicated to serving CS undergraduate community
- Socials
- Infosessions/tech talks
- Workshops (like this one)
- Tutoring
- Computing resources
- Robert Quitt
- 3rd year CSUA Officer
- Vim user for a couple of years
- People tend to be turned off by Vim/terminal workflows
- By the end of today, you should know how to use Vim
- Fast editing, fast editor
- Ubiquitous
- Works remotely
- Powerful
- A fun learning experience
- Unique
- Windows
- https://www.vim.org/download.php#pc
- Download gVim
- You can also ssh into something
- Otherwise, Vim comes installed with Git bash (if MinTTY installed)
- Mac
- iTerm2 is great
- Use homebrew to install Vim and tmux
- brew install vim
- https://stackoverflow.com/questions/21012203/how-can-i-install-macvim-on-os-x
- *nix
- Install vim and tmux from whatever package manager you use.
- build from source (
git clone
+make
+make install
)
- Play around with a few things while you wait!
- Vim tutor (you are new to Vim)
- *nix: run vimtutor
- Windows: Search for Vim tutor in windows search
- Familiarize yourself with the interface
https://drive.google.com/file/d/1MU-_VfddpETYuA5l4tpTcbl4qmeAFAMB/view?usp=sharing
- Diagnostic Quiz
- Lecture + Examples
- A terminal-based text editor, around since 1991
- Based on an older Vi, written in 1976
- By far the most popular text editor for *nix users
- Self-documenting (:help)
- Customize keybindings and extend with plugins (.vimrc)
- Modal editor (has multiple modes) (you will learn these later)
- Normal
- Insert
- Visual
What does each of the following sequences of keys do (assume we start in normal mode)
ihi
dd
:q!
:%s/foo/bar/g
caw
qsA;<ESC>qj@s
yip
<C-w>l
:set expandtab
u
What does each of the following sequences of keys do (assume we start in normal mode)
ihi
: enter insert mode, insert "hi"dd
: delete line, send to default register ("
):q!
: force quit:%s/foo/bar/g
: replace all instances of "foo" with "bar" multiple times per linecaw
: "change a word", deletes word under cursor and enters insert modeqsA;<ESC>qj@s
: create macros
, which appends;
to the end of the line, move down a line, run macros
"tyip
: "yank inner paragraph", yanks paragraph to registert
<C-w>l
: move to window to the right:set expandtab
: sets expandtab to true, which causes tabs to be inserted as spacesu
: undo last command
- Edit text using a sequence of operations and motions
- An operation needs a motion or selection to operate over
- Have modes to do different things
- Stay in normal mode, quickly go into other modes to do edits
- Normal, Command, Visual, Insert
- There can be multiple ways to do the same thing
- But usually there's one best way
- Manipulate text by composing many operations, motions, selections
- On command line: vim [filename]
- Or: vim
- then type :e <filename>
- Vim starts in Normal Mode
- Entering insert mode:
i
: insert at cursorI
: insert at beginning of linea
: append after cursorA
: append at the end of line
- Exiting insert mode:
- Esc or C-c
- Moving around in normal mode:
h
: leftj
: downk
: upl
: right
- Invoke by using
:
in normal mode - Basic necessary commands
:w[rite] [filename]
:q[uit]
- :q[uit]! : don't save
- Some useful commands
:h[elp] [subject]
- This is your best best friend for learning vim
:se[t] {option}
- Used for setting vim settings in the current session
- Open ex1_getting_started.txt
- Remember:
h
j
k
l
to move in normal modei
to insert, a to appendI
to insert at beginning of line, A to insert at end of lineESC
to exit insert mode back to normal mode
- Typical flow: stay in normal mode, enter insert mode, edit, and then go back to normal.
- Normal mode common commands
- dd : delete line
- yy : yank line
- p : paste below
- P : paste above
- o : open line below--creates a new line below cursor and enters insert mode
- O : open line above--creates a new line above cursor and enters insert mode
- u : undo last command
- C-r : redo last command
- Start with /
- Press enter
- n : next result
- N : previous result
- Supports regexes
- Some settings:
- :set incsearch : set incremental search--starts searching for partially typed queries
- :set hlsearch : set highlight search
- :noh : clears highlighted search
- Vim has operations and motions
- This allows a lot of flexibility in your commands
- Operators:
d
: deletey
: yankc
: changegU
: uppercase=
: format>
: shift right
- Motions/Text object motions(just a few)
w
: wordb
: previous wordaw
: "a workd"4j
: 4 lines down/foo
: next occurence offoo
tc
: "unTil c"fr
: right aFter "r"
- Additionally, can use numbers to repeat many operators
3dd
: delete 3 lines
- Also, repeat the operator to operate on that line
yy
,dd
,cc
,>>
,gUU
should be self-explanatory
- Composing operators and motions:
ciw
: change inner wordgUi)
: make the text inside a pair of parentheses uppercaseyap
: yank a paragraphd4W
: delete the next 4 WORDs
- Need to :set shiftwidth to choose how far to change indent
<<
and>>
change indentation for current line{visual}<
and{visual}>
change indentation for selection- Use
.
to repeat indentation change - Exercise:
ex3_bad_indent.c
- Macros allow you to repeat repetitive keystroke sequences
- Examples tend to be things like, adjust the format of particular lines
- Use
q<register>
followed by the keys you want to use - Using
ESC
to go from normal mode to insert mode sometimes screws things up - If that happens, use
C-c
instead - To run a macro, use
@<register>
- Repeat last macro:
@@
- Repeat multiple times:
50@@
- Use this mode to select text to then use an operator on
- Useful for selecting text precisely
v
: enter visual modeV
: enter visual line modeC-v
: enter visual block mode- Special: for visual block mode, use A or I to add to the end of each line
- Use the motions
^
for beginning of line and$
for end of line
- Use your documentation-reading abilities to find a solution to the following problem.
- In
ex4_vim_golf.txt
, transform the text in the fewest keystrokes possible! - Find a way to replace all instances
- be sure to look at
:h motions.txt
- Change your keyboard settings to have low repeat delay and high repeat rate for a more enjoyable Vim experience
"Hey wanna check out my dotfiles"
- Use .vimrc to customize your vim experience
- .vimrc is executed as commands when vim is started up
- Can contain plugins, settings, keybinds
- Vimawesome.com lists the most popular vim plugins
- Vim has very extensible syntax highlighting
- :setf[iletype] {filetype}
- This changes the syntax type as well
- Use this when vim has the wrong syntax identified
- Install support for other syntax files using plugins
- Colorschemes - change the way vim looks
- Set with :colo[rscheme] {name}
- Many many colorschemes around.
- Some personal favorites: Molokai, Solarized.
- Install the same way as plugins
- Countless talks on Vim productivity
- Most popular text editor -- there's a large community
- Print out a cheatsheet!
- Keep using it! Don't give up!
- vimcasts.org
- Webcasts of practical examples of things to do with Vim
- vimawesome
- Put them in a repo so that you can easily copy them and keep them updated on all your machines you work on
- Lets you move your config around easily!
- Good to have an understanding of how git works to do this
- First thing I do when I log into a machine is clone my dotfiles!
- :set list helps view tabs vs spaces
- Should also set listchars in .vimrc
- See ex5_whitespace.py
- Can have multiple buffers open at once as tabs
- From :help windows.txt
- A buffer is the in-memory text of a file.
- A window is a viewport on a buffer.
- A tab page is a collection of windows.
- A window is a viewport onto a buffer. You can use multiple windows on one buffer, or several windows on different buffers.
- A buffer is a file loaded into memory for editing. The original file remains unchanged until you write the buffer to the file.
- Use C-w s for split, C-w n for new, C-w = for set windows equal size
- Gazillions of articles online about how to do this
- Options
- youcompleteme
- OmniComplete (Vim >8.0)
- Read more about these, I personally don't use them.
you can use the
*
command to search for a keyword
Vimium is a plugin that lets you use the vim keybinds for Chromium Very fast web browsing
- Start with a base
- Modify and add things until you are happy with what you have
- Keep modifying it forever, you will never be 100% happy with it
- Many online resources (or just search for dotfiles on github!)
Thanks for coming!
Please fill out feedback form!
https://goo.gl/forms/yFEW5A966XzsD3812