- Basics of VIM
- How to insert a string at the beginning of a line
- How to cut and paste (ctrl-v or ctrl-V)
- How to find a string
- how to replace with an / across the string to replace
- Repeats the last action
- Insert a # character at the beginning of the line
- Find an precise string an replace with something
- Insert a character or string at the end of a selected line
- Insert a consecutive number at the beginning of a selected line
- Delete all lines that contains a specific pattern
- Make lowercase
- Make upercase
- Find any String inside parenthesis Ex. (http://...) with empty content ()
- Find a particular character in a line using f
- Delete only a character
- Change inside brackets
- Quickly change a word or line
- Jump to the place of last Edit
- Yank the current line, including the newline character at the end of the new line, yy or Y
- Jump to the place before of the last Edit
- Yank the current word (no spaces)
- Yank the current word (with sorounding spaces)
- Yank all contained inside parenthesis ()
- Yank all contained inside brackets
- Replace the character under the cursor
- Enter insert mode, replacing characters rather than inserting
- redo
- insert mode
- remove ... from this line: 1.1 Should Software Engineers Worry About Hardware ......... 23
- Find any line starting by any number
- Delete the last character the end of the line
- Delete the last character at the end of the line if it is a number
- Delete the last two characters at the end of the line if they both were a number
- Delete the first n characters at the end of a line
- Delete empty lines
- Delete 1 or more of the preceding spaces at the end of the line
- find any header or implementation name file (class.h class.m)
- Find a file's name string like class.swift
- Find a swift or objective-c method like
nameMethod(parameter:)
- Using your last course, find any number of digits at the end of a sentence in any line
- Enumerate selected lines
- Add/insert words to your own word list
- Cursor movement VIM
- Insert mode - inserting/appending text
- normal mode [Esc]
- insert mode [i]
- replace mode
Selection mode - visual - visual line - visual block
- command line model
Notations for control + V
^V
Ctrl-V
<C-V>
the interface itself is a programming language
- ctrl-v
- drop down with "down arrow" up to the desired line
- shift + i
- type what ever you want to insert in the first line
- type scape
- then go down with the down arrow, it automatically will appear what you want
- take place where your want to start to copy or cut
- Type ctrl-v if you want to select a character or type cltr-V if you want to select a full line.
- if you type ctrl-v move the cursor where you want to cut/copy. Or move down if you want to copy/cut several lines.
- if you want to cut, type Esc then d (delete), if you want to copy, Press Esc then y (yank)
- then you move where you want to paste, then press Esq then type p (paste)
- Press Esc
- type: /
- type what you want to find.
- Once you find it, press n, to the next ocurrence.
- Press Esc
- Type :%s/stringTolookFor/stringToReplace/
if the string contains an character like /, then type / to scape it.
example:
-
before: ()
-
after: (https://github.com/c4arl0s/NavigationAndWorkflows#navigationandworkflows)
-
type
:%s/()/(https:\/\/github.com\/c4arl0s\/NavigationAndWorkflows#navigationandworkflows)/
- Then type enter.
- Press ESC
- press .
- Press Esc
- :1,40s/^/# /
- Press ESC
- :
- Type
:%s/\<direccionMemoria\>/memoryDirection/
- Select the line or lines. Type ESC, then ctrl-V.
- then type: s/$/anyString/
it will looks like this:
:'<,'>s/$/anyString/
let i=1 | '<,'>g/^/ s//\=printf("%d ",i) / | let i+=1
- Press Esc
- type:
:g/.com/d
g - find it globally .com - pattern .com d - delete
- another example: Delete all lines that start with // and it is the end of the line
- press Esc
- type:
:%g/^\/\/$/d
// hola
//
// como estas
//
output:
// hola
// como estas
11. Make lowercase
- Select word, line or several words, then:
:gu
12. Make upercase
- Select word, line or several words, then:
:gU
:%s/(.*)/()/
In normal mode
type:
fa - finds the first a ahead of the cursor Fa - fins the first a before of the cursor.
type in normal mode:
x
in normal mode:
ci[
cw change word caw ciw cc change an entire line cis change inside sentence
g;
yy
Y
Type again g; so many times required to find the last Edit
g;
yiw
this command exclude white spaces around the word.
yaw
This command include whithe spaces sorounding
yi)
yi]
r{character}
R
then start typing
27. redo
Type Esc, then
u
tyoe Esc, then
ctrl-r
Type . to repeat the last command
28. insert mode
- i - insert before the cursor
- I - insert at the beginning of the line
- a - insert after the cursor (aopend)
- A - insert at the end of the line (append)
- o - insert a new line below the current line
- O - insert a new line above the current line
- ea - insert at the end of the word -
1.1 Should Software Engineers Worry About Hardware .........
remove all dots after the title, including the number
:%s/\..*$//
%s substitude all lines .. scaped dot twice, because 1.1 could be taken. .* all $ up to the end of the line // replace with nothing.
then the output is
1.1 Should Software Engineers Worry About Hardware
/^[0-9]
s/$//
s/.[1-9]$//
s/.[1-9][1-9]$//
replace n with the desired number of characters
:%s/^.\{3}//
:%g/^\s*$/d
%s/\s\+$//
/\<\w*\.h\w*\>/
/\<\w*\.m\w*\>/
/<\w*\.swift\w*>/
/\w*(.*:)/
/ [0-9]\+$//
Example:
1. [this is a test](blablablabla) Page 1234
It finds the space character and 1234, remember the space, to find this kind of pattern.
:let i=1 | '<,'>g/^/s//\=i.'. '/ | let i=i+1
zg
h - move cursor left
j - move cursor down
k - move cursor up
l - move cursor right
H - move to top of screen
M - move to middle of screen
L - move to bottom of screen
w - jump forwards to the start of a word
W - jump forwards to the start of a word (words can contain punctuation)
e - jump forwards to the end of a word
E - jump forwards to the end of a word (words can contain punctuation)
b - jump backwards to the start of a word
B - jump backwards to the start of a word (words can contain punctuation)
% - move to matching character (default supported pairs: '()', '{}', '[]' - use :h matchpairs in vim for more info)
0 - jump to the start of the line
^ - jump to the first non-blank character of the line
$ - jump to the end of the line
g_ - jump to the last non-blank character of the line
gg - go to the first line of the document
G - go to the last line of the document
5G - go to line 5
fx - jump to next occurrence of character x
tx - jump to before next occurrence of character x
Fx - jump to previous occurence of character x
Tx - jump to after previous occurence of character x
; - repeat previous f, t, F or T movement
, - repeat previous f, t, F or T movement, backwards
} - jump to next paragraph (or function/block, when editing code)
{ - jump to previous paragraph (or function/block, when editing code)
zz - center cursor on screen
Ctrl + e - move screen down one line (without moving cursor)
Ctrl + y - move screen up one line (without moving cursor)
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
Tip Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.
i - insert before the cursor
I - insert at the beginning of the line
a - insert (append) after the cursor
A - insert (append) at the end of the line
o - append (open) a new line below the current line
O - append (open) a new line above the current line
ea - insert (append) at the end of the word
Esc - exit insert mode