Francisco Cornejo-Garcia RIT | Computer Science

Vim Tips

Below are the following commands that may help you. If you ever get stuck, type :help for more information. Normal Mode is the default mode when entering Vim. This mode is mainly used for altering text. If not in Normal Mode, press Esc or <C-[> to return. Also, you can use these commands to exit any mode and return to Normal Mode.

Moving Between Characters

Moving Between Lines

Moving Between Files

Special Commands - . - repeat last change

If you make any changes while in Normal Mode, the following commands will help. - u - undo change - <C-r> - redo change

One Shot Commands

The following commands peforms a one-shot action. - ~ - toggle case - x - delete character - J - join lines together - #[<C-a> | <C-x>] - [add, subtract] #

Operator-Pending Mode is a mode that you briefly enter when typing the following commands. These commands are usually appended by a motion. Some commands act on a line when typed twice. - c - change - d - delete - y - yank - [<>] - shift [left, right] - = - autoindent - g~ - swap case - gu - lowercase - gU - uppercase - ! - filter through external program

These commands act on following characters and may be used to move around more efficiently. - f? - find next character - F? - find previous character - t? - find until next character - T? - find until previous character - ; - go to next character - , - go to previous character

Macros introduce a way to record multiple commands. - q? - record and name a macro with any ? letter - @? - start macro - @: - repeat Ex command - @@ - repeat macro

Text Objects allow for greater control over which text to operate on. - a[w, t, p, ) | b, } | B, ], >, ’, ", \]- around [word, tag, paragraph, (), {}, [], '', "", ``] -i[w, t, p, ) | b, } | B, ], >, ’, “, `]` - in [word, tag, paragraph, (), {}, [], ’’, ““, ``]

Marks

Buffers

You can also navigate through buffers/jump list with these commands. - <C-o> - move to previous buffer/jump - <C-i> - move to next buffer/jump - <C-^> - switch alternate buffers - <C-g> - echo name & status of current buffer/file

You can also manipulate buffers through Command Mode. - :bp[revious]/bn[ext] - interact with buffer list - :b[uffer] # - go to specified buffer - :bufdo - execute Ex command in all buffers - :bd[elete] - delete buffer - :ls - shows content of buffer list - :% - filepath of active buffer - appending ‘:h’ removes the filename - :lcd [path] - set local working directory in window - :windo lcd [path] - set local working directory for all windows in tab

Windows

Split Windows

Close Windows

Change Focus

Move Windows

Resize Windows

Tabs

Insert Mode is used for inserting text. The following commands will send you to Insert Mode. - i - insert at character

Insert & Command Modes have some commands in common listed below. - <C-h> - backspace - <C-w> - delete back one word - <C-u> - delete back to start of line

There are some ways to exit Insert Mode. - Esc - go to Normal Mode - <C-[> - go to Normal Mode

Compound Commands

These commands will not only put you in Insert mode but also move to that location. - gi - insert at last insertion - I - insert at start of line - a - append after character - A - append at end of line - C - change line - o - new line below - O - new line above - s - substitute character - S - substitute line

Insert Normal Mode is a quick way to do a Normal Command before returning to Insert Mode. Just press <C-o> to go to Normal Mode for just one command.

Registers

Note: prepend u to four-digit hexadecimal code - <C-r>[register] - paste from specified register - <C-r><C-p>[register] - paste unformatted text - <C-v>[code] - convert to character - <C-k>[char1][char2] - insert a digraph - ga - show numeric code for current character - “[register] - set a register

Expression Register is a unique register to do quick calculations and more. Just press <C-r>= to enter.

Replace Mode is a mode where you can change text without inserting anything. The following commands will allow you to access this mode. - R - enter Replace Mode - r - replace character

Virtual Replace Mode is just like Replace Mode but can act on tabs and whitespace as if they were spaces. - gR - enter Virtual Replace Mode - gr - replace virtual character

Visual Mode is utilized for selecting and operating on text. The following commands will send you to Visual Mode. You can exit normally or also press the following commands again. - v - enter character-wise Visual Mode - V - enter line-wise Visual Mode - <C-v> - enter block-wise Visual Mode - gv - reselect last visual selection

When in Visual mode, you can navigate and make changes with your selection. - o - go to alternate end of selection - U - uppercase selection - u - lowercase selection

Command Mode allow you to make greater changes with Ex commands. To enter this mode, press ‘:’. - :p[rint] - echo current line - :[range]delete [register] - delete into register - :[range]yank [register] - yank into register - :#put [register] - put text from register after line # - :[range]co[py]/t [address] - copy lines to to below specififiedy by address - :[range]m[ove] [address] - move lines to to below specififiedy by address - :[range]join - join lines - :[range]norm[al] [command] - execute normal command - :[range]global/[pattern]/[cmd] - execute command on specified lines where pattern matches - :vglobal

Search Mode is a way to search for long text. - * - search current word - / - search forward - ? - search backward - K - search current word for man page - n - go to next search - N - repeat previous search

Search and Substitute

Motion & Selection

Shell

Note: To use the shell, it’s recommended to use <C-z> & fg instead. - :! - run shell commands - :shell - enter shell session - :pwd - print working directory - :cd - change directory - :find - open file - :set path+=[subdir] - specify directories Vim will look in

Argument List

Note: May use globbing and backtick expansion. - :args - list arguments - :first - go to first arg - :next/prev[ious] - navigate files in args - :argdo - execute same command on each buffer in the set - :cfdo - execute command in each file on quickfix list

Files

Command Line Window Mode opens a buffer that allows you to edit its specified history. - q: - enter command line window with Ex commands history - q/ - enter command line window with search history - <C-f> - switch to command line window

Changelist - g[;,] - traverse backward/forward through each change