Skip to content

Instantly share code, notes, and snippets.

@josephoaks
Last active August 15, 2019 00:03
Show Gist options
  • Save josephoaks/1db41014b5aa8f7e24b89ba17f6f2212 to your computer and use it in GitHub Desktop.
Save josephoaks/1db41014b5aa8f7e24b89ba17f6f2212 to your computer and use it in GitHub Desktop.
### Opening file to edit
vim <file_name> either new or existing file_name
### Entering edit mode
a append after cursor
A append at end of line
i insert before cursor
I insert at beginning of line
o opens new line below cursor
O opens new line above cursor
### Saving a file
:wq press esc to exit edit mode and enter command-line type :wq
### Testing current file without exiting the vim editor
1) esc :w write file (always a good thing)
2) esc :!<command to run> example: running puppet parser validate without exiting vim run the following
esc :w
esc :!puppet parser validate %
(the % says current file being edited)
### Change content
C change to end of line
cc change entire line
cw change current word
cis change sentence
ci" change/cut inside ""
ci( change/cut inside ()
ci{ change/cut inside {}
ci[ change/cut inside []
ci< change/cut inside <>
### Replace content
r replace character
R replace word
### Delete content
dd delete entire line
de delete to end of word
dE delete to next space
dt. delete to next dot
diw delete current word
di( delete within the current ()
di" delete within the current ""
di{ delete within the current {}
di[ delete within the current []
di< delete within the current <>
### Copy / Paste
yy copy current line
p paste buffer (example the line you just yy'ed)
### Movement
b beginning of word
e end of word
h j k l move cursor ( h:← j:↓ k:↑ l:→ )
^ beginning of line
$ end of line
w move to next word (better than b/e)
### Visual Editor
Ctrl+v use arrow keys to select (V select entire line)
arrow keys move indent left or right
### Comment / Uncomment
Put cursor on first # and then Ctrl+V, go down to bottem of comment section
and press x, this deletes the # characters
To comment, put cursor on first line, Ctrl+V then arrows to last line,
then Shift+I # Esc Esc
##########################################
### Set these lines in your vimrc file ###
##########################################
" F5: Toggle paste.
nnoremap <F5> :set invpaste paste?<Enter>
set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
" F6: Toggle list (display unprintable characters).
nnoremap <F6> :set invlist! list?<Enter>
" F7: Toggle line numbers.
nnoremap <F7> :set number! number?<Enter>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment