Brainscape Vim Flashcards
forward word/WORD
w / W
backward word/WORD
b / B
end of word/WORD
e / E
end of previous word
ge
beginning of line
0
beginning of text in line
end of line
$
land on next/previous “x” in line
fx / Fx
land just before the next/previous “x” in line
tx / Tx
next/previous (intra-line) find result
; / ,
move to matching parenthesis or bracket (or whatever is set in the ‘matchpairs’ option)
%
go to beginning of file
gg
go to end of file
G
go to line 7 of file
7G or 7gg
go to three-quarters of the way through the file
75% (you can use percentages!)
move cursor to the top of the screen
H (remember “highest”)
move cursor to the middle of the screen
M
move cursor to the bottom of the screen
L (remember “lowest”)
turn line numbers on/off
‘nu’ ‘number’ ‘nonu’ ‘nonumber’ :set nu, :set number/:set nonu, :set nonumber (also :# will just show you your current line number without turning on numbering)
turn on/off line number and percentage in the status bar
‘ru’ ‘ruler’ ‘noru’ ‘noruler’ (e.g. “:set ruler”)
scroll whole page at a time (name for both directions)
CTRL-F / CTRL-B (remember “Forward”/”Backward”)
scroll half a page at a time (name for both directions)
CTRL-D/CTRL-U (remember “Down”/”Up”)
scroll one line at a time (name for both directions)
CTRL-E (down) / CTRL-Y (up)
move the LINE with the cursor in middle of visible screen
zz
put the line with the cursor at the top of the screen
zt
put the line with the cursor at the bottom of the screen
zb
search (forward and backward)
/ forward ? backward
go to next/previous search result
n/N (note that “next” could be either forward or backward depending on whether / or ? is used)
setting to always make searches case-insensitive / sensitive (also, what is the default?)
‘ic’ ‘ignorecase’ ‘noic’ ‘noignorecase’ e.g. “:set ic” (default is ‘noignorecase’, so searches are case-sensitive by default)
use the current word under the cursor and search forward/backward (like “/” or “?”)
- (forward), # (backward)
SEARCH for the third next word under the cursor
3* (used with count)
turn off search highlighting temporarily
:noh :nohlsearch (command)
turn off search highlighting permanently
‘nohls’ ‘nohlsearch’ e.g. “:set nohls”
enable/disable display of search matches while you’re still typing (this is on by default)
‘is’ ‘incsearch’ ‘nois’ ‘noincsearch’ :set is/:set nois (this setting is on by default):
define a “jump”
anything farther than one line (not including “j” and “k” with count though)
jump back and forth between two recent JUMPS
`` (to the actual cursor position in the line) or ‘’ (to the beginning of line)
go to older/newer location in jump list
CTRL-O older / CTRL-I newer (also )
display list of recent jumps
:ju :jumps
mark place under cursor with an “a”
ma (marks can be “a-z”)
jump to mark “q”
q or 'q (
for intra-line, ‘ for beginning of line)
display list of marks
:marks (no abbreviated version)
clear the jump list of the current window
:cle :clearjumps
special mark for cursor position from just before most recent jump
’ or ` (e.g. `` or ‘’ to get back to where you were last)
special mark for cursor position from when last editing the file
” (e.g. `” or ‘” to get back to where you were when last editing the file)
special marks for the start/end of the last change
[ / ]
difference between uppercase and lowercase marks
lowercase marks are specific to one file, whereas uppercase marks are global and can be used from any file
see where “F” is marked, see where “M”, “C”, and “P” are marked
:marks F :marks MCP
delete operator
d{motion}
delete whole line
dd
change whole line (but keep indent) (two ways of doing this!)
cc (or S)
delete character under/before cursor
x (same as “dl”) / X (same as “dh”)
delete to end of line
D (same as “d$”)
change one character
s (same as “cl”)
replace one character
r{character}
replace mode
R
repeat last change
.
character-based/line-based/block-based visual mode
v / V / CTRL-V
change to other side of selection in visual mode
o (“o”ther)
change to opposite set of corners when in block-based visual mode
O (“O”ther)
re-select the most-recently selected visual area
gv
put copied text after/before cursor
p / P
put three copies of copied text after cursor
3p
swap two characters
xp (simply the commands “x”, then “p”)
copy text specified by a given movement
y{movement} (remember “yank”)
copy whole line
yy
copy to end of line
Y (must be mapped to do so in init.vim, since by default it acts identical to “yy”)
copy using normal clipboard instead of register, paste using normal clipboard instead of register
“y “p (or you can use “+” instead of “*”)
what “ab” and “aB” text objects represent
“a(“ and “a{“
change case of one character and move forward
~
switch case of current line
g~g~ or g~~
lowercase/uppercase the text indicated by a given motion
gu{motion} / gU{motion}
make current line uppercase / lowercase
gUgU or gUU gugu or guu
make highlighted text lowercase/uppercase in visual mode
u / U
append at end of line, insert at beginning of line
A I
text objects for an HTML or XML tag block (e.g. …)
at / it
text objects for words, sentences, and paragraphs
iw/aw is/as ip/ap
add one to the number under the cursor, add three
CTRL-A 3CTRL-A
subtract one from the number under the cursor, subtract three
CTRL-X 3CTRL-X
create an incrementing sequence
On separate lines, put “1” “1” “1” “1”. Then visually select all lines except the first and execute “g CTRL-A” to create “1” “2” “3” “4”.
location of init.vim, Linux
~/.config/nvim/init.vim
location of init.vim, Windows
~/AppData/Local/nvim/init.vim
reset an option to its default state
end with “&”, e.g. “:set iskeyword&”
what distinguishes a “setting” in the help files
single quotes, e.g. :help ‘wrap’
how to find help for a visual mode command
prepend “v_”, e.g. :help v_u
how to find help for an insert mode command
prepend “i_”, e.g. :help i_CTRL W
how to find help for a command-line command
prepend “:”, e.g. :help :quit
how to find help for editing text in the command-line
prepend “c_”, e.g. :help c_
how to find help for a Vim start-up option
prepend “-“, e.g. :help -r
how to find help for a regular expression
prepend “/”, e.g. :help /[
how to search for a help topic
type “:help word” and then press CTRL-D to see matching entries for “word” (or use “:helpgrep word”)
change background to dark/light version of color scheme
‘bg’ ‘background’ (e.g. “:set background=dark/light”)
change color scheme
:colorscheme evening
print a physical paper copy of a file, print only a portion of a file
:hardcopy highlight with visual mode before printing
settings relating to physical printing of a file
look at settings beginning with ‘print*’, e.g. ‘printdevice’ ‘printheader’ ‘printfont’ ‘printoptions’
print to html
:TOhtml
disable SYNTAX highlighting for the moment
:syntax clear
disable syntax highlighting completely
:syntax disable
allow manual turning on and off of syntax highlighting per buffer
:syntax manual, then “:set syntax=ON” (or OFF) on a per-buffer basis
force Vim to use a certain type of syntax highlighting for a file
‘ft’ ‘filetype’ (e.g. “:set filetype=fortran”)
see what filetype Vim is currently using for syntax highlighting
:set ft? :set filetype? (with no argument)
open Vim with multiple files in horizontal splits, vertical splits
nvim -o file1.txt file2.txt nvim -O file1.txt file2.txt
close the current file and open a new one
:edit FILE
hide current file and edit another
:hide edit otherfile.txt
edit a new set of files from within Vim
:args five.txt six.txt seven.txt
view currently open files that were given from arguments
:ar :args
edit the next, previous file in the :args list, skip two files forward in :args list
:n :next :N :prev :previous :2next
write changes and move to next, previous file in :args list
:wn :wnext (same as “:write”, then “:next”) :wN :wp :wprevious
go to first file in :args list
:fir :first (bonus–can also use “:rewind”)
go to last file in :args list
:la :last
setting to automatically write file when switching to another buffer
‘aw’ ‘autowrite’ ‘noaw’ ‘noautowrite’ (e.g. “:set autowrite”)
what is the difference between the argument list and buffers in Vim
the argument list was already present in Vi, but the buffer list was a new addition for Vim
add file(s) to the argument list in Vim
:arga :argadd (e.g. “:arga file3.txt file4.txt”)
remove file(s) from argument list in Vim
:argd :argdelete (e.g. “:argdelete file1.txt” or “*.txt” or “%”)
edit file N in the argument list
:argu :argument (e.g. “:argu 3” or “:3argu”)
write and quit all (TWO different command-line commands)
:wqa :xa
quit all files
:qa :quitall
quit without saving
:q! quit!
technical difference between “:wq” and “:x”
“:wq” writes and quits no matter what, whereas “:x” writes and quits, but only actually does the “write” if the file was changed
uppercase letters to write current file, if modified, and quit
ZZ (same as “:x”)
uppercase letters to quit without checking for changes
ZQ (same as “:q!”)
close the current window (command-line command and keybinding)
:clo :close CTRL-W c
quit the current window (command-line command and keybinding)
:q :quit CTRL-W q
what is the technical difference between “:quit” and “:close”
“:quit” will quit Vim if you’re in the last open window, whereas “:close” will make sure to leave Vim open
jump between the previous file and the current file (back and forth as desired)
CTRL-^ (technically, will jump to the “alternate file”, which is the most-recently viewed one)
jump to buffer N (command line command and keybinding)
:Nbuf :Nbuffer N CTRL-^
how backups work by default in Vim, what option controls this behavior
backup is made, file is overwritten, backup is deleted (this is the behavior of the ‘wb’ ‘writebackup’ option)
keep backups from being deleted automatically after write
‘bk’ ‘backup’ ‘nobk’ ‘nobackup’ (e.g. “:set backup”)
what backup filenames look like by default
“file.txt~” with a tilde
setting to make a custom backup-file signifier
‘bex’ ‘backupext’ (e.g. “:set backupext=.backup”)
backup to a specified directory instead of just cwd
‘bdir’ ‘backupdir’ (e.g. “:set backupdir=DIRECTORY”)
how to keep a backup of the original file before any changes were made, also, what is prerequisite for this to work
:set patchmode=.orig (“.orig” is the extension); requires ‘backupdir’ to be set for this to work
how to open a file in read-only mode
nvim -R file.txt (bonus! you may also be able to simply use the command “view file.txt” from Linux)
what is the difference between “nvim -R file.txt” and “nvim -M file.txt”
“-R” is read-only mode, which will warn before saving, whereas “-M” is even more strict, opening Vim with the ‘modifiable’ setting switched off
how can you remove the read-only setting if you opened a file in read-only mode
:set write (inverse of “:set nowrite”), no shortened version of this option
how you can remove the “modifiable” protection and make a file modifiable again
‘ma’ ‘modifiable’ ‘noma’ ‘nomodifiable’ (e.g. “:set modifiable”)
how to append to a file instead of simply writing one
:write»_space; file.txt (append current buffer to file.txt)
how to save a copy of the file with a new name, but keep on editing the file with the original name
:write file2.txt
save a copy of a file and continue editing the file with the new name
:saveas file2.txt
display information about the current file (both command-line command and keybinding)
:f :file CTRL-G
split current buffer into two separate (horizontal) windows (command-line command and keybinding)
:sp :split CTRL-W s
which window will have the cursor after a horizontal split
the top window
which window will have the cursor after a vertical split
the left window
create a new split window that is 3 lines high
:3split (note that count must precede the command)
split and open a specified file in the new window
:sp :split FILE (e.g. “:split file2.txt”)
split (horizontally) and open a new file in the new split (command-line command and keybinding)
:new CTRL-W n
split the current buffer into two VERTICAL windows (command-line command and keybinding)
:vsp :vsplit CTRL-W v
create a vertical split with a specified file
:vsp :vsplit file2.txt
create a vertical split with a new file
:vne :vnew
hide the current buffer
:hid :hide
close all other windows except the current one (command-line command and keybinding)
:on :only CTRL-W o
jump from window to window
CTRL-W w
move to window to the left, down, up, or to the right
CTRL-W h j k l
move to the top window
CTRL-W t
move to the bottom window
CTRL-W b
rotate all windows downwards/rightwards (clockwise) or upwards/leftwards (counter-clockwise)
CTRL-W r and CTRL-W R
swap current window with the next one (or the previous if there is no “next” window)
CTRL-W x
swap current window with the third window from the top
3 CTRL-W x (windows increment starting with “1”)
move window left, down, up, or right
CTRL-W H J K L
move current window to a new tab page
CTRL-W T (uppercase “T”)
move current window to a new tab page before tab three
3 CTRL-W T
make all windows the same height and width
CTRL-W =
increase/decrease size of window (also, increase/decrease by four lines) (command-line command and keybinding)
:resize +4/-4 CTRL-W +/- and 4 CTRL-W +/-
set current window as high as possible, “maximize” (command-line command and keybinding)
:res :resize (with no arguments) CTRL-W _
set current window height to a specific number of rows (command line and keybinding), also, a “bonus” shortcut for this
:resize N [N]CTRL-W _ z{nr}
make window wider/narrower, make window wider/narrower by three columns (command-line command and keybinding)
:vert :vertical resize +3/-3 CTRL-W >//< (three columns)
how to make the new window you’re creating appear to the right or below rather than to the default above or left
:rightb :rightbelow / :bel :belowright (bonus FYI, “:lefta :leftabove” / “:abo :aboveleft” are the inverse counterparts of these
how to make the new window you’re creating all the way at the top and/or to the left, OR bottom and/or right
:to :topleft / :bo :botright (but NOT :bottomright)
the two options that will alter the default above/left behavior for window splits
‘sb’ ‘splitbelow’ ‘nosb’ ‘nosplitbelow’ ‘spr’ ‘splitright’ ‘nospr’ ‘nosplitright’ (e.g. “:set splitbelow”)
settings to set the DESIRED (not hard) minimum hight and width of a new window also, what is the default and minimum setting for this
‘wh’ ‘winheight’ ‘wiw’ ‘winwidth’ e.g. “:set wiw=5” minimum and default setting is “1”
settings for the hard minimum height and width to enforce for other windows (besides the new one you’re opening)
‘wmh’ ‘winminheight’ ‘wmw’ ‘minwinwidth’
reasonable values for the ‘winminheight’ option
0-3, where zero will just be the separator itself (too large a number will cause errors when opening multiple windows)
reasonable values for the ‘winminwidth’ option
0-12, where zero will just be the separator itself (too large a number will cause errors when opening multiple windows)
option to automatically resize all windows to have equal spacing among them (default on)
‘ea’ ‘equalalways’ ‘noea’ ‘noequalalways’
how do you open Vim in diff mode
nvim -d main.c~ main.c (in this example using a backup file as a means of comparison)
how do you go into diff mode from within Vim
:vertical diffsplit main.c~ (compare “main.c~” with the file you’re currently editing, presumably “main.c”)
make it so that the two windows no longer scroll together in diff mode
:set noscrollbind (‘scb’ ‘scrollbind’ ‘noscb’ ‘noscrollbind’)
jump to the next/previous change in diff mode, jump three changes forward/back
]c / [c used with a count, 3]c / 3[c
in diff mode, replace deleted text when you’re in the LEFT window
dp (remember “diff put”)
in diff mode, remove changes when you’re in the RIGHT window
do (remember “diff obtain”)
open Vim with multiple files in separate tab pages
nvim -p file1.txt file2.txt
open a file in a new tab page within Vim
:tabedit FILE
open a new tab with an empty window
:tabnew
close all tabs except current
:tabonly
close current tab
:tabc :tabclose
close all tabs except tab number two
:2tabonly OR :tabonly 2
go to next tab/previous tab, go to tab number 3 (command-line command and keybindings)
:tabnext :tabprevious gt / gT 3gt ALSO CTRL-/ (works in both normal and insert mode)
go to first/last tab page
:tabfirst :tablast
make the current tab the last one
:tabm :tabmove (default behaviour of “:tabmove” is to put current tab at the end–“:tabmove $” will also work)
move current tab left, right, after tab 2, or to the beginning
:-tabmove :+tabmove :2tabmove :0tabmove (also can use “:tabm” for short) (yes, it is fine to put the number after the command as well)