notes/vim_notes.txt
2021-10-08 06:08:59 -07:00

120 lines
2.8 KiB
Text

This Document covers some of the most commonly used vim commands:
# Super Basic:
# Quit Vim:
:q (make sure to enter the colon, this is in NORMAL mode)
:q! (quit without saving)
# Save Document:
:w
:wq (save and quit)
# Insert Text (enter INSERT mode):
i (that's right, just hit i)
a (enter insert mode, and put the cursor one ahead, ie append)
# Return to NORMAL mode:
Esc (hit the Escape key)
# Enter VISUAL mode:
v (from NORMAL mode, hit v, this will allow you to enter VISUAL mode)
# Navigate the Document in NORMAL mode:
h (go one character left)
j (go one character down)
k (go one character up)
l (go one character right)
w (go to the first character of the next word)
e (go to the last character of the next word)
b (go to the first character of the last word)
0 (go to the beginning of the current line)
$ (go to the end of the current line)
ctrl+d (navigate down one half screen)
ctrl+u (navigate up one half screen)
ctrl+f (navigate down one full screen)(essentially pgdown)
ctrl+b (navigate up one full screen)(essentially pgup)
# Copy/Paste:
yy or Y: copy current line, including new line character
y$: copy to the end of current line, but not the new line character
yiw: copy the current word, excluding surrounding whitespace
yaw: copy the current word, including surrounding whitespace
ytx: copy from the current cursor position up to and before the character represented by x
yfx: copy from the current cursor position up to and including the character represented by x
# Undo/Redo:
u: undo
Ctrl-R: redo
# Indent/Unindent:
>> : indent current line
<< : unindent current line
# Travel to a specific line:
5G (takes you to line 5)
# Page Up/ Page Down:
CTRL + B (Page Up)
CTRL + F (Page Down)
# Global Search and Replace:
:%s/word_to_replace/new_word/g
# Delete all blank lines:
g/^\s*$/d
# Running Bash Commands from within Vim:
:! <bash command>
# Dealing with multiple files:
#Tabs:
To open a new tab there are a few options, one is to use the command line:
!tabnew <filename>
You can cycle through tabs using:
gt or gT
You can cycle through windows using:
Ctrl + w or Ctrl + Shift + w
*From NerdTree you can also simply push t to open a new tab of the file you have selected
t
Side Note: in NerdTree you can display hidden files by invoking capital I:
I
# You can open multiple files by simply typing them in sequentially after the vim command(tab auto complete works on this):
vim item1.txt item2.txt
# You can hope between files then with the following commands(not as effective as tabs):
# Next
:n
# Previous
:N or :prev
# To see which files are open in the vim buffer:
:args
# To open up more, simply type:
:n item3.txt
# Note that this would only open item3.txt, it clears the buffer when you do this and so you would have to enter your total list of files.