PLIC1-Bai2

Bai 2:

Graphical Text Editor
      - Sublime Text
      - VScode Visual Studio Code
Commandline text editor:
      - Vi
      - nano
      - vim
 alias vi=“vim”
 Cú pháp: vim <tên file>
 vim modes:
 Command mode
 Insert mode
 Visual mode
 vim .swp file:
 Lưu trữ các thay đổi khi edit file. Khi máy hoặc chương trình vim bị ”crash” có thể phục hồi lại nội dung từ
file swp.
 Ngăn ngừa file bị edit ở nhiều nơi đồng thời.
...............
which vi
ls -al /usr/bin/vi
which vim
ls -al /usr/bin/vim
vi .zsh_history
- di chuyển phím
h:trái 
l: phải
j: up
k: down
- 4 phím mũi tên lên xuống chỉ dùng cho vim
sudo apt install vim-nox
..
vim --version
apt search vim-nox  # tìm hiểu vim-nox là gì?
sudo apt install vim
apt search nginx
vim .zsh_history
vim abc  #normal mode. read only
4 phím mũi tên lên, xuống 
i => insert mode  # chèn thêm ký tự
a => insert mode và con trỏ dịch sang phải 1 kỹ tự (append sau con trỏ)
o => insert mode và con trỏ dịch xuống phía sau dòng hiện tại đang đứng
insert mode=> esc => normal mode
shift + : => command mode 
set number # sét số dòng
command mode => esc ==> normal mode
...
saving changes
 :x Write buffer to file and quit editor
 :wq Write buffer to file and quit editor
 :wq! Write buffer to file and quit editor (overrides protection)
 :w Write buffer to file and stay in editor.
 :w! Write buffer to file and stay in editor (overrides protection)
 :q Quit editor without writing buffer to file.
 :q! Quit editor without writing buffer to file (overrides protection)
 ZZ (shift + zz) Write buffer to file and quit editor.
..
vim ex.txt
file ex.txt.swp
...
shift + G # đi về cuối file
2 lần phím G # về đầu file
...
:set nu
shift + ^ # về đầu dòng
shift + $ # về cuối dòng
7+(shift+g) # về dòng số 7
...
copy: nhấn 2 lần liên tiếp chữ y
dán: nhấp p để dán ngay sau con trỏ
nhấp shift + p để dán trước vị trí con tro
phím u là undo
d: xóa (cut)
     dgg: xóa về đầu file
     d + shift + g: xóa về cuối file
     d^: xóa về đầu dòng
     d$: xóa về cuối dòng
y: copy
     ygg: xóa về đầu file
     y + shift + g: xóa về cuối file
     y^: xóa về đầu dòng
     y$: xóa về cuối dòng
.............
grep -rni "vmware1" # tìm từ trong thư mục => hiển thị file chứa
ví dụ có kết quả: test.txt:22:vmware1
vi test.txt +22 # mở file và con trỏ di chuyển đến dòng 22
...
:! ip a # thực hiện lệnh command trong file đang mở và hiển thị kết quả trong file đan gmowr
:r! ip a # lấy kết quả command lưu vào file đang mở
:/192
n (tương ứng 1 next match)
..
:%s/192.168/172.16/g
:%s/172.16/192.168/gc
Test Test # có chưa khoảng trống space
:%s/Test\sTest
......
vim 
   .vimrc
   .bashrc
   .zshrc
vi .vimrc
set number
vi Desktop/test.txt
.................................cut

 echo "Today is Tuesday" | cut -b 1
 echo "Today is Tuesday" | cut -b 5
 echo "Today is Tuesday" | cut -c 1,2,3
 echo "Today is Tuesday" | cut -c 1-3
 echo "Today is Tuesday" | cut -c -5 # lấy từ đầu
 echo "Today is Tuesday" | cut -c 5- # lấy về cuối
 echo "Today is Tuesday" | cut -d " " -f 1
 echo "Today is Tuesday" | cut -d " " -f 2
 echo "Today is Tuesday" | cut -d " " -f 3
 ip a | cut
................................awk
echo "Today is Tuesday" | awk '{print $1}'
echo "Today is Tuesday" | awk '{print $2}'
echo "Today is Tuesday" | awk '{print $3}'
echo "Today is Tuesday" | awk '{print $1$2$3}'
echo "Today is Tuesday" | awk '{print $1,$2,$3}'
.....
echo "Today_is_Tuesday" | awk -F "_" '{$2="Kernel"; print $0}'



Nhận xét