Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 操作系统 > Linux > vim编辑器使用[学习札记]
【标  题】:vim编辑器使用[学习札记]
【关键字】:vim
【来  源】:http://blog.csdn.net/simonjo/archive/2006/10/16/1337162.aspx

vim编辑器使用[学习札记]

Your Ad Here

vim(vi improved)Unix/Linux环境下最为普遍的文本编辑器,被广泛应用于Linux/Unix编程、系统管理中。如果被合理的配置(写配置文件,增加高亮、缩进的设置),VI还是一个合格的IDE。当然,现在有很多的Unix文本编辑器具有,或者超越了VI的功能,但是,作为一种Unix的基本配置软件,VI的使用依然很普遍。 笔者今天在公司系统学习了VIM的基本命令,现整理于下(为了输入方便,命令的注解将使用英文,日后如有闲暇,将转移为中文):

在命令行提示符下,输入vi test.txtvim test.txt,即可打开(若存在,如不存在则新建)test.txt。进入之后为command mode,不可以输入文本。输入I, i, A, a, O, o可以进入Input mode编辑文本;在Input mode中按Esc可以进入Command mode

I: Engage insert mode, the cursor will be positioned at the beginning of the current line.

i: Engage insert mode, the cursor will be positioned one character after the current position.

A: Engage append mode, the cursor will be positioned at the end of the current line.

a: Engage append mode, the cursor will be positioned after the current position.

O: Engage insert mode, a new line will be added before the current line.

o: Engage insert mode, a new line will be added after the current line.

 

Command mode下,有如下基本命令(Note: Linux is case sensitive, so the case(Hi/Low) of the commands matters)

(When I mention "current line", I actually mean the line where the cursor is currently positioned)

dd: Delete the current line.

D: Delete the content from the current cursor position to the end of the line.

(n)dd: Where (n) represents numbers like 10dd. (All the (n) in this article means the same) Deletes n line from the current line.


yy: copy the current line to the buffer.

(n)yy: copy n lines from the current line to the buffer.

cc: cut the current line to the buffer.

(n)cc: cut n lines from  the current line to the buffer.

p: paste the content of buffer after the current line.

P: paste the content of buffer before the current line.


u: Undo

ctrl-r: Redo

(VI/VIM allows only one step of undo/redo, it's like notepad, but not like winword)


h: Move the cursor left by one character.

l(the letter l, lower case, not number 1): Move the cursor right by one character.

j: Move the cursor up by one character.

k: Move the cursor down by one character.

w(lower case): move the cursor to the next word(word by word).

0(zero): move the cursor to the beginning of the current line(like Home in notepad).

$: move the cursor to the end of the current line(like End in notepad).

G: move the cursor to the end of the document.

ctrl-f: move forward for 1 page.

ctrl-b: move backward for 1 page.

:1(column, then the number 1): move the cursor to the beginning(the beginning of the first line) of the document.

:(n): move the cursor to the beginning of the nth line.


/keyword: search the document for the keyword and highlight them. like /tcs, /china to search for the string "tcs", "china". Then press n to move the cursor to the next one matching pattern, press N to move it to the last one matching pattern.

:%s/string1/string2/g: replace all "string1" with "string2". /g means globally. If no /g was specified, then only the first matching pattern in each line will be replaced. The editor will not look further to find more patterns.


r: replace the letter at the current cursor position with another.

R: replace(overwrite) everything from the current cursor position to the end of the current line.

cw: change(overwrite) the current word. The rest of the current line remains untouched.


:w: write the document to the current file.

:w filename1: write the document to another file, with the name "filename1".

:q: quit.(will prompt if the content is changed but not saved.)

:q!: force quit.(will not prompt and quit directly, thus will lose all changes made since last save.)

:wq: save and quit.


以上即为VI基本操作的命令集合。涵盖了文件打开、保存、退出,剪切、复制、粘贴,文本查找、替换,指针(光标)的定位、移动等基本的编辑器使用方法。

如有更高阶的操作在Training中有介绍,将会另贴文出来。

Simon Jo

 

[转自CU]HP小型机的信息的命令集:【上一篇】
Perl 语言编程 第三版 在线版本:【下一篇】
【相关文章】
  • Vim documentation: usr_toc
  • VIM 使用手册
  • LINUX文本编辑VIM
  • Vim小技巧
  • vim的常用命令
  • Vim 学习笔记
  • vim手册
  • .vimrc
  • some advance tips in using vim
  • vim使用
  • 【随机文章】
  • 架設 MAIL
  • ssh无须密码登陆
  • 网管员安全训练营——让FTP服务器更安全
  • 找出一个数组中若干个数相乘等于另外一个数的组合
  • VBS、ASP代码语法加亮显示的类(1)
  • C++图书热点观察[转]
  • WDM全光通信网技术及其发展
  • 好带光盘,从最简单的源文件开始
  • Comparing the syntax of Java 5 and ActionScript 3
  • some advance tips in using vim
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.