Showing posts with label cheatsheet. Show all posts
Showing posts with label cheatsheet. Show all posts

Sunday, 9 March 2014

Emacs Cheatsheet

Commands mentioned here works on GNU Emacs but does not cover every command. A subset of these commands may work on Zile, XEmacs and others.

Note: C stands for Ctrl and M stands for either Alt or Esc

Command                Description
----------------------------------------------------------------------------------------
C-x C-c          Quit completely
C-g                Quit a partial entered command
C-v                Move forward one screen
M-v                Move back one screen
C-l                 Move text on which cursor is to center of screen (Pressing again leads to movement, first to top, then to bottom and back)

C-p                Move to previous line
C-b                Move backwards character by character
C-f                 Move forwards character by character
C-n                Move to next line
M-f                Move forward word by word (when cursor is between word, then move cursor to end of word)
M-b               Move backwards word by word (when cursor is between word, then move cursor to beginning of word)
C-a                Move to beginning of line (if at beginning, then does nothing)
C-e                Move to end of line (if at end, then does nothing)
M-a               Move to beginning of sentence (if repeatedly pressed, cursor moves to previous sentence's beginning)
M-e               Move to end of sentence (if repeatedly pressed, cursor moves to next sentence's end)
M-<               Move to beginning of whole text
M->               Move to end of whole text
C-u Number Command        Repeat the command "Number" times (Works for most commands)
M-Number Command        Repeat the command "Number" times (Works for most commands)
C-u Number C-v            Scroll text forward by "Number" lines (not screenfull)
C-u Number M-v            Scroll text backward by "Number" lines (not screenfull)
C-x 1                Kill all windows except the current one
C-u Number Character        Insert "Character" "Number" times at current cursor position
C-d                Delete character at current cursor position 
Backspace    Delete character before current cursor position (If used with C-u, then will kill instead of delete)
M-Backspace Kill word before current cursor position
M-d                Kill word after current cursor position 
C-k                 Kill from current cursor position till end of line (if pressed repeatedly, will kill the newline) (If used with C-u Number will kill, instead of delete)
M-k                Kill from current cursor position till end of sentence
C-Space         Start highlighting from current cursor position
C-w                Kill all text previously highlighted by "C-Space"
C-u Number C-k            Kill the "Number" lines along with their newlines
C-y                Yank (Paste) latest killed text at current cursor position (If several C-k were used, then would yank all killed)

M-y                Yank second latest killed text (If pressed repeatedly, then would come back to latest kill) (Could be used with C-u)

C-/                Undo (If used with C-u, then repeat undo "Number" times)
C-_                Undo (If used with C-u, then repeat undo "Number" times)
C-x u             Undo (If used with C-u, then repeat undo "Number" times)
C-x C-f          Open file or create new file
C-x C-s          Save file
C-x C-b          Show the list of buffers
C-x b buffername        Goto "buffername" buffer
C-x s             Save buffers which had changes in them
C-x C-c         Quit emacs
C-z                Suspend Emacs
fg                 Resume Emacs
%emacs       Resume Emacs
M-x repl s string replace    Replace all occurrences of "string" with "replace" after the current cursor position
M-x recover-file        After opening file, if during editing system crashes, this command can be used to recover or get back changes

M-x mode-name            Change mode to "mode-name" (Use text-mode for editing text, use minor mode: auto-fill-mode for human language text)

C-h m                Shows help on current mode
C-u number C-x f        Change margin to "number" (default is 70)
M-q                Re-fill paragraph (if paragrah is made up of sentences, some at new lines, then pressing this would connect them at the period)

C-s string            Search for string in forward direcrion (Enter to terminate search, keep pressing it for next occurrence of "string", after this is Backspace is pressed the cursor would jump to previous occurence of string)

C-r string            Search for string in reverse direction (Enter to terminate search, keep pressing it for next occurrence of "string", after this is Backspace is pressed the cursor would jump to previous occurence of string)

Note:     If control characters are typed other than C-s and C-r, the search terminates

C-x Number            Split the screen into "Number" frames, each displaying the same file
C-x o(other)            Bring the cursor to the other frame
C-M-v                      Scroll other frame (cursor remains where it was)
Escape C-v              Scroll other frame (cursor remains where it was)
C-x 4 C-f                  Open a different file in new frame (Cursor also moves to new frame)
M-x make-frame     Create new window
M-x delete-frame    Delete selected window
Escape Escape Escape        Get out of recursive editing level or out of minibuffer
C-h ?                       Get help on everything
M-x help                  Same as C-h ?
F1                           Same as C-h ?
C-h c Command     Tells "Command" name (Here "Command" is of the form C-x, M-v, C-x C-s, etc...)
C-h k Command            Displays documentation of the "Command" (Here "Command" is of the form C-x, M-v, C-x C-s, etc...)

C-h f Command-name        Displays documentation of "Command-name" (Here "Command-name" is of the form previous-line, etc...)
C-h v variable-name        Displays documentation of "variable-name" (Here "variable-name" refers to all variables some of which can be used to customize Emacs)

C-h a               Search for commands
C-h i                Info (Use "m emacs" to read Emacs Manual, type ? for guided tour)
C-h r               Read Manual

Note:
Use Tab for auto-completion of commands.

If you want to download it, here you go.

As Always thanks for reading and please comment.

Vim Cheatsheet

This is awesome editor. Enough Said. So, here is the cheatsheet

Command            What it does
--------------------------------------------------------------------------------
:q                        Quit (no saving)
:wq                     Save and quit
j                          Move one line down
k                         Move one line up
l                          Move to the next alphabet
h                         Move to the previous alphabet
x                         Delete unwanted character
i                          Insert text
dw                      Delete word
d$                       Delete from current cursor position to end of line
de                       Delete word till end of word
w                        Move onto next word
e                         Move onto next word's end alphabet
0                         Move to beginning of line
$                         Move to end of line
dd                       Delete a line
u                         Undo recent change
U(capital u)        Undo everything on that line
CTRL-r               Redo recent change
p                         Put deleted text after cursor (the entire thing)
r<new char>     Replace character at current cursor position with specified character
ce                       Change characters until the end of the word
Ctrl-g                 Show line number and file status
G                        Go to end of file
gg                      Go to beginning of file
<line number>  Ctrl-g    Go to specified line number
/<word>            Search for specified word in forward direction
?<word>           Search for specified word in backward direction
n                        Search previous word for next hit in forward direction
N                       Search previous word for next hit in backward direction
Ctrl-o(Oh)          To go back where you came from
Ctrl-i                  To go forward
%                       To search for matching parenthesis (place cursor on parenthesis first)
:s/old/new           Substitute 'old' word with 'new' word (only first occurence of 'old' word)
:!<command>    Execute specified command
:w <Filename>   Save opened file with specified filename
v motion :w <filename>    By pressing 'v' we enter visual mode which selects all text with motion such as move down
:r <filename>     Place the text from specified filename below the current cursor position
o                         Place text below cursor position
O(capital o)        Place text above cursor position
a                         Append Text
A                        Insert text after the end of the line
R(capital r)        Replace all characters until <ESC> is pressed
y                         Yank (copy) selected text. Use after entering visual mode
:set ic                  Ignore case for all searches (Use after search command)
:set hls is            Highlight matching text for all searches (Use after search command)
:set noic             Disable ignore case for all searches (Use after search command)
:nohlsearch        Disable highlighting text for all searches (Use after search command)
<HELP>, <F1>, :help    To get help
Ctrl-w Ctrl-w       To jump from one window to another
:e <filename>     Open filename for editing
:set nocp             Disable compatible mode
Ctrl-d                   Show a list of available commands starting with the specified character (Enter a character first), press repeatedly for autocompletion of command (Do :set nocp first)

<TAB>            Autocomplete command or filename (Do :set nocp first)

Note:
You can use the following formats for these commands:
    <times> command
like
    3w        -    Move three words forwards
    2e        -    Move two words forward on the end character
    d3w        -    Delete three words
    2dd        -    Delete two lines
    c$        -    Change till end of line
    c3w        -    Change from beginning of line till beginning of fourth word
    4G        -    Move to fourth line from top
    :s/old/new/g    -    Substitute 'old' word with 'new' word (for every occurence of the 'old' word in the file)

    :#,#s/old/new/g -    #,# are line numbers within which to change 'old' word with 'new' word

    :%s/old/new/g    -    Change 'old' word with 'new' word in entire file
    :%s/old/new/gc  -    Change 'old' word with 'new' word in entire file but prompt first

    :!ls        -    See contents of present working directory
    :!rm <filename>    -    Delete specified filename
    :r !ls        -    Write contents of directory below current cursor position
    j$        -    Move to end of line
    /<text>\c    -    Search for specified text while ignoring case just for this search
    :help <argument> -    Get help on the specified argument


If you want to download it, here you go.

This covers the terminal based vim and not GVim, and also does not cover buffer management  and other commands. These commands should also work on GVim.

As Always thanks for reading and please comment.

Stuff that most try to do