vi(m) in Indonesian
Dalam bahasa Indonesia
Dalam halaman ini, saya akan menampilkan tentang vi dan vim.
Saya harap, catatan ini dapat membantu saya dikemudian hari, ketika saya membutuhkannya.
Mohon diperhatikan bahwa, sebagian dari catatan ini adalah cerita lama menggunakan vi, sejak di kampus. jadi mohon maaf bercandaanya.
vi, ngerikah?
hoho vi, the better version is vim (VIMprove) I think awesome edtitor, cool, powerfull, durable, efficent, etc. But if compared to notepad++, vi might not stand a change. :P (edit, I was still considering vim is better in it’s own league)
Tapi dihati awak, tetap vim :P. Ya, beda field dengan notepad++, both have their own advantages.
kemaren ada teman yang bilang pas lagi ngerjain tugas.
"pake vi?, ga ada yg lain, yg lebih gampang?"
Dulu awak bilang kek gitu juga, tapi keknya vim bisa dibilang gampang deh.
terutama untuk edit2 configurasi di *nix
. di windows pun sudah ada vim
for windows(gvim).
klo kow di terminal, the best menurut awak ya itu, vim. sampe sekarang vim tetap dikembangkan. Dah sampe versi 7.3xx (cmiiw).
oke deh, bukan sok tau ato apa, cuman mo meracuni, diberi sikit tips2 yang biasa awak pakai
Langkah pertama. Umumnya mo mulai vim, ketik
$ vim
di terminal tar bakal keluar editor yg blom ada isinya, ato klo dah tau file apa yg mo diedit, tinggal
$ vim fileku.txt
menuju ke tempat tertentu dari fileku,
$ vim +60 fileku.txt
ini bakal ke baris 60 di fileku (sangat gampang bagi programer, melihat bug dsb)
okeh, dah masuk vim :D mo pindah-pindah, gampang banget…
j
h l
k
pake arah yg ada dikeyboard jg bs
ingat hjlk
bs digunakan di mode command, by pressing esc.
untuk menulis, ketik dulu insert mode bisa pake i, I, a, A, o, O. untuk sekarang i aja dulu :P
sila ketik. selesai ketik, tekan esc
, :
, w
, dan q
.
i-> insert at the left of current cursor
I-> insert at the begining of current line
a-> insert at the right of current cursor
A-> insert at the end of current line
o-> insert one line below current line
O-> insert one line above current line
search :
Untuk melakukan pencarian, kita harus berada di mode command.
untuk memastikan bahwa kita berada di mode command, silahkan ketik esc
terlebih dahulu.
Kemudian untuk mencari suatu kata, sila ketik /
, diikuti dengan kata yang ingin dicari:
/kata_yang_dicari
Agar pencarian tidak case sensitive, sila ketik:
:set ic
to ignore case sensitive.
If you want to search for bandung or jakarta:
/bandung\|jakarta
untuk find and replace, ketik :
:%s/hari/hary/gc
perintah ini akan mencari kata hari
untuk digantikan dengan kata hary
.
flag g
untuk semua, flag c
untuk bertanya, apakah mau diganti(untuk konfirmasi).
When starting vi, to go to first occurent of string
, we can use:
$ vi +/string file
eg:
$ vi +/JKT_IVRTSM1b_SERVICE /etc/hosts
akan menuju langsung ke JKT_IVRTSM1b_SERVICE
.
or we want to go to specific line
$ vi +50 fileku
this will bring us to the 50th line of fileku
.
splitting
in vi, type :sp
for spliting the windows (mendatar), dan pindah dengan
ctrl-w lalu arah, j(bawah) dan k(atas), h ke kiri dan l ke kanan.
:sp filename (horizontal)
:vsp filename (vertical)
atau dapat menggunakan control:
Ctrl-W s for horizontal splitting
Ctrl-W v for vertical splitting
Ctrl-w q to close one
in terminal: Normally if we want to open N windows (default: one for each file), we use:
# vi -o[N]
if we want to display it all, use
# vi -O[N]
its like -o but split vertically
restore edit
in vi, ketik :e!
utk kembali ke awal, original file.
inser command to current edit file:
to insert from a command, in vi use:
:r !date
this will print output of date to the content of vi
:r !whoami
:r!pwd
vim in windows
edit vimrc di windows, open gvim, then edit file _vimrc
:
:e _vimrc
then append :
set guifont=Consolas:h10:cANSI
colors slate
Aditional command:
7j -> move 7 baris ke bawah
dw -> delete a word
* -> cari kata yang sedang ditunjuk kursor (cool)
:new ~/Desktop/coba.txt -> open file coba.txt in new window in vim (cool)
:tabe -> go to tab edit
:tabn -> go to next tab
:tabp -> go previous tab
v -> to start visual, and you can select text, eg to copy using arrow comand
or any text movement to move around. (DAMN...THIS IS PRETTY COLL, I didn't know about this...Agghh..)
V -> visual yang bekerja pada baris
to input from standard output just use vim -R - (there’s dash at the end) eg:
# chkconfig --list | vim -R -
will invoke vim which contain output of chkconfig
to browse file system and press to open the file
:Vex
or
:Sex
Please note that :
Vex=Vertical split explor and
Sex=Split explor
completion
command line completetion in vim. for example you want to know command start with a, type
:a
then without space, followed by <ctrl-D>
this will give you autocompletion a
, and see possible completions:
abbreviate amenu argdelete arglocal augroup
abclear anoremenu argdo args aunmenu
aboveleft append argedit argument autocmd
all argadd argglobal ascii
you can also use <tab>
hehe
oh, gw baru tau.. ilmu baru.. you can select (and it will automatically store in cliboard, in other name, it coppied) then you can paste it by middle mouse button, or two tap simustaniously. yep select a text, then go to any other you wnat to paste, then you middle click there / doubletap at once there, the text will be pasted. COOLLLLLL
regular expression in vi
[...] -> match any character from the set
[^...] -> match any character outside the set
[...-...] -> any character from range
[^...-...] -> any character outside range
\< -> begining of word, eg /\<London matchs every line with begin with London
\> -> end of word
to copy all line type
:%y
to copy from current line to the end,press y
followed by G
to join line type J
, if you want to join 5
lines at one time, type 5
then J
.
to repeat last action, type .
. if you want to execute it 5 times, type 5 followed by dot
to redo or undo:
u, U, R
to execute command while in vi, execute :!your-command
.
eg:
:!pwd
while in vi, if you want to go to shell, type
:sh
and when you exit
shell, you will be back to vi
.
open file with single press: to open file with filename is under current cursor, press gf, then it will automatically open this file
in vim, to enter commandline history, type q
then :
to disable .viminfo
, add to .vimrc
set viminfo="NONE"
other GREAT vimtips:
make lowercase:
in vim, to make all lines to lower case with guG
folding in vim:
to open folding : click left(h) or right(l) or zo
to close folding : zc
autocompletion in vim: ctrl-N
. THIS IS AWESOME…..
jump to tags:
use ctrl-]
to jump to tags and to go back use ctrl-T
keyboard mapping di vim this could be really useful:
:nmap - Display normal mode maps
:imap - Display insert mode maps
:vmap - Display visual and select mode maps
:smap - Display select mode maps
:xmap - Display visual mode maps
:cmap - Display command-line mode maps
:omap - Display operator pending mode maps
I just knew… that ESC
can be replace by ctrl-[
.
Tips dan Triks
menghilangkan auto indent sementara waktu untuk paste
Ketika kita paste kode yang ke vi, maka formatnya berubah karena indentasi oleh vim, hal ini dapat dihindari dengan menggunakan perintah
:set paste
kemudian setelah selesai paste, kita kembalikan settingan:
:set nopaste
tips lain..
Saya perlu menambahkan lagi dan merubah yang masih kurang