Login atau daftar akun gratis untuk membaca cheat sheet ini.
# Ubuntu/Debian
sudo apt install neovim
# macOS
brew install neovim
# Arch Linux
sudo pacman -S neovim
Buka Neovim:
nvim # buka editor
nvim file.txt # buka file
nvim +42 file.txt # buka di line 42
nvim -d file1 file2 # diff mode
nvim -R file.txt # read-only modeNeovim punya beberapa mode dasar yang harus dihafal.
| Mode | Cara masuk | Fungsi |
|---|---|---|
| Normal | Esc atau Ctrl+[ | Navigasi, command |
| Insert | i, a, o, I, A, O | Ketik teks |
| Visual | v (char), V (line), Ctrl+v (block) | Seleksi teks |
| Command | : (dari Normal) | Eksekusi command |
h k
| |
| <- h j k l ->
| |
v v
j l
j = turun
k = naik
h = kiri
l = kananw " awal word berikutnya
b " awal word sebelumnya
e " akhir word berikutnya
W " awal WORD (spasi-delimited) berikutnya
B " awal WORD sebelumnya
E " akhir WORD berikutnya
ge " akhir word sebelumnyaBedanya word vs WORD:
0 " awal line
^ " karakter non-blank pertama di line
$ " akhir line
g_ " karakter non-blank terakhir
gg " baris pertama file
G " baris terakhir file
5G " ke baris 5
50% " ke 50% file
{ " paragraf sebelumnya
}H " top of screen (High)
M " middle of screen (Middle)
L " bottom of screen (Low)
Ctrl+d " scroll down half page
Ctrl+u " scroll up half page
Ctrl+f " scroll down full page
Ctrl+b " scroll up full page
/pattern " cari ke depan
?pattern " cari ke belakang
n " match berikutnya
N " match sebelumnya
* " cari word di bawah cursor (forward)
# " cari word di bawah cursor (backward)
:set hlsearch " highlight semua matches
:noh " clear search highlighti " insert sebelum cursor
a " insert setelah cursor
I " insert di awal line
A " insert di akhir line
o " buka line baru di bawah, insert mode
O " buka line baru di atas, insert mode
s " hapus karakter, insert mode
S " hapus line, insert mode
cw " change word (delete word, insert mode)
x " hapus karakter (cut)
dd " hapus line (cut)
dw " hapus word
d$ atau D " hapus sampai akhir line
dG " hapus sampai akhir file
dgg " hapus sampai awal file
dt( " hapus sampai sebelum tanda kurung
yy " yank (copy) line
Vim ngikuti pola: [count] [operator] [motion]
Operator Fungsi
d delete (cut)
y yank (copy)
c change (delete + insert)
> indent
< dedent
= auto-indent
~ toggle case
gu lowercase
gU uppercase
! filter through external commandContoh kombinasi:
d2w " hapus 2 words
c$ " change sampai akhir line
>5j " indent 5 baris ke bawah
gg=G " auto-indent seluruh file
gUU " uppercase entire lineu " undo
Ctrl+r " redo
U " undo all changes di line saat inir{x} " replace 1 karakter dengan x
R " replace mode (overwrite)
~ " toggle case karakterv " visual mode (character-wise)
V " visual mode (line-wise)
Ctrl+v " visual block mode
# Setelah seleksi:
d " delete
y " yank
c " change
> " indent
< " dedent
# Multi-line edit (column select):
Ctrl+v " masuk visual block
jjjj " select ke bawah
I " insert sebelum block
# ketik teks, tekan Esc
# teks akan di-insert di semua line yang terseleksi
# Comment multiple lines:
:e file.txt " buka file di buffer baru
:badd file.txt " add buffer tanpa buka
:ls atau :buffers " list semua buffers
:bN " ke buffer N
:bn atau :bnext " buffer berikutnya
:bp atau :bprev " buffer sebelumnya
:bf " buffer pertama
:bl
:sp atau :split " horizontal split
:vs atau :vsplit " vertical split
:sp file.txt " split + buka file
Ctrl+w h " ke window kiri
Ctrl+
:tabnew file.txt " buka tab baru dengan file
:tabnew " tab kosong
:tabn atau :tabnext " tab berikutnya
:tabp atau :tabprev " tab sebelumnya
:tabfirst " tab pertama
:tablast " tab terakhir
:tabc " close tab
:tabo " close semua tab kecuali aktif
:tabm 0
:w " write (save)
:w file.txt " write as (save as)
:wq atau :x atau ZZ " write + quit
:q " quit
:q! atau ZQ " force quit (no save)
:wqa " write all + quit:s/old/new/ " replace first occurrence di line
:s/old/new/g " replace all di line
:%s/old/new/g " replace all di file
:%s/old/new/gc " replace all dengan confirm
:%s/old/new/gi " replace all, case insensitive
:5
:set number " tampilkan line numbers
:set relativenumber " relative line numbers
:set tabstop=4 " tab width
:set shiftwidth=4 " indent width
Konfigurasi modern Neovim pakai Lua dan lazy.nvim.
-- ~/.config/nvim/init.lua
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data")
:Lazy " buka UI
:Lazy install " install semua plugins
:Lazy update " update semua plugins
:Lazy sync " install + clean
:Lazy clean " hapus plugins yang tidak terpakai
:Lazy check " cek updates
:Lazy log " lihat log
:Lazy profile " profiling startup time-- ~/.config/nvim/lua/lsp.lua
require("mason").setup()
require("mason-lspconfig").setup({
ensure_installed = { "lua_ls", "tsserver", "pyright",
-- Global keymaps untuk LSP
vim.api.nvim_create_autocmd("LspAttach", {
callback = function(args)
local opts = { buffer = args.buf }
-- ~/.config/nvim/lua/cmp.lua
local cmp = require("cmp")
local luasnip = require("luasnip")
cmp.setup
local telescope = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", telescope.find_files, {})
vim.keymap.
:Telescope find_files
:Telescope live_grep
:Telescope buffers
:Telescope help_tags
:Telescope git_files
:Telescope oldfiles
:Telescope command_historyrequire("nvim-treesitter.configs").setup({
ensure_installed = {
"lua", "vim", "vimdoc", "query",
"javascript", "typescript", "tsx",
Struktur direktori konfigurasi yang clean:
~/.config/nvim/
init.lua " entry point
lua/
core/
options.lua " vim options
keymaps.lua " global keymaps
autocmds.lua " autocommands
plugins/
lsp.lua " LSP config
cmp.lua " completion
telescope.lua " fuzzy finder
treesitter.lua " syntax highlighting
lualine.lua " statuslineContoh init.lua:
-- Require modules
require("core.options")
require("core.keymaps")
require("core.autocmds")
-- Options
vim.opt.number = true
vim.
-- Leader key mappings
local map = vim.keymap.set
-- Clear search highlight
map("n", "<Esc>", "<cmd>nohlsearch<CR>"
| Replace | R | Overwrite teks |
| Terminal | :terminal | Shell di dalam Neovim |