文本编辑工具VIM

本文介绍了VIM编辑器的基本使用方法,包括安装过程、三种基本模式及其转换方式。此外还详细讲解了一般模式下的光标移动技巧、文本编辑操作、文件保存与退出等常见命令,并提供了实用的命令模式示例。

VIM的介绍

  • vim 是vi的升级版本
  • vim 是带颜色显示的
  • 安装VIM:yum install -y vim-enhanced
  • vim 的三种模式:一般模式、编辑模式、命令模式

1、一般模式

使用命令vim filename 编辑文件时,默认是进入一般模式;

移动光标

  • h、l、k、j :光标左、右、上、下移动一个字符
  • ctrl+B :文本页面向前翻一页;
  • ctrl+F :文本页面向后翻一页;
  • 0或shift+6 :移动到本行行首;
  • shift+4 :移动到本行行尾;
  • gg :移动到首行;
  • G :移动到尾行;
  • nG:移动到第n行

删除、复制、粘贴、

  • x和X :x表示向后删除一个字符;X表示向前删除一个字符;
  • nx :向后删除n个字符;
  • dd :删除/剪切光标所在的那一行;
  • ndd:删除/剪切光标所在行之后的n行;
  • yy :复制光标所在行;
  • nyy :光标行开始向下复制n行;
  • 小p :光标所在行开始向下粘贴已经复制/粘贴的内容;
  • 大P :光标所在行开始向上粘贴已经复制/粘贴的内容;
  • u :还原上一步操作;
  • v :按v后移动光标会选中指定字符;

编辑模式(i、I、a、A、o、O)

  • i :从目前光标所在处插入;
  • I :在目前所在行的第一个非空格符处开始插入;
  • a :从目前光标所在的下一个字符处开始插入;
  • A :从光标所在行的最后一个字符处开始插入;
  • o :在目前光标所在的下一行处插入新的一行;
  • O :在目前光标所在处的上一行插入新的一行;

命令模式

  • /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;
  • :w :保存文本;
  • :q :退出vim;
  • :w! :强制保存,在root用户下,即使文本是只读也可以完成保存;
  • :q! :强制退出,所有改动不生效;
  • :wq :保存并退出;ntime会改变;
  • :x :保存并退出;ntime不会改变;
  • :set nu :显示行号;
  • :set nonu :不显示行号;
  • :sp :多窗口显示打开文件;

例:

[root@bogon /]# cp /etc/dnsmasq.conf /tmp/1.txt
[root@bogon /]# vim /tmp/1.txt

/dnsmasq ?dnsmasq

# 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
/dnsmasq 
?dnsmasq 
:wq
:q!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值