進入編輯模式 vim命令模式 vim實踐

vim編輯模式、vim命令模式
vim編輯模式git

使用vim filename 進入的界面是通常模式,在這個模式下雖然咱們可以查看,複製,剪切,粘貼,可是不能編輯新的內容,如何能直接寫入東西呢?這就須要進入編輯模式了,從通常模式進入編輯模式有不少個按鍵均可以實現,可是不一樣的按鍵進入編輯模式是有區別的vim

  • i 在光標當前字符前插入
  • I 在光標所在行的行首插入
  • a 在當前字符後插入
  • A 在光標所在行尾插入
  • o 在當前行的下一行另起一行插入
  • O 在當前行的上一行另起一行插入

vim命令模式

vim工具還有一個命令模式,在通常模式下輸入「:、/」就能夠進入命令模式,在命令模式下咱們能夠搜索某個字符串,也能夠實現保存,替換,退出,顯示行號,高亮顯示等操做。windows

  • /word 在光標以後查找一個字符串word,按n鍵向後繼續搜索
  • ?word 在光標以前查找一個字符串word,按n鍵向前繼續搜索
  • :n1,n2s/word1/word2/g 在n1和n2行之間查找word1並替換成word2,不加g則只替換每行的第一個word1
  • :1,$s/word1/word2/g 將文檔中全部的word1替換成word2,不加g則只替換每行的第一個word1
  • 當要被替換或要替換的內容當中有「/」時,系統會不識別命令,能夠用「#或@」將語法中的/替換掉,好比講wo/rd1 替換成wo/rd2 可使用:1,$s#wo/rd1#wo/rd2#g

命令模式的其餘功能

  • :w 保存文本
  • :q 退出vim
  • :w! 強制保存文本,使用root用戶時,即便文本是隻讀的,也能夠完成保存
  • :q! 強制退出,全部改動不生效
  • :wq 保存並退出(若是沒有改動文本,使用該命令也會更新文件的Mtime)
  • :x 保存並退出(若是沒有改動文本,使用該命令不會更新文件的Mtime)
  • :set nu 顯示行號

:set nonu 不顯示行號bash

vim 實踐less

[root@bogon ~]# vim test.txt
[root@bogon ~]# cp /etc/dnsmasq.conf /tmp/1.txt
[root@bogon ~]# vim /tmp/1.txt
# Configuration file for dnsmasq.
#
# Format is one option per line, legal options are the same
# as the long options legal on the command line. See
# "/usr/sbin/dnsmasq --help" or "man 8 dnsmasq" for details.

# Listen on this specific port instead of the standard DNS port
# (53). Setting this to zero completely disables DNS function,
# leaving only DHCP and/or TFTP.
#port=5353

# The following two options make you a better netizen, since they
# tell dnsmasq to filter out queries which the public DNS cannot
# answer, and which load the servers (especially the root servers)
# unnecessarily. If you have a dial-on-demand link they also stop
# these requests from bringing up the link unnecessarily.

# Never forward plain names (without a dot or domain part)
#domain-needed
# Never forward addresses in the non-routed address spaces.
#bogus-priv

# Uncomment these to enable DNSSEC validation and caching:
# (Requires dnsmasq to be built with DNSSEC option.)
#conf-file=%%PREFIX%%/share/dnsmasq/trust-anchors.conf
#dnssec

# Replies which are not DNSSEC signed may be legitimate, because the domain
# is unsigned, or may be forgeries. Setting this option tells dnsmasq to
# check that an unsigned reply is OK, by finding a secure proof that a DS
# record somewhere between the root and the domain does not exist.
# The cost of setting this is that even queries in unsigned domains will need
# one or more extra DNS queries to verify.
#dnssec-check-unsigned

# Uncomment this to filter useless windows-originated DNS requests

分別向下、向右、向左、向右移動6個字符(6j 6l 6h 6l)dom

搜索文件中出現的dnsmasq字符串,並數一下該字符串出現的次數(輸入/dnsmsq,而後按n)。工具

把從第1行到第10行出現的dnsmasq字符串替換成dns(:1,10s/dnsmasq/dns/g)ui

還原上一步操做(u)this

把光標移動到第25行,刪除字符串1y(輸入25G後回車,而後按j向右移動光標找到ly,按v選中,而後按x)spa

刪除第50行

刪除第37行至第42行的全部內容(37G 6dd)

複製第48行的內容並將其粘貼到第52行下面(48G yy 52G p)。

相關文章
相關標籤/搜索