您的位置:首页 > 其它

Vim自己总结教程

2011-11-16 08:27 99 查看
需求分析:用习惯了notepad,用习惯了editplus,用习惯了npp++,结果,发现这些差不多都一样。虽然挺好。但是,自己希望去接触更加厉害的代码编辑器工具。vim已经发展了好多年了,而且是非常非常厉害的。这个名字vim也挺小,挺好看。所以,以后文本编辑,全部选择用这个吧。即使是一个简单的txt文件,只要是进行文本编辑的,都请用vim吧。。

但是,自己是知道的。vim是何等强大。所以,自己得总结学习一下子。。那么,下面就开始自己的vim之旅啦。。。(生命本身该是一次美丽的旅程。Life is a journey,not work.The key point that you need to think about is how to make it.)

思路:

1.从自己每天的对vim的学习和掌握中,不断提炼出来,vim的一些使用技巧问题。。总结一下子。、

2.阅读互联网上的参考和帮助。阅读vim自带的帮助。

行文思路:

-----------------------------------------2011/11/16星期三

恩。第一天会学习到什么知识呀。自己给好好总结总结。

I am a slow walker,but i never walk backwards.

(Hyp:
let me make some summaries of the usage of Vim^^)

1.Modes

Vim,by default,runs in a mode which does not let you begin typing(unlike notepad,Word,etc).
Instead,vim begins in command mode.Each mode is accessed by pressing a key,and escape returns
to command mode.The various modes are as follows.

总结:Vim默认启动直接进入命令模式,是不允许像普通编辑器那样子直接输入文本等信息的。Vim通过按下特殊键,切换到不同的模式。

通过按下Esc键,返回到初始的命令模式。

a).Insert mode:
The mode that lets you type normally.When in command mode,vim allows you to start typing before
the cursor(i/I),after the cursor(a/A),or in adjacent lines(o/O).

b)Visual mode:
v allows you to highlight text,as you would by using a mouse in a graphical editor.
i.Block:ctrl+V Visual Block selects characters in a rectangular shape,controlled by the movement(h,j,k,l) keys.
ii.Line:shift+V Select entire lines at a time.

c)Movement:
h,j,k,l These four keys are located adjacent to each other on the keyboard,where the right hand sits.
This is intentional;they seem to be a strange collection,but the arrangement allows easy movement of the cursor
without having to move your hand to a mouse,or the the arrow keys.

Vim deals with text by the character,word,line,or paragraph.
With many commands,you can combine a command with one of the letters w,W,(for 'words'),
b,B(for words,moving backwards from the cursor),or l (for lines).Simply pressing w,W,b,or B moves forward or
backward by that amount while in command mode.The brackets, { and } move forward and backward one paragraph
at a time.

2.Deleting text:

d and x delete text.
x removes one character at a time;
X deletes backwards.
dw and dW delete words,whereas db and dB delete words backwards.
dd deletes an entire line,and D deletes everything from the cursor to the end of the line.

3.Copy/Pasting text

a)"yanking" is the equivalent to copying,so named because you use the y key to copy selected text.
Anything highlighted (in Visual mode)will be placed into a buffer.There are other buffers available for your use,
named a-z.To use the registers,prefix the commands with a quotation mark ,",followed by the letter of the buffer.
For example,to yank into register q,the command is "qy.
Pressing yy grabs an entire line.

b)"pasting" puts the contents of a buffer back into the file being edited.
To paste,p pastes after the cursor,P before.Similar to yanking,prefixing the command with " and
a letter will paste from the specified buffer.

4.Files

a)Opening:
The most basic way to open a file is from the terminal,when launching vim.Once you are using vim,the :e command ,
followed by a filename,opens a file for reading.

b)Saving:The :w command writes your document to disk.Adding a name,i.e. :w main.cpp will save to that filename.

c)Quitting: :q quits vim.This can be used in conjunction with :w,to form the command :wq,which writes your file,then quits.

If you are editing a file and have not saved it when trying to quit or open a new file,
you will get a message saying No write since last change (use ! to override).
By appending an ! to the :e or :q commands,you can discard any changes since you last save.

{HYP:SO ,by now,we have seen some basic tips about the usage of vim.
Now let's get to some advanced skills of vim.}

Advanced Vim Features

1.The tilde (~) key will change the capitalization of the current selection(i.e.,'vim' becomes 'VIM')

2.Moving to the beginning or end of a line can be accomplished with 0 and $,respectively.

3.By pressing m,followed by any letter a - z,you can save ("mark") a location in your document,and jump to it using the
apostrophe ' key,followed by the same letter.
This lets you jump to important points of a file quickly.

4. Syntax highlighting can be turned on using the :syntax on command.
It can be turned off with:syntax off.

5.Vim allows you to run terminal commands without having to quit vim.
Pressing :!,followed by a terminal command,vim will execute the command,
the return you to the vim window.
For example,:!ls will print out the contents of the current directory,prompt you to hit Enter,then return to vim.

6.The .vimrc file resides in your home directory ,and contains a list of preferences.
In this file,you can set your favorite options(syntax highlighting ,etc) to be set every time vim is launched.

7. u undoes the last action.ctrl+r redoes it.

8. The / command allows you to search a file for a string.
/linux will search the document for the string 'linux'.
Pressing n jumps to the next occurrence of the string ,and N moves backwards.

9.Folding

In a class such as cs225,Folding is one of the most useful features of vim.
Folding lets you 'hide' areas of your document,which your can collapse and expand at will.
Vim creates folds based on syntax,indentation or you can create them mannually.
When dealing with a language such as C++,
vim's syntax detection does an excellent job of creating folds.

a)Enabling folds:
Folds are turned on and off with the :set foldenable and :set nofoldenable options.
b)Fold method:
There are three primary methods of doing this;syntax,indent,manual.
Toggle between them with :set foldmethod=OPTION,i.e. :set foldmethod=syntax.
c)Folding Commands:There are several ways to expand and collapse folds.

za toggles a fold.
zc and zC close a fold,and recursively close all folds that contain the area under the cursor.
z0 and zO opens a fold ,and recursively opens all folds under the cursor.
zR and zM open all folds in a document,and close all folds in a document.
In manual folding mode,zfNj creates a fold from the cursor down N lines.
zd deletes the fold at the cursor,and zE deletes all folds.

10.Tabs

New versions of Vim allow you to open up separate tabs with different documents in each .
To create a tab,use the command:tabnew.
The commands :tabnext and :tabprev move to the next and previous open tabs.

11.Split Windows

Vim lets you divide your window into multiple areas to edit different regions of the same file,or different file concurrently.

:split divides the window in half horizontally.
Prefixing it with a number ,such as :20 split,creates a split of 20 characters.

:vsplit divides the window vertically.

Pressing ctrl+w,followed by one of the direction(j,k,l) keys,will move focus from one area to another.

The quit(:q) command will close a split area.

来自于Vim自带帮助文档的知识:

输入:help help.txt就可以查看help.txt这个帮助文件的文档内容了。

同理:help visual.txt就可以查看visual.txt这个帮助文件了。

但是,这里自己在思考一个问题。如何将程序目录下面的那个帮助文件全部

都给列出来。这样子,自己在进行操作的时候,好进行一下子的选择呀。

恩。这点值得自己去解决。

使用命令开启鼠标的anchor效应。就像是超链接一样子。命令为:

:set mouse=a 我想,这里的a就是代表的anchor了吧。就像是html标签里面的a,该是一个意思。

我自己试了试,改为:set mouse= 然后,就关闭了鼠标单击效果。

鼠标单击效果使得你进入到一个新的主题内容上下文环境中,那么,如果你要返回,就应该是用快捷键CTRL+T或者是CTRL+O啦。

Vim是代表着VI Improved ,在vim的插入模式下面呢,hjkl用于实际的 输入操作。而在可视模式下面,hjkl分别用于控制光标的左上下右的移动操作,等价于光标的替代了。注意,这里,进入可视模式有v,有V,有Ctrl+v,其差别在哪里,自己还不是very clear...

这个是我今天学习到的东西。Vim的东西实在是太多了。不好整理呀。。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: