您的位置:首页 > 其它

vim tips

2009-01-17 23:01 337 查看
In my mind, vim is one tool, just to use it and be an expert step by step if needs.
---------------------------------------------------------
First step: open and edit

To one newer, we only need to know little commands to use vi/vim. There are 2 modes when we start it.
-- command mode : it is default mode, and we can't input characters as other text editors. We can input commands in this mode.
-- insert mode: we can edit text.
To switch from [command mode] to [insert mode], press "i".
To return [commnad mode], press "Esc"

There are some other modes in some documents, don't care about them. The others can be classified into [command mode] in someway.

Now, there are some useful commands in the [command mode]
--"dd", delete current cursor line
--"yy", copy current cursor line
--"nx", n is a number(1, 2, ....), delete n characters from the cursor
--"p", paste. maybe to below line for one line, maybe to follow the current cursor for characters
--"h"/"j"/"k"/"l", h: move left, j: move down, k: move up, l: move right. in the lastest version, the direction arrows work also.
--":q!" quit vim without save
--":w"/":wq" save(/save and quit) file
--"/words" search word, words respresents the string

Now we can edit file thought without efficiently.

---------------------------------------------------------
Further step: tips
--ctags
installation: don't use the package "elvis-tools", use the "exuberant-ctags"
preparation: to create one tags file for vim
---ctags -R *
---:set tags=tagsfilepath
usage:
---ctrl+] goto the defination
---ctrl+o go back

--plugins
To install plugin, just put vim file into ~/.vim/plugin, and help text to ~/.vim/doc. Use :helptags ~/.vim/doc in vim to create helps.

Here is one alternate plugin, it is useful, it was written by Michael Sharpe
please refer to: http://www.vim.org/scripts/script.php?script_id=31
A few of quick commands to swtich between source files and header files quickly.
:A switches to the header file corresponding to the current file being edited (or vise versa)
:AS splits and switches
:AV vertical splits and switches
:AT new tab and switches
:AN cycles through matches
:IH switches to file under cursor
:IHS splits and switches
:IHV vertical splits and switches
:IHT new tab and switches
:IHN cycles through matches

--switch in files
--:e filename add new file into buffer
--:bn/bN switch to next/previous file
--:b(number) switch to nth file
--:bd remove current file from buffer
--:ls list files in buffer

---------------------------------------------------------
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: