Vim tricks

Зарим хүмүүст хэрэгтэй байж магадгүй гэж бодоод өөрийхөө ашигладаг vim трикүүдийг бичлээ.
Табийн шилжих уртыг тодорхойлох
:set tabstop=2

Таб дарахад white space-р шилжих.
:set expandtab
Өөрөөр хэлбэл энэ тохиргоо хийсний таб дарж 4 тэмдэгтээр шилжлээ гэж бодоход энэ нь 4 удаа space товч дарсантай адил.

Олон мөрийг зэрэгцүүлэх
Shift+V-гээр нэг мөрийг сонгодог. Дээш болон доош товчоор олон мөр сонгоод > буюу shift+. < буюу shift+ , товчуудаар сонгосон мөрүүдийг баруун зүүн тийш зөөдөг.
:set shiftwidth=2 командаар шилжих уртыг заана.


Tabbed Vim
Олон файлтай ажиллах үед терминал нэмж ажиллуулалгүйгээр Vim дээр таб үүсгээд ажиллаж болно.
:tabnew file_name Хэрэв файлын нэрийг заагаагүй бол шинэ файл үүсгэдэг.
:tabnext Дараагийн таб руу шилжих
:tabprevious Өмнөх таб руу шилжих
:tabclose Таб хаах
:tabfind Табыг нэрээр нь хайх
:tabend Хамгийн сүүлчийн таб
:tabfirst Хамгийн эхний таб
гэх мэт хэдэн командыг мэдэж байхад болоод явчихна. Командын горимд tab гэж бичээд табаа дарахад табтай ажилладаг командууд гараад байна.

Colorizing Vim
Юуны өмнө Vim өнгийн файл хэрэгтэй. Гүүглдээд .vim өргөтгөлтэй файлууд татаад авчихна. .vim файлаа ~/.vim/colors хавтсанд хуулсны дараа командын мөрт
:colorscheme vim_file (Файлын нэр таб дарахад гараад ирнэ.)
:syntax on
гэж бичээрэй.

Эцэст нь vim засварлагчийг нээх бүрдээ дээрх командуудыг бичих нь ядаргаатай учир vim тохиргооны файл бичээд хадгалчихна.
sudo vi /etc/vim/vimrc
Хамгийн доор
set tabstop=2
set expandtab
set shiftwidth=2
colorscheme wombat
syntax on

4 comments:

  Battur Sanchin

December 6, 2008 at 4:03 AM

Ингэж ажилладийм гээд харуулбал нь лавтай нэлээд хүмүүс шууд л вимдэх байх да... Энэ талаар ямар нэгэн видео байна уу?

  Анхаа

December 6, 2008 at 12:09 PM

Шээл дээр дандаа vi аар зүтгүүлээд байсан. vim нь тун дажгүй эд байна. Коммандуудыг жаал туршиж үзлээ. vim таалагдлаа. Thanks

  Battur Sanchin

December 9, 2008 at 6:02 PM

(Just for Reference, to use later)
vi commands Key command Description

h
Move left one character.

j
Move down one line.

k
Move up one line.

l
Move right one character.

H
Move to the top of the screen.

L
Move to the bottom of the screen.

G
Move to the end of the file.

w
Move forward one word.

b
Move backward one word.

0 (zero)
Move to the beginning of the current line.

^
Move to the first non-whitespace character on the current line.

$
Move to the end of the current line.

Ctrl-B
Move up (back) one screen.

Ctrl-F
Move down (forward) one screen.

i
Insert at the current cursor position.

I
Insert at the beginning of the current line.

a
Append after the current cursor position.

A
Append to the end of the current line.

o
Start a new line after the current line.

O
Start a new line before the current line.

r
Replace the character at the current cursor position.

R
Start replacing (overwriting) at the current cursor position.

x
Delete the character at the current cursor position.

X
Delete the character immediately before (to the left) of the current cursor position.

s
Delete the character at the current cursor position and go into insert mode. (This is the equivalent of the combination xi.)

S
Delete the contents of the current line and go into insert mode.

dX
Given a movement command X, cut (delete) the appropriate number of characters, words, or lines from the current cursor position.

dd
Cut the entire current line.

D
Cut from the current cursor position to the end of the line. (This is equivalent to d$.)

cX
Given a movement command X, cut the appropriate number of characters, words, or lines from the current cursor position and go into insert mode.

cc
Cut the entire current line and go into insert mode.

C
Cut from the current cursor position to the end of the line and enter insert mode. (This is equivalent to c$.)

yX
Given a movement command X, copy (yank[a]) the appropriate number of characters, words, or lines from the current cursor position.

yy or Y
Copy the entire current line.

p
Paste after the current cursor position.

P
Paste before the current cursor position.

.
Repeat the last command.

u
Undo the last command.[b]

/regex
Search forward for regex.

?regex
Search backward for regex.

n
Find the next match.

N
Find the previous match. (In other words, repeat the last search in the opposite direction.)

:n
Next file; when multiple files are specified for editing, this command loads the next file. Force this action (if the current file has unsaved changes) with :n!.

:e file
Load file in place of the current file. Force this action with :e! file.

:r file
Insert the contents of file after the current cursor position.

:q
Quit without saving changes. Force this action with :q!.

:w file
Write the current buffer to file. To append to an existing file, use :w >>file. Force the write (when possible, such as when running as root) with :w! file.

:wq
Write the file contents and quit. Force this action with :wq!.

:x
Write the file contents (if changed) and quit (the ex equivalent of ZZ).

ZZ
Write the file contents (if changed) and quit.

:! command
Execute command in a subshell.

  Gobi

December 13, 2008 at 7:58 PM

Иймэрхүү мэдээллүүд хэнд ч гэсэн маш хэрэгтэй байдаг. Cheat sheet (шпригалка гэдэг байхаа) байдалтай хураангуйлаад хэвлэхэд зориулсан pdf файл болгоод бэлдвэл бүр их гоё хүмсүүдэд дэлгэрэх байх гэж бодож байна.

Би л гэхэд vi, vim, nano эдэр гээд л хэрэглээд байдаг боловч бүх боломжийг нь ер нь хэрэглэдэггүй байхаа.

Миний нэлээн дардаг бөгөөд бичигдээгүй зарим нэг товчуудаас гэвэл:

o, O, ce, cw, $, Ctrl+F, Ctrl+B, og, G, :(мөрийн дугаар), :sh, b, e, :%s/(search string)/(replace string)/g гэх мэт зүйлс санаанд орж байна. Ер нь миний хувьд сум товчуудыг огт хэрэглэхгүй ажиллаад сурчихсан юм билээ. Баттөр биччихсэн байна.