Linux學習
一、vim介紹
二、vim顏色顯示和移動光標
三、vim一般模式下移動光標
四、vim一般模式下復制、剪切和粘貼
一、vim介紹
vim是vi的升級版本
-
vim帶有顏色顯示
image.png vim系統默認是沒有安裝的,需要執行yum install -y vim-enhanced命令安裝
三種模式:一般模式、編輯模式和命令模式
一般模式:dd命令刪除一行
編輯模式:按i,編輯文檔
命令模式:按:set nu顯示行數
set nu顯示行數
[root@01 ~]# vim /etc/passwd
1 root:x:0:0:root:/root:/bin/bash
2 bin:x:1:1:bin:/bin:/sbin/nologin
3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
4 adm:x:3:4:adm:/var/adm:/sbin/nologin
5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
6 sync:x:5:0:sync:/sbin:/bin/sync
7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
8 halt:x:7:0:halt:/sbin:/sbin/halt
9 mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
10 operator:x:11:0:operator:/root:/sbin/nologin
11 games:x:12:100:games:/usr/games:/sbin/nologin
12 ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
13 nobody:x:99:99:Nobody:/:/sbin/nologin
14 systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
15 dbus:x:81:81:System message bus:/:/sbin/nologin
16 polkitd:x:999:997:User for polkitd:/:/sbin/nologin
17 postfix:x:89:89::/var/spool/postfix:/sbin/nologin
18 sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
19 chrony:x:998:996::/var/lib/chrony:/sbin/nologin
20 user1:x:1000:1000::/home/user1:/bin/bash
21 admin:x:1001:1001::/home/admin:/bin/bash
22 linux-01:x:1002:1002::/home/linux-01:/bin/bash
23 linux-02:x:1003:1003::/home/linux-02:/bin/bash
24 linux-05:x:1008:1005::/home/admin:/sbin/nologin
25 linux-06:x:1009:1005::/home/user1:/sbin/nologin
26 linux-07:x:1010:1005::/home/user1:/sbin/nologin
27 user2:x:1011:1011::/home/user2:/bin/bash
28 AAA:x:111:0::/home/admin/:/sbin/nologin
~
~
~
:set nu
二、vim顏色顯示和移動光標
- 指定的文檔放在指定的位置,會有顏色顯示
- vim顯示條件有很多,vim編輯文件時會顯示顏色(和文件的具體內容有關系.ss&.py)
- vim的配置文件在/etc/vimrc,也可在用戶自己的家目錄下編輯:vim /root/.vimrc
vim
[root@01 ~]# vim /etc/vimrc
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
" autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/run/media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add $PWD/cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
三、vim一般模式下移動光標
- h或者向左的方向鍵 光標向左移動一個字符;
- l(小寫字母l)或者向右的方向鍵 光標向右移動一個字符;
- k或者向上的方向鍵 光標向上移動一個字符;
- j或者向下的方向鍵 光標向下移動一個字符;
- CTRL+f或者pageup鍵 屏幕向前移動一頁;
- CTRL+b或者pagedown鍵 屏幕向后移動一頁;
- 數字0或者shift+6 移動到本行的行首;
- shift+4 移動到本行行尾;
- gg 移動到行首;
- G 移動到行尾;
- nG(n是任意數字) 移動到第n行;
四、一般模式下復制、剪切、粘貼
- x,X x表示向后刪除一個字符,X表示向前刪除一個字符;
- nx 向后刪除n個字符
- dd 刪除/剪切光標所在的那一行
- ndd 刪除/剪切光標所在行之后的n行
- yy 復制光標所在行
- p 從光標所在行開始,向下粘貼已經復制或者粘貼的內容
- 大p 重光標所在行開始,向上粘貼已經復制或者粘貼的內容
- nyy 從光標所在行開始,向下復制n行
- u 還原上一步操作(最大50次) CTRL+r回復u上一步操作;
- v 按v后移動光標會選中指定字符,然后可以實現復制、粘貼等操作