Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

27 Commits

Repository files navigation

  1. Basics of VIM
  2. How to insert a string at the beginning of a line
  3. How to cut and paste (ctrl-v or ctrl-V)
  4. How to find a string
  5. how to replace with an / across the string to replace
  6. Repeats the last action
  7. Insert a # character at the beginning of the line
  8. Find an precise string an replace with something
  9. Insert a character or string at the end of a selected line
  10. Insert a consecutive number at the beginning of a selected line
  11. Delete all lines that contains a specific pattern
  12. Make lowercase
  13. Make upercase
  14. Find any String inside parenthesis Ex. (http://...) with empty content ()
  15. Find a particular character in a line using f
  16. Delete only a character
  17. Change inside brackets
  18. Quickly change a word or line
  19. Jump to the place of last Edit
  20. Yank the current line, including the newline character at the end of the new line, yy or Y
  21. Jump to the place before of the last Edit
  22. Yank the current word (no spaces)
  23. Yank the current word (with sorounding spaces)
  24. Yank all contained inside parenthesis ()
  25. Yank all contained inside brackets
  26. Replace the character under the cursor
  27. Enter insert mode, replacing characters rather than inserting
  28. redo
  29. insert mode
  30. remove ... from this line: 1.1 Should Software Engineers Worry About Hardware ......... 23
  31. Find any line starting by any number
  32. Delete the last character the end of the line
  33. Delete the last character at the end of the line if it is a number
  34. Delete the last two characters at the end of the line if they both were a number
  35. Delete the first n characters at the end of a line
  36. Delete empty lines
  37. Delete 1 or more of the preceding spaces at the end of the line
  38. find any header or implementation name file (class.h class.m)
  39. Find a file's name string like class.swift
  40. Find a swift or objective-c method like nameMethod(parameter:)
  41. Using your last course, find any number of digits at the end of a sentence in any line
  42. Enumerate selected lines
  43. Add/insert words to your own word list
  44. Cursor movement VIM
  45. 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
  1. take place where your want to start to copy or cut
  2. Type ctrl-v if you want to select a character or type cltr-V if you want to select a full line.
  3. 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.
  4. if you want to cut, type Esc then d (delete), if you want to copy, Press Esc then y (yank)
  5. then you move where you want to paste, then press Esq then type p (paste)
  1. Press Esc
  2. type: /
  3. type what you want to find.
  4. Once you find it, press n, to the next ocurrence.
  1. Press Esc
  2. Type :%s/stringTolookFor/stringToReplace/

if the string contains an character like /, then type / to scape it.

example:

:%s/()/(https:\/\/github.com\/c4arl0s\/NavigationAndWorkflows#navigationandworkflows)/
  • Then type enter.
  1. Press ESC
  2. press .
  1. Press Esc
  2. :1,40s/^/# /
  1. Press ESC
  2. :
  3. Type
:%s/\<direccionMemoria\>/memoryDirection/
  1. Select the line or lines. Type ESC, then ctrl-V.
  2. then type: s/$/anyString/

it will looks like this:

:'<,'>s/$/anyString/
let i=1 | '<,'>g/^/ s//\=printf("%d ",i) / | let i+=1
  1. Press Esc
  2. 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
  1. press Esc
  2. type:
:%g/^\/\/$/d
// hola
//// como estas
//

output:

// hola
// como estas
  • Select word, line or several words, then:
:gu
  • 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;
yyY

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

  • 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.

Screen Shot 2021-04-16 at 13 45 23

:let i=1 | '<,'>g/^/s//\=i.'. '/ | let i=i+1
zg
h - 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 mode

Yank 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)

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.

Option 1: Visual Selection + Join

Select the paragraph visually, then join all lines:

vim

vipJ

vip — select the inner paragraph J — join all selected lines into one

47

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\+/ /g

Use 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.

About

wiki VIM

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors