Diễn đàn Nhật Bản - diendannhatban.info

NHÀ PHÁT TRIỂN - DEVELOPERS - 技術開発 => FRAMEWORK - SDK => Tác giả chủ đề:: admin trong Thứ hai, 3/10/2016, 11:26:34 pm

Tiêu đề: [Căn bản] Sử dụng VIM Editor - trình soạn thảo phổ biến trên Linux
Gửi bởi: admin trong Thứ hai, 3/10/2016, 11:26:34 pm
(http://www.vim.org/images/0xbabaf000l.png)

# Giới thiệu
Cú pháp:
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
vi  filename

# Vấn đề
1. Visual copy
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
- Step 1: Position the cursor at the beginning of the text you want to cut/copy.
- Step 2: Press v to begin character-based visual selection, or V to select whole lines, or Ctrl-v or Ctrl-q to select a block.
- Step 3: Move the cursor to the end of the text to be cut/copied. While selecting text, you can perform searches and other advanced movement.
- Step 4: Press d (delete) to cut, or y (yank) to copy.
- Step 5: Move the cursor to the desired paste location.
Press p to paste after the cursor, or P to paste before.
- Reference: http://vim.wikia.com/wiki/Cut/copy_and_paste_using_visual_selection

2. Cập nhật tập tin -  Reload file
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
:e!
3. Trở về 1 hành động trước - Redo
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
Ctrl + R
4. Tìm kiếm - Search
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
Search ¥:/
Search next: n
Search privious: N

5. Tìm kiếm và Thay thế - Search and replace
Thay thế toàn bộ chuỗi diendannhatban.info thành diendannhatban.test
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
%s/diendannhatban.info/diendannhatban.test/g

Xoá line có chứa text (pattern)
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
# Vd xoá tất cả các dòng có chứa chữ "nhật bản"
:g/nhật bản/d

Tìm kiếm và thay thế dòng mới
Thay thế đoạn code sau
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
;
}

thành
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
; }

Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
:%s/;\n}/; }/g

6. Di chuyển con trỏ / dấu nhắc
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
h   move one character left
j   move one row down
k   move one row up
l   move one character right
w   move to beginning of next word
b   move to previous beginning of word
e   move to end of word
W   move to beginning of next word after a whitespace
B   move to beginning of previous word before a whitespace
E   move to end of word before a whitespace

7. Sử dụng tiếng Nhật hoặc tiếng Việt trong Vim (thiết lập encodding cho vim)
Code: Bạn không thể xem liên kết này. Đăng ký hoặc Đăng nhập
# .vimrc
:filetype on
:autocmd FileType c,cpp,perl set cindent
:autocmd FileType python set tabstop=4 shiftwidth=4 expandtab
:set autoindent
:set shiftwidth=4
:set backup
:set fencs=iso-2022-jp,sjis,euc-jp

# Tham khảo
- About Vim (Official Site) http://www.vim.org/about.php
- http://bullium.com/support/vim.html
- http://vim.wikia.com/wiki/Search_and_replace
- http://vim.wikia.com/wiki/All_the_right_moves