(File, Common)#
:e filename | Edit filename, unless changes have been made |
:e # filename | Switch to last file edited |
:e! filename | Edit filename always (by default reload current) |
:w filename | Write (Save-(As)) |
:wq filename | Write and Quit |
:q | Quit |
:q! | Quit w/o Confirmation |
:x | Like :wq, writes if file changes |
:n, :N | Next Buffer, Previous Buffer |
Moving Around#
w | Forward word |
b | Back word |
0 ^ $ | Beginning, first, last character of line |
( ) | Beginning of previous, next sentence |
{ } | Beginning of previous, next paragraph |
C-HOME, gg line | Goto line, default beginning of file |
C-END, G line | Goto line, default end of file |
C-f | Page Forward (Down) |
C-b | Page Backward (Up) |
z | Redraw, line at top of window (default cursor line). Put cursor at first non-blank in the line. |
z. | Redraw, line at center of window (default cursor line). Put cursor at first non-blank in the line. |
Inserting Text#
The following commands can be used to insert new text into the buffer. They can all be undone. The non-Ex commands can be repeated with the "(N)." command. So, repeating a command 4 times, you do "4." after the escape (after the command).
You can end Insert mode with [ESC].
i | Insert text before the cursor |
I | Insert text before the first CHAR on the line |
o | Begin a new line below the cursor and insert text |
O | Begin a new line above the cursor and insert text |
:r filename | Insert the file (filename) (default: current file) below the cursor. |
:{range}r filename | Insert the file (filenamename) (default: current file) below the specified line. |
Deleting Text#
["x] x | Delete [count] characters under and after the cursor [into register x] |
["x] X | Delete [count] characters before the cursor [into register x] (not linewise). |
["x] d{motion} | Delete text that is moved over [into register x]. |
["x] dd | Delete [count] lines [into register x] (linewise). |
["x] D | Delete the characters under the cursor until the end of the line and [count]-1 more lines [into register x]. |
Visual Mode#
This is used to select a block of text.
v | start Visual mode per character. |
V | start Visual mode linewise. |
C-V | start Visual mode blockwise. |
o | go to Other end of highlighted text. |
Copy Text#
Often times, it helps to be in visual mode for this.
["x] y{motion} | Yank (Copy) {motion} text [into register x]. |
["x] yy | Yank [count] (Copy) lines [into register x] (linewise). |
["x] Y | Yank [count] lines [into register x] (synonym for yy, linewise). If you like "Y" to work from the cursor to the end of line (which is more logical, but not Vi-compatible) use ":map Y y$". |
{Visual}["x] y | Yank the highlighed text [into register x]. |
{Visual}["x] Y | Yank the highlighted lines [into register x] |
Copy Text to OS Clipboard#
"+y | Yank (from visual mode) |
Insert "set clipboard=unnamed" into .vimrc file |
Paste Text#
["x] p | Paste the text [from register x] after the cursor [count] times. |
["x] P | Paste the text [from register x] before the cursor [count] times. |
:[line]pu [x] | Put the text [from register x] after [line] (default current line). |
:[line]pu! [x] | Put the text [from register x] before [line] (default current line). |
["x]] p | Like "p", but adjust the indent to the current line. |
Undo and Redo#
u | Undo [count] changes. |
:u | Undo one change. |
C-R | Redo [count] changes which were undone. |
:red | Redo one change which was undone. |
U | Undo all latest changes on one line. |
The following are emacs commands to be eventually translated to vi.
Frame Commands#
C-x 5 o | other-frame | Move to other frame |
C-x 5 0 | delete-frame | Delete current frame |
C-x 5 2 | make-frame | Create a new frame on the current buffer |
C-x 5 f | find-file-other-frame | Find file in a new frame |
C-x 5 r | find-file-read-only-other-frame | find a file in a new frame, but it is read-only |
C-x 5 b | switch-to-buffer-other-frame | Make frame and display other buffer in it |
Buffer manipulation commands#
C-x b | switch-to-buffer | Move to buffer specified |
C-x → | next-buffer | Move to the next buffer in the buffer list |
C-x ← | previous-buffer | Move to the previous buffer in the buffer list |
C-x C-b | list-buffers | Display the buffer list |
C-x k | kill-buffer | Delete the buffer specified |
kill-some-buffers | Ask about deleting each buffer | |
Change the buffer's name to the name specified | ||
C-x s | save-some-buffers | Ask whether you want to save each modified buffer |
Window Commands#
C-x 2 | split-window-vertically | Divide current window into two windows, one above the other |
C-x 3 | split-window-horizontally | Divide current window into two side-by-side windows |
C-x > | scroll-right | Scroll the window right |
C-x < | scroll-left | Scroll the window left |
C-x o | other-window | Move to the other window. If there are several, move to the next window |
C-x 0 | delete-window | Delete the current window |
C-x 1 | delete-other-windows | Delete all windows but this one |
delete-windows-on | Delete all windows on a given buffer | |
C-x ^ | enlarge-window | Make window taller |
shrink-window | Make window shorter | |
C-x } | enlarge-window-horizontally | Make window wider |
C-x { | shrink-window-horizontally | Make window narrower |
C-x - | shrink-window-if-larger-than-buffer | Make window smaller if buffer is smaller than window |
C-x + | balance-windows | Make windows the same size |
C-M-v | scroll-other-window | Scroll other window |
C-x 4 f | find-file-other-window | Find a file in the other window |
C-x 4 b | switch-to-buffer-other-window | Select a buffer in the other window |
compare-windows | Compare this window with the next window and show the first difference |
Compilation mode commands#
C-x ` | next-error | Move to the next error message and visit the corresponding source code |
M-n | compilation-next-error | Move to the next error message |
M-p | compilation-previous-error | Move the previous error message |
C-c C-c | compilation-goto-error | Visit the source code for the current error message |
Space | scroll-down | Scroll down one screen |
Del | scroll-up | Scroll up one screen |
Search#
C-s | Search |
M-Shift-% | Search & Replace |
C-M-Shift-% | Regex Search & Replace |
Python Mode#
C-j | Insert a new line with the same indentation level as the current line |
RET | Insert a new line with the same indentation level as the current line |
C-M-a | Go to the beginning of the current function or class |
C-M-e | Go to the end of the current function or class |
C-M-h | Mark the current function or class for copying, etc. |
C-M-x | Execute the current function or class |
C-c C-b | Submit a bug report |
C-c C-c | Execute the buffer (i.e., the file being displayed) |
C-c C-d | Trace the stack of the process being executed |
C-c C-h | Get context-based help |
C-c TAB | Indent a highlighted (or marked) region |
C-c C-k | Mark a block of text. Using this at the head of a class or function definition will mark the entire block. |
C-c C-l | Shift the region to the left. If the cursor is in the middle of a region, the lower half of the region will shift. |
C-c RET | Execute the current file, opening a new window to show the output. |
C-c C-n | Jump to the next statement. |
C-c C-p | Jump to the previous statement. |
C-c C-r | Shift the region to the right. If the cursor is in the middle of a region, the lower half of the region will shift. |
C-c C-s | Execute a Python command. |
C-c C-t | Toggle shells |
C-c C-u | Go up one block |
C-c C-v | List the version of the Python mode |
C-c C-w | Run PyChecker |
C-c ! | Open the Python interactive shell |
C-c # | Comment the highlighted (marked) region |
C-c : | Check the indentation off-set |
C-c < | Shift the region to the left |
C-c > | Shift the region to the right |
C-c ? | Show Python mode documentation |
C-c PIPE | Execute the highlighted (marked) part of the current program. |
Software Development#
M-x compile | Will prompt for make command, then execute |
M-x recompile | Will repeat last compile command without prompting |
IDE - Fixme