Skip to content

Instantly share code, notes, and snippets.

@kkoziarski
Last active Oct 21, 2021
Embed
What would you like to do?
VIM

VIM

h/j/k/l - cursors

Usecases

disable VsVim: Alt+Ctrl+Shift+F12

Remove method parameter

  1. For the first argument, this key-combination goes to opening parenthesis, and deletes everything up to the next comma, including the space after it: T(df,x
  2. For a middle argument, this key-combination goes to the previous comma, and deletes it and everything until the next comma: F,dt,
  3. For the last argument, this key-combination goes to the previous comma, and deletes it and everything until the closing parenthesis: F,dt)

Moving: motions

w: jump to the beginning of the next _W_ord

b: (B_ack) to jump to the beginning of a word backwards

e: (E_nd) to jump to the end of a word

ge: to jump to the (E_nd) of a word backwards

f{character} | F{character} = (F_ind)

; - to go to the next occurrence of the character or

, - to go to the previous one

; | , = After using f{character} you can type ; to go to the next occurrence of the character or , to go to the previous one. You can see the ; and , as commands for repeating the last character search.

t{character} | T{character} = (un_T_il)

/{pattern}: to search forward inside a file

?{pattern}: to search backwards

0: moves to the first character of a line

^: moves to the first non-blank character of a line

$: moves to the end of a line

g_: moves to the non-blank character at the end of a line

} : jumps entire paragraphs downwards

{ : similarly but upwards

CTRL-D: lets you move down half a page by scrolling the page

CTRL-U: lets you move up half a page also by scrolling

/{pattern}: to search forward inside a file

?{pattern}: to search backwards

/<Enter> or ?<Enter>: run the last search (forwards or backwards).

* to do a search for the word under the cursor (# to do the same backwards).

{count}{motion}: [2w,5j,3;,2/baby,2/cuc] - counts are numbers which let you multiply the effect of a command

gg: to go to the top of the file.

{line}gg: to go to a specific line.

G: to go to the end of the file.

%: jump to matching ({[]})

gd: to jump(g_o) to d_efinition of whatever is under your cursor.

gf: to jump(g_o) to a f_ile in an import.

Editing Magic: operator

{operator}{count}{motion}

{count}{operator}{motion}

Operators

c (c_hange): Change

y (y_ank): Copy in Vim jargon

p (put): Paste in Vim jargon

g~ (switch case): Changes letters from lowercase to uppercase and back. Alternatively, use gu to make something lowercase and gU to make something uppercase

gu - lowercase

gU - uppercase

>: (shift right): Adds indentation

< (shift left): Removes indentation

= (format code): Formats code

c/hello changes everything until the first occurrence of hello.

ggyG copies a whole document

gUw capitalizes a word

yi(: yanks everything within ( and so on…

d2w: delete two words

d5j: delete 5 lines downwards

df': to delete everything in the current line from the cursor until the first occurrence of the ' character, INCLUDING the character itself

dt': to delete everything in the current line from the cursor until the first occurrence of the ' character, EXCLUDING the character itself

d/hello: to delete everything until the first occurrence of hello

ggdG: to delete a complete document

Text objects

{operator}{a|i}{text-object}

a: around

i: inner

w for word

s for sentence

', ", ``` for quotes

p for paragraph

b or (, ) for block surrounded by (),

B or {, }for block surrounded by{}`

<, > for a block surrounded by <>

[, ] for a block surrounded by []

t for tag.

D deletes from the cursor to the end of a line

daw to delete a word (plus trailing whitespace)

ciw to change inner word

das to delete a sentence (dis to delete inner sentence)

da" to delete something in double quotes including the quotes themselves (di" deletes only the content inside the quotes and spares the quotes)

ci" to change something inside double quotes

dap to delete a paragraph

dab da( or da) to delete a block surrounded by (

daB da{ or da} to delete a block surrounded by {

dat to delete an HTML tag

cit to change the contents of an HTML tag

x is equivalent to dl and deletes the character under the cursor

X is equivalent to dh and deletes the character before the cursor

s is equivalent to ch, deletes the character under the cursor and puts you into Insert mode

~ to switch case for a single character

cc changes a complete line

C changes from the cursor until the end on the lin

Inserting text

i: for insert and,

a: for append.

I: puts you in Insert mode at the beginning of the current line whilst,

A: puts you in Insert mode at the end.

o: inserts a new line below the current one and drops you into Insert mode (mnemonic open a line below)

O: inserts a new line above the current one and also drops you into Insert mode

gi: puts you into Insert mode at the last place you made a change. This is great if you drop from Insert mode by mistake and want to go back where you were and continue typing. (This behavior is slightly different to Vim where gi sends you to the last place you left Insert mode).

CTRL-h: lets you delete the last character you typed

CTRL-w: lets you delete the last word you typed

CTRL-u: lets you delete the last line you typed

Selecting text - Visul mode

v for visual mode character-wise. This mode lets you select text character by character

V for visual mode line-wise. This other one lets you select text line by line

<C-V> for visual mode block-wise. This last mode lets you select text using rectangular blocks

v{motion}{operator}

lvtbd

jVjjd

<C-V>8jc<li><ESC>C-V8j$A</li>

Operations on search

gn -

  1. If you are on top of a search match, it selects the match in Visual mode.
  2. If you are in Visual mode, it extends your current selection until the end of the next match.
  3. (and the best part) If you are in Operator-pending mode, it operates on the next match. gn - there’s no need to combine n and . because . already includes the next match.

/cucumber<ENTER>dgn4.

/(cucumber | cucumber)<ENTER>dgn4.

Copying and pasting

yl - copy character

yy - copy line

yy{count}p - duplicates line n-times

yyp - DUPLICATES line

yyP - duplicate line ABOVE

ddp & ddP - SWAP lines

yi"P - copy inside "

yi(P - copy inside (

Registers

:reg

": unnamed register a-z: named registers 0: yank register 1-9: cut registers

Pasting in insert mode

CTRL-R " pastes the contents of the unnamed register CTRL-R a pastes the contents of register a CTRL-R 0 pastes the contents of the yank register

Command-line mode

:.,$d - to delete from the current line to the end of the file :0,+10d - to delete the first 10 lines :.,+2d - to delete the current line and the next two ones :10,12d - to delete lines 10, 11 and 12

@: - you will repeat the last ex command, from then on you can repeat it again with @@ @@ - repeat it again

Substituting text

:[range]s/{pattern}/{substitute}/{flags}

:s/led/gold - transmutes the first occurrence of led in the current line into gold.

:s/led/gold/g - all occurrences in the current line

:%s/led/gold/g - all occurrences for a whole file

/gi - case insensitive

Surrounding

ds to delete the surroundings

cs to change the surroundings

ys to add surroundings

ds{count}{motion}

cs{count}{motion}

ys{count}{motion}

ds' to delete the surrounding ' (ds{char})

cs'" to change the surrounding ' for " (cs{old}{new})

ysaptli> to surround a paragraph with an <li> tag (ys{motion}{char})

syntax on
" pokazuje menu z lista plikow itp
set wildmenu
"sam zmienia katalogi na te w kotrych edytuje pliki
set autochdir
set autoindent
set history=1000
set title
set tabpagemax=50
set ruler
" autocmd FileType php set omnifunc=phpcomplete#CompletePHP
colorscheme jellybeans
"filetype plugin indent on
set t_Co=256
"for python developement
set tabstop=8
set expandtab
set shiftwidth=4
set softtabstop=4
set mouse=a
nmap <F7> gT
nmap <F9> gt
autocmd TabEnter,BufEnter *.php nmap <F8> :!php -l -d display_errors=on %<CR>
autocmd TabEnter,BufEnter *.pl,*.pm nmap <F8> :!perl -c %<cr>
autocmd TabEnter,BufEnter *.php nmap <F6> :!php %<CR>
autocmd TabEnter,BufEnter *.pl nmap <F6> :!perl %<CR>
autocmd TabEnter,BufEnter *.sh nmap <F6> :!./%<CR>
nmap <F2> :w!<CR>
set pastetoggle=<F10>
set cursorline
"if You serach for all lowercase, then it is case-insensitive
set ignorecase
" else: case sensitive :)
set smartcase
" higlight searches during typing
set incsearch
" get rid of stupid F1 key ;)
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
"select just pasted text
nmap gp `[v`]
set background=dark
noremap H ^
noremap L $

Alfabet VIMa

vim nazwa_pliku

często jest tak w VIM że mała litera robi akcję X, a duża litera przeciwieństo X

VIM = kursory lub h/j/k/l

:set nocompatible

:set autoindent = uruchamia automatyczne wyrównanie kodu (wcięcia)

:set incsearch = szukanie incrementalne, czyli pokazuje w locie co znalazło

:set hlsearch = wyświetla wszystkie znalezione wzorce. hl - skrót od "highlight" czyli podświetlenie

:nohl = "no highlight", czyli wyłącz podświetlenie

e = end (koniec, tutaj: słowa)

b = beginning (początek)

$ = skok na koniec wiersza

^ = skok na początek wiersza

G = skocz na koniec pliku

gg = skocz na początek pliku

7G = skok do 7 linii

3 = skok do 3 linii

/ = szukaj

? = szukaj wstecz

n = next (następny) wynik

N = porzedni wynik

i = insert - wstaw tekst

a = append - dodaj text

A = dodaj na końcu wiersza

u = undo - cofnij akcję

ctrl+r = redo - powtórz

o = open - otwiera nowy paragraf

O = nowy paragraf (linię wyżej)

r = replace (zamiana) znaku

c = change - większa zmiana. Używamy gdy zmieniamy coś więcej jak jedną literę

ce = zmiana tekstu do końca słowa (c = change, e = end of word)

cb = zmiana tekstu do początku słowa

1,2,3 number = wielokrotne powtórzenie polecenia ce = zmień do końca słowa

c3d = zmień do końca 3 słów

r = replace, podmienia jedną literę

R = podmienia kolejne litery aż naciśniesz <ESC>

t = to/till (aż do)

i = inside

ctH = zmienia wszystko do 'H' (c = change, t = till, H = duża litera 'h')

dd = delete - usuwanie linii

d = usuwanie zaznaczonego tekstu

d5d = usuwa 5 linijek

5dd = usuwa 5 linijek

ci{ = zmień wszystko w tych nawiasach (c = change, i = inside, { = nawiasy klamrowe)

* = skocz to innych wystąpień tego słowa (np. do definicji)

% = skocz do odpowiadającego nawiasu

v = VISUAL - wizualne wskazywanie fragmentu tekstu

V = zaznacz tekst (cała linia)

v = swobodne zaznaczanie

yy = yanks - skopiuj linię

p = paste - wklej

P = paste - wklej linię wyżej

ci" = change inside " (cudzysłowa)

:wq = zapisz i wyjdź

https://www.youtube.com/watch?v=n8QolyJyNc4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment