Toolbox Vim
Task 1
Lets get started! To check whether Vim is installed:
- Launch a Terminal Window
- Type "vim"
If you're looking at the Vim splash page
Then you're in luck!
Otherwise type:
- Debian-Based Distributions:
sudo apt install vim- Arch-Based Distributions:
sudo pacman -S vim- Fedora-Based Distributions:
sudo dnf install vim-enhanced- Windows: Go to: https://www.vim.org/download.php#pc
Download and install the "self-installing-executable"
Task 2
š¹ Pengenalan Vim
Vim adalah text editor berbasis terminal yang sangat powerful. Vim bekerja dengan mode, bukan sekadar mengetik seperti editor biasa.
š¹ Mode di Vim
Ada 3 mode utama yang wajib dipahami:
1ļøā£ Command Mode (Normal Mode)
- Mode default saat Vim dibuka
- Digunakan untuk:
- Navigasi
- Menghapus teks
- Menyalin (copy)
- Menjalankan perintah
- Tekan
Esckapan pun untuk kembali ke mode ini
2ļøā£ Insert Mode
- Digunakan untuk mengetik / mengedit teks
- Masuk ke Insert Mode dengan:
iā insert sebelum kursoraā append setelah kursoroā buat baris baru di bawahOā buat baris baru di atas
- Keluar dengan
Esc
3ļøā£ Visual Mode
- Digunakan untuk menyeleksi teks
- Masuk dengan:
vā seleksi per karakterVā seleksi per barisCtrl + vā block/column selection
- Setelah seleksi, bisa langsung:
dā deleteyā yank (copy)
š¹ Navigasi Dasar
Vim tidak mengandalkan arrow key, tapi key cluster:
| Arah | Tombol |
|---|---|
| Kiri | h |
| Bawah | j |
| Atas | k |
| Kanan | l |
Ingat: h j k l = navigasi utama Vim
Navigasi Kata
wā lompat ke awal katabā lompat ke awal kataeā lompat ke akhir kata
Navigasi Cepat File
ggā ke baris paling atasGā ke baris paling bawah:nā ke baris ke-n (contoh:10)0ā ke awal baris$ā ke akhir baris
š¹ Menyisipkan & Menambahkan Teks (Insert vs Append)
Shortcut ini sangat penting agar editing jadi cepat:
| Perintah | Fungsi |
|---|---|
i | Insert sebelum kursor |
a | Append setelah kursor |
I | Insert di awal baris |
A | Append di akhir baris |
o | Baris baru di bawah |
O | Baris baru di atas |
š” Tips: Biasakan pakai shortcut ini, jangan cuma i
š¹ Bantuan di Vim
Vim punya dokumentasi bawaan yang lengkap banget.
Membuka Help
:helpHelp untuk Command Tertentu
:help ggContoh info dari :help gg:
gg= lompat ke awal file- Bisa pakai angka ā
10gg(lompat ke baris 10) - Setara dengan
<Ctrl + Home>
š¹ Kesimpulan
- Vim berbasis mode
- Kuasai Normal Mode dulu
- Hafalkan hjkl
- Biasakan insert/append shortcut
- Jangan ragu pakai
:help
- How do we enter "INSERT" mode?
i
- How do we start entering text into our new Vim document?
typing
- How do we return to command mode?
esc
- How do we move the cursor left?
h
- How do we move the cursor right?
l
- How do we move the cursor up?
k
- How do we move the cursor down?
j
- How do we jump to the start of a word?
w
- How do we jump to the end of a word?
e
- How do we insert (before the cursor)
i
- How do we insert (at the beginning of the line?)
I
- How do we append (after the cursor)
a
- How do we append (at the end of the line)
A
- How do we make a new line under the current line?
o
Task 3
Selamat! š Sekarang kamu sudah bisa mengetik, navigasi, dan pakai fungsi dasar Vim. Tinggal satu hal penting: cara keluar dari Vim (biar nggak kejebak š).
Ada 6 cara utama:
:wš Simpan file, tidak keluar:w !sudo tee %(atau edit sebagai root) š Simpan file dengan hak root:wqš Simpan dan keluar:qš Keluar jika tidak ada perubahan:q!š Paksa keluar tanpa menyimpan:wqaš Simpan dan keluar semua tab/file aktif
- How do we write the file, but don't exit?
:w
- How do we write the file, but don't exit- as root?
:w !sudo tee %
- How do we write and quit?
:wq
- How do we quit?
:q
- How do we force quit?
:q!
- How do we save and quit, for all active tabs?
:wqa