Global

  • :h[elp] keyword - open help for keyword
  • :sav[eas] file - save file as
  • :clo[se] - close current pane
  • :ter[minal] - open a terminal window
  • K - open man page for word under the cursor
Tip Run vimtutor in a terminal to learn the first Vim commands.

Pergerakan Kursor

  • h - memindahkan kursor ke kiri
  • j - memindahkan kursor ke bawah
  • k - memindahkan kursor ke atas
  • l - memindahkan kursor ke kanan
  • gj - move cursor down (multi-line text)
  • gk - move cursor up (multi-line text)
  • H - move to top of screen
  • M - move to middle of screen
  • L - move to bottom of screen
  • w - lompat ke awal kata selanjutnya
  • W - lompat ke awal kata selanjutanya (kata-kata dapat mengandung tanda baca)
  • e - lompat ke akhir kata selanjutnya
  • E - lompat ke akhir kata selanjutnya (kata-kata dapat mengandung tanda baca)
  • b - lompat ke awal kata sebelumnya
  • B - lompat ke awal kata sebelumnya (kata-kata dapat mengandung tanda baca)
  • ge - jump backwards to the end of a word
  • gE - jump backwards to the end of a word (words can contain punctuation)
  • % - move to matching character (default supported pairs: '()', '{}', '[]' - use :h matchpairs in vim for more info)
  • 0 - lompat ke awal baris saat ini
  • ^ - lompat ke karakter pertama baris saat ini
  • $ - lompat ke akhir baris saat ini
  • g_ - jump to the last non-blank character of the line
  • gg - pindah ke baris teratas dokumen
  • G - pindah ke baris paling akhir dokumen
  • 5gg or 5G - pindah ke baris ke-5
  • gd - move to local declaration
  • gD - move to global declaration
  • fx - lompat tepat pada karakter x
  • tx - lompat tepat sebelum karakter 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
  • } - Lompat ke paragraf berikutnya (atau blok kode, saat mengedit kode)
  • { - Lompat ke paragraf sebelumnya (atau blok kode, saat mengedit kode)
  • zz - center cursor on screen
  • zt - position cursor on top of the screen
  • zb - position cursor on bottom of the 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.

Mode Insert - menyisipkan/menambahkan text

  • i - menyisipkan sebelum kursor
  • I - menyisipkan pada permulaan baris
  • a - menyisipkan (menambahkan) setelah kursor
  • A - menyisipkan (menambahkan) pada akhir baris
  • o - menambahkan (membuka) baris baru dibawah baris saat ini
  • O - menambahkan (membuka) baris baru diatas baris saat ini
  • ea - menyisipkan (menambahkan) pada akhir kata
  • Ctrl + h - delete the character before the cursor during insert mode
  • Ctrl + w - delete word before the cursor during insert mode
  • Ctrl + j - begin new line during insert mode
  • Ctrl + t - indent (move right) line one shiftwidth during insert mode
  • Ctrl + d - de-indent (move left) line one shiftwidth during insert mode
  • Ctrl + n - insert (auto-complete) next match before the cursor during insert mode
  • Ctrl + p - insert (auto-complete) previous match before the cursor during insert mode
  • Ctrl + rx - insert the contents of register x
  • Ctrl + ox - Temporarily enter normal mode to issue one normal-mode command x.
  • Esc or Ctrl + c - berhenti dari mode insert

Editing

  • r - mengubah satu karakter
  • R - replace more than one character, until ESC is pressed.
  • J - menyambung baris di bawah dengan baris saat ini
  • gJ - join line below to the current one without space in between
  • gwip - reflow paragraph
  • g~ - switch case up to motion
  • gu - change to lowercase up to motion
  • gU - change to uppercase up to motion
  • cc - menghapus isi baris saat ini untuk diganti dengan text lain
  • c$ or C - menghapus semua karakter setelah kursor hingga akhir baris
  • ciw - change (replace) entire word
  • cw or ce - menghapus satu kata untuk diganti dengan kata lain
  • s - menghapus karakter dan mengganti text
  • S - menghapus isi baris saat ini untuk diganti dengan text lain (sama dengan cc)
  • xp - menukar dua karakter (delete dan paste)
  • u - undo
  • U - restore (undo) last changed line
  • Ctrl + r - redo
  • . - ulangi perintah sebelumnya

Menandai Text (Visual Mode)

  • v - memulai mode visual, menandai baris-baris, lalu jalankan perintah (misal y-yank)
  • V - memulai mode visual secara per baris
  • o - pindah ke ke bagian akhir dari area lain yang telah ditandai
  • Ctrl + v - memulai mode visual blok
  • O - pindah ke sudut lain pada sebuah blok
  • aw - menandai kata
  • ab - a block with ()
  • aB - a block with {}
  • at - a block with <> tags
  • ib - inner block with ()
  • iB - inner block with {}
  • it - inner block with <> tags
  • Esc or Ctrl + c - berhenti dari mode visual
Tip Instead of b or B one can also use ( or { respectively.

Perintah - perintah visual

  • > - menggeser text ke kanan
  • < - menggeser text ke kiri
  • y - yank (menyalin) text yang ditandai
  • d - menghapus text yang ditandai
  • ~ - menukar huruf kapital-kapitil
  • u - change marked text to lowercase
  • U - change marked text to uppercase

Registers

  • :reg[isters] - show registers content
  • "xy - yank into register x
  • "xp - paste contents of register x
  • "+y - yank into the system clipboard register
  • "+p - paste from the system clipboard register
Tip Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.
Tip Special registers:

0 - last yank
" - unnamed register, last delete or yank
% - current file name
# - alternate file name
* - clipboard contents (X11 primary)
+ - clipboard contents (X11 clipboard)
/ - last search pattern
: - last command-line
. - last inserted text
- - last small (less than a line) delete
= - expression register
_ - black hole register

Marks

  • :marks - list of marks
  • ma - set current position for mark A
  • `a - jump to position of mark A
  • y`a - yank text to position of mark A
  • `0 - go to the position where Vim was previously exited
  • `" - go to the position when last editing this file
  • `. - go to the position of the last change in this file
  • `` - go to the position before the last jump
  • :ju[mps] - list of jumps
  • Ctrl + i - go to newer position in jump list
  • Ctrl + o - go to older position in jump list
  • :changes - list of changes
  • g, - go to newer position in change list
  • g; - go to older position in change list
  • Ctrl + ] - jump to the tag under cursor
Tip To jump to a mark you can either use a backtick (`) or an apostrophe ('). Using an apostrophe jumps to the beginning (first non-blank) of the line holding the mark.

Macros

  • qa - record macro a
  • q - stop recording macro
  • @a - run macro a
  • @@ - rerun last run macro

Memotong dan menempel

  • yy - menyalin sebaris text
  • 2yy - menyalin dua baris text
  • yw - menyalin satu kata
  • yiw - yank (copy) word under the cursor
  • yaw - yank (copy) word under the cursor and the space after or before it
  • y$ or Y - menyalin dari posisi sekarang hingga akhir baris saat ini
  • p - menempelkan salinan dari clipboard setelah kursor
  • P - menempelkan salinan dari clipboard sebelum kursor
  • gp - put (paste) the clipboard after cursor and leave cursor after the new text
  • gP - put (paste) before cursor and leave cursor after the new text
  • dd - menghapus satu baris
  • 2dd - menghapus (memotong) dua baris
  • dw - menghapus (memotong) kata
  • diw - delete (cut) word under the cursor
  • daw - delete (cut) word under the cursor and the space after or before it
  • :3,5d - delete lines starting from 3 to 5
Tip You can also use the following characters to specify the range:
e.g.

:.,$d - From the current line to the end of the file
:.,1d - From the current line to the beginning of the file
:10,$d - From the 10th line to the beginning of the file

  • :g/{pattern}/d - delete all lines containing pattern
  • :g!/{pattern}/d - delete all lines not containing pattern
  • d$ or D - menghapus (memotong) hingga ke akhir baris saat ini
  • x - menghapus (memotong) satu karakter

Indent text

  • >> - indent (move right) line one shiftwidth
  • << - de-indent (move left) line one shiftwidth
  • >% - indent a block with () or {} (cursor on brace)
  • <% - de-indent a block with () or {} (cursor on brace)
  • >ib - indent inner block with ()
  • >at - indent a block with <> tags
  • 3== - re-indent 3 lines
  • =% - re-indent a block with () or {} (cursor on brace)
  • =iB - re-indent inner block with {}
  • gg=G - re-indent entire buffer
  • ]p - paste and adjust indent to current line

Keluar

  • :w - menulis (menyimpan) ke file, tapi tidak keluar
  • :w !sudo tee % - menulis (menyimpan) ke file dengan sudo
  • :wq or :x or ZZ - menulis (menyimpan) lalu keluar
  • :q - keluar (batal jika ada perubahan yang belum disimpan)
  • :q! or ZQ - keluar dan abaikan perubahan yang telah dibuat
  • :wqa - write (save) and quit on all tabs

Cari dan Tukar

  • /pattern - pencarian dengan pola
  • ?pattern - pencarian ke belakang dengan pola
  • \vpattern - pola 'magic': karakter-karater non alfanumerik diinterpretaskan sebagai sebagai simbol regex khusus (tidak membutuhkan escape)
  • n - ulangi pencarian ke arah selanjutnya
  • N - ulangi pencarian ke arah sebaliknya
  • :%s/old/new/g - tukar yang lama dengan yang baru di keseluruhan file
  • :%s/old/new/gc - tukar yang lama dengan yang baru di kesluruhan file dengan konfirmasi
  • :noh[lsearch] - menghilangkan sorotan pada hasil-hasil pencarian

Pencarian di beberapa file

  • :vim[grep] /pattern/ {`{file}`} - pencarian pola di beberapa file
e.g. :vim[grep] /foo/ **/*
  • :cn[ext] - lompat ke temuan selanjutnya
  • :cp[revious] - lompat ke temuan sebelumnya
  • :cope[n] - membuka windows baru yang menampilkan hasil temuan
  • :ccl[ose] - close the quickfix window

Tabs

  • :tabnew or :tabnew {page.words.file} - membuka file di tab baru
  • Ctrl + wT - move the current split window into its own tab
  • gt or :tabn[ext] - pindah ke tab selanjutnya
  • gT or :tabp[revious] - pindah ke tab sebelumnya
  • #gt - pindah ke tab nomor #
  • :tabm[ove] # - pindahkan tab saat ini ke urutan ke # (urutan mulai dari angka 0)
  • :tabc[lose] - tutup tab saat ini dan semua jendela di dalamnya
  • :tabo[nly] - tutup semua tab kecuali tab yang aktif saat ini
  • :tabdo command - menjalankan perintah command pada semua tab (misal: :tabdo q - akan menutup semua tab)

Bekerja dengan beberapa file

  • :e[dit] file - mengedit file di dalam buffer baru
  • :bn[ext] - beralih ke buffer selanjutnya
  • :bp[revious] - beralih ke buffer sebelumnya
  • :bd[elete] - menghapus buffer (menutup file)
  • :b[uffer]# - go to a buffer by #
  • :b[uffer] file - go to a buffer by file
  • :ls or :buffers - daftar buffer yang terbuka
  • :sp[lit] file - buka file di buffer baru dan split jendela
  • :vs[plit] file - buka file di buffer baru dan split jendela secara vertikal
  • :vert[ical] ba[ll] - edit all buffers as vertical windows
  • :tab ba[ll] - edit all buffers as tabs
  • Ctrl + ws - split jendela
  • Ctrl + wv - split jendela secara vertikal
  • Ctrl + ww - berganti jendela
  • Ctrl + wq - keluar dari jendela
  • Ctrl + wx - exchange current window with next one
  • Ctrl + w= - make all windows equal height & width
  • Ctrl + wh - memindahkan kursor ke jendela kiri (split vertikal)
  • Ctrl + wl - memindahkan kursor ke jendela kanan (split vertikal)
  • Ctrl + wj - memindahkan kursor ke jendela bawah (split horizontal)
  • Ctrl + wk - mmemindahkan kursor ke jendela atas (split horizontal)
  • Ctrl + wH - make current window full height at far left (leftmost vertical window)
  • Ctrl + wL - make current window full height at far right (rightmost vertical window)
  • Ctrl + wJ - make current window full width at the very bottom (bottommost horizontal window)
  • Ctrl + wK - make current window full width at the very top (topmost horizontal window)

Diff

  • zf - manually define a fold up to motion
  • zd - delete fold under the cursor
  • za - toggle fold under the cursor
  • zo - open fold under the cursor
  • zc - close fold under the cursor
  • zr - reduce (open) all folds by one level
  • zm - fold more (close) all folds by one level
  • zi - toggle folding functionality
  • ]c - jump to start of next change
  • [c - jump to start of previous change
  • do or :diffg[et] - obtain (get) difference (from other buffer)
  • dp or :diffpu[t] - put difference (to other buffer)
  • :diffthis - make current window part of diff
  • :dif[fupdate] - update differences
  • :diffo[ff] - switch off diff mode for current window
Tip The commands for folding (e.g. za) operate on one level. To operate on all levels, use uppercase letters (e.g. zA).
Tip To view the differences of files, one can directly start Vim in diff mode by running vimdiff in a terminal. One can even set this as git difftool.