summaryrefslogtreecommitdiffhomepage
path: root/vim.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'vim.html.markdown')
-rw-r--r--vim.html.markdown63
1 files changed, 47 insertions, 16 deletions
diff --git a/vim.html.markdown b/vim.html.markdown
index 7723136f..0eb2c37e 100644
--- a/vim.html.markdown
+++ b/vim.html.markdown
@@ -8,18 +8,20 @@ filename: LearnVim.txt
[Vim](http://www.vim.org)
-(Vi IMproved) is a clone of the popular vi editor for Unix. It is a text
-editor designed for speed and increased productivity, and is ubiquitous in most
-unix-based systems. It has numerous keybindings for speedy navigation to
+(Vi IMproved) is a clone of the popular vi editor for Unix. It is a text
+editor designed for speed and increased productivity, and is ubiquitous in most
+unix-based systems. It has numerous keybindings for speedy navigation to
specific points in the file, and for fast editing.
## Basics of navigating Vim
```
vim <filename> # Open <filename> in vim
+ :help <topic> # Open up built-in help docs about <topic> if any exists
:q # Quit vim
:w # Save current file
:wq # Save file and quit vim
+ ZZ # Save file and quit vim
:q! # Quit vim without saving file
# ! *forces* :q to execute, hence quiting vim without saving
:x # Save file and quit vim, shorter version of :wq
@@ -32,6 +34,11 @@ specific points in the file, and for fast editing.
k # Move up one line
l # Move right one character
+ Ctrl+B # Move back one full screen
+ Ctrl+F # Move forward one full screen
+ Ctrl+D # Move forward 1/2 a screen
+ Ctrl+U # Move back 1/2 a screen
+
# Moving within the line
0 # Move to beginning of line
@@ -47,16 +54,17 @@ specific points in the file, and for fast editing.
:%s/foo/bar/g # Change 'foo' to 'bar' on every line in the file
:s/foo/bar/g # Change 'foo' to 'bar' on the current line
+ :%s/\n/\r/g # Replace new line characters with new line characters
# Jumping to characters
f<character> # Jump forward and land on <character>
- t<character> # Jump forward and land right before <character>
+ t<character> # Jump forward and land right before <character>
- # For example,
+ # For example,
f< # Jump forward and land on <
t< # Jump forward and land right before <
-
+
# Moving by word
w # Move forward by one word
@@ -73,19 +81,28 @@ specific points in the file, and for fast editing.
L # Move to the bottom of the screen
```
+## Help docs:
+
+Vim has built in help documentation that can accessed with `:help <topic>`.
+For example `:help navigation` will pull up documentation about how to navigate
+your workspace!
+
+`:help` can also be used without an option. This will bring up a default help dialog
+that aims to make getting started with vim more approachable!
+
## Modes:
Vim is based on the concept on **modes**.
-Command Mode - vim starts up in this mode, used to navigate and write commands
-Insert Mode - used to make changes in your file
-Visual Mode - used to highlight text and do operations to them
+Command Mode - vim starts up in this mode, used to navigate and write commands
+Insert Mode - used to make changes in your file
+Visual Mode - used to highlight text and do operations to them
Ex Mode - used to drop down to the bottom with the ':' prompt to enter commands
```
i # Puts vim into insert mode, before the cursor position
a # Puts vim into insert mode, after the cursor position
- v # Puts vim into visual mode
+ v # Puts vim into visual mode
: # Puts vim into ex mode
<esc> # 'Escapes' from whichever mode you're in, into Command mode
@@ -102,18 +119,18 @@ Ex Mode - used to drop down to the bottom with the ':' prompt to enter comm
## The 'Grammar' of vim
-Vim can be thought of as a set of commands in a
+Vim can be thought of as a set of commands in a
'Verb-Modifier-Noun' format, where:
-Verb - your action
-Modifier - how you're doing your action
+Verb - your action
+Modifier - how you're doing your action
Noun - the object on which your action acts on
A few important examples of 'Verbs', 'Modifiers', and 'Nouns':
```
# 'Verbs'
-
+
d # Delete
c # Change
y # Yank (copy)
@@ -135,7 +152,7 @@ A few important examples of 'Verbs', 'Modifiers', and 'Nouns':
s # Sentence
p # Paragraph
b # Block
-
+
# Sample 'sentences' or commands
d2w # Delete 2 words
@@ -157,6 +174,20 @@ A few important examples of 'Verbs', 'Modifiers', and 'Nouns':
ddp # Swap position of consecutive lines, dd then p
. # Repeat previous action
:w !sudo tee % # Save the current file as root
+ :set syntax=c # Set syntax highlighting to 'c'
+ :sort # Sort all lines
+ :sort! # Sort all lines in reverse
+ :sort u # Sort all lines and remove duplicates
+ ~ # Toggle letter case of selected text
+ u # Selected text to lower case
+ U # Selected text to upper case
+
+ # Fold text
+ zf # Create fold from selected text
+ zo # Open current fold
+ zc # Close current fold
+ zR # Open all folds
+ zM # Close all folds
```
## Macros
@@ -180,7 +211,7 @@ Here's a sample ~/.vimrc file:
```
" Example ~/.vimrc
-" 2015.10
+" 2015.10
" Required for vim to be iMproved
set nocompatible