Skip to content

Instantly share code, notes, and snippets.

@michaelcpuckett
Forked from JoshuaEstes/000-Cheat-Sheets.md
Last active April 2, 2021 17:17
Show Gist options
  • Save michaelcpuckett/5404412 to your computer and use it in GitHub Desktop.
Save michaelcpuckett/5404412 to your computer and use it in GitHub Desktop.

Bash (Readline)

Moving

ctrl + a                 Goto BEGINNING of command line
ctrl + e                 Goto END of command line
ctrl + b                 move back one character
ctrl + f                 move forward one character
alt + f                  move cursor FORWARD one word
alt + b                  move cursor BACK one word

Other

ctrl + d                 Delete the character under the cursor
ctrl + l                 Clear the screen (same as clear command)
ctrl + p                 Fetch the previous command from the history list, moving back in the list (same as up arrow)
ctrl + n                 Fetch the next command from the history list, moving forward in the list (same as down arrow)
ctrl + u                 Clear all BEFORE cursor
ctrl + k                 Clear all AFTER cursor
ctrl + r                 Search backward starting at the current line and moving 'up' through the history as necessary
crtl + s                 Search forward starting at the current line and moving 'down' through the history as necessary
ctrl + c                 kill whatever is running
ctrl + d                 Exit shell (same as exit command)
ctrl + w                 delete the word BEFORE the cursor
ctrl + t                 swap the last two characters before the cursor
ctrl + y                 paste (if you used a previous command to delete)
ctrl + z                 Place current process in background
ctrl + _                 undo
esc + t                  Swap last two words before the cursor
esc + . OR esc + _
alt + [Backspace]        delete PREVIOUS word
alt + <                  Move to the first line in the history
alt + >                  Move to the end of the input history, i.e., the line currently being entered
alt + ?
alt + *
alt + .                  print the LAST ARGUMENT (ie "vim file1.txt file2.txt" will yield "file2.txt")
alt + c
alt + d
alt + l
alt + n
alt + p
alt + r
alt + t
alt + u
~[TAB][TAB]              List all users
$[TAB][TAB]              List all system variables
@[TAB][TAB]              List all entries in your /etc/hosts file
[TAB]                    Autocomplete
!!                       Run PREVIOUS command (ie "sudo !!")
!vi                      Run PREVIOUS command that BEGINS with vi
cd -                     change to PREVIOUS working directory

References

  1. http://cnswww.cns.cwru.edu/php/chet/readline/readline.html

M = Meta Key, meta key is either the left alt or esc key.

Commands

M + p                       Scroll up in window
M + n                       Scroll down in window
ctrl + p                    Previous window
ctrl + n                    Next window

Ctrl + b is default to enter before you enter the commands M = Left Alt key or ESC key

Windows

c           Create a new window.
&           Kill the current window.
n           Change to the next window.
p           Change to the previous window.
,           Rename the current window.
l           Move to the previously selected window.
w           Choose the current window interactively.
M-n         Move to the next window with a bell or activity marker.
M-p         Move to the previous window with a bell or activity marker.

Panes

"           Split the current pane into two, top and bottom.
%           Split the current pane into two, left and right.
x           Kill the current pane.
;           Move to the previously active pane.
o           Select the next pane in the current window.
!           Break the current pane out of the window.
q           Briefly display pane indexes.

Other

d           Detach the current client.
$           Rename the current session.
[           Enter copy mode to copy text or view the history.
f           Prompt to search for text in open windows.
r           Force redraw of the attached client.
L           Switch the attached client back to the last session.
$           Rename Current Session
:           Enter the tmux command prompt
?           List all key bindinds
f           Search window titles and goto that window
i           Breifly display window information
r           Force redraw of the attached client.
s           Select a new session for the attached client interactively.
t           Show the time.
=           Choose which buffer to paste interactively from a list.
]           Paste the most recently copied buffer of text.

Create a new session

tmux
tmux new
tmux new-session

Reattach to a session

tmux attach
tmux attach-session

List sessions

tmux ls
tmux list-sessions

How to copy and paste

  1. Enter copy-mode C-b [
  2. Move to text, press Space to slect text, move cursur to highlight text
  3. Press Enter
  4. Back at the command prompt, press C-b ] and the text you selected is pasted

References

Open a file

vim + file.ext               Open file at last line
vim +42 file.ext             Open file at line 42
vim +/^include_path          Open the file at the line that starts with include_path

Exiting

:q                           Quit
:wq                          Write and Quit
:q!                          Quit without saving
ZZ                           Write and quit
ZQ                           Quit without saving

Moving

h                            Move cursor LEFT
j                            Move cursor DOWN
k                            Move cursor UP
l                            Move cursor RIGHT
gg                           Move to START of buffer
G                            Move to END of buffer
ngg OR nG                    Move to n line (n represents a digit)
w                            Move to the start of the next word
e                            Move to the END of the word
b                            Move to the BEGINNING of the word
$                            Move to the END of the line
g                            Move to the BEGINNING of the line

Inserting Text

a                            append after the cursor
A                            append at end of line
i                            Insert before cursor
I                            Insert before line
o                            Create new line below and start editing
O                            Create new line above and start editing
gi                           Place cursor where you were last editing (Useful for when you exit Insert mode and then need to go back where you once were)

Other Commands

u                            undo
ctrl + R                     redo

Buffers

:ls                          List current buffers
:bn                          Next buffer
:bp                          Previous Buffer
:bd                          Close Buffer

Tabs

:tabnew                     create new tab
:tabn                       move to NEXT tab
:tabp                       move to PREVIOUS tab
:tabfir                     goto FIRST tab
:tablas                     goto LAST tab

Windows

ctrl + w s                  Split window horizontally
ctrl + w v                  Split window vertically
ctrl + w q                  Close current window, if last window then exit vim
ctrl + w c                  Close current window, will not exit vim
ctrl + w o                  Make window the only window on the screen

Spell Checking

" ~/.vimrc
" Enable spell checking
set spell

Commands

]s                           Move to next misspelled word
[s                           Move to previous misspelled word
z=                           Show list of possible replacements words

Marcos

  1. Press q then press another key that you want to assign it to. Example: qq
  2. Enter commands
  3. Press q when finished
  4. To run the macro, press @ and then the key that it is assigned to. Example @q
  5. NOTE: Can be ran multiple times. Enter the number of times you want it to run then the macro. Example 10@q will run the macro 10 times.

Code Folding

zo                           OPEN code fold under cursor
zc                           CLOSE code fold under cursor
zR                           OPEN ALL code folds
zM                           CLOSE ALL code folds

Autocomplete

ctrl + x ctrl + o            Autocomplete current word
ctrl + x ctrl + n            word completion next
ctrl + x ctrl + p            word completion previous
ctrl + x ctrl + f            Complete filename
ctrl + x ctrl + l            Whole line completion

Enable

" ~/.vimrc
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

One liners

:w|bd                       write (save) buffer and then close the buffer

Multi Liners

:set tw=80                  Sets text width to 80 characters
    gg                      Goto first line
    gqG                     Format file till you reach the last line

PHP Stuff

phpDoc

Install phpDoc.vim

ctrl+p                       Insert phpDoc block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment