- 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
^VCtrl-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 estas11. Make lowercase
- Select word, line or several words, then:
:gu12. 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;yyYType again g; so many times required to find the last Edit
g;
yiwthis command exclude white spaces around the word.
yawThis command include whithe spaces sorounding
yi)yi]r{character}Rthen start typing
27. redo
Type Esc, then
utyoe 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 1234It finds the space character and 1234, remember the space, to find this kind of pattern.
:let i=1 | '<,'>g/^/s//\=i.'. '/ | let i=i+1zgh - move cursor leftj - move cursor downk - move cursor upl - move cursor rightH - move to top of screenM - move to middle of screenL - move to bottom of screenw - jump forwards to the start of a wordW - jump forwards to the start of a word (words can contain punctuation)e - jump forwards to the end of a wordE - jump forwards to the end of a word (words can contain punctuation)b - jump backwards to the start of a wordB - 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 lineg_ - jump to the last non-blank character of the linegg - go to the first line of the documentG - go to the last line of the document5G - go to line 5fx - jump to next occurrence of character xtx - jump to before next occurrence of character xFx - jump to previous occurence of character xTx - 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 screenCtrl + 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 screenCtrl + f - move forward one full screenCtrl + d - move forward 1/2 a screenCtrl + u - move back 1/2 a screenTip 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 modeYank the content of the first pair of parentheses.
yi)Visually select the content of the second pair of parentheses and put:
yi)p(jdksadjksaldjksaljdklasdjklasdskad) (jdksadjksaldjksaljdklasdjklasdskad)
46 Join lines
Create a command or macro for VIM in order to put in one line this following text:
"The view layer contains all the objects that you see on the user screen
and objects that support them. Among the examples are classes that are
subclasses of UIView like UIButton, UITableView, and more. But not only
are views part of this layer – you can also find transitions, Core Graphics
code, animation, layouts, images, and colors."
As you can see it contains new lines after "screen", "are", "only" and "Graphics" words, remove these new lines and the complete sentence should be on one line. Create a macro or command in VIM in order to do this.
Select the paragraph visually, then join all lines:
vim
vipJvip — select the inner paragraph J — join all selected lines into one
To replace all irregular spacing (tabs, multiple spaces, or newlines) and separate all words with a single space all over the file, run the following command in Vim's normal mode:
vim:%s/\s\+/ /gUse code with caution.i Here is exactly how this actionable command works:
:%s: Tells Vim to run a substitution (search and replace) across the entire file (from line 1 to the end).\s\+: The search pattern. It matches any sequence of whitespace characters (one or more), including tabs (\t), newlines, and multiple continuous spaces./: The replacement. It replaces any match found with exactly one single space./g: The global flag. It ensures this substitution happens on every single occurrence in the line, rather than just the first one.
