找回密码
 注册
查看: 3093|回复: 4

show line number and fill tab with spaces in vi

[复制链接]
发表于 2007-9-25 23:51:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
[这个贴子最后由newcfd在 2007/09/26 00:19pm 第 4 次编辑]

if you use vi, create a .exrc in your home directory. In you use vim, create .vimrc.
Do not miss . in front of the file name. Adding the following two lines into
the file.
    set number
    set softtabstop=4
First line always shows line number. Second line fills tab with spaces. If you
do not use spaces to fill tab, you may get a chaotic file when you print it or
in CVS. To check if your code is in order with tab, type "more your_file_name".
I am using different editors: kate, eclipse, emacs, gedit and nedit. The reason I use different editors is that I can learn more about GUI design.
 楼主| 发表于 2007-10-2 02:09:48 | 显示全部楼层

show line number and fill tab with spaces in vi

To insert space characters whenever the tab key is pressed, set the
';expandtab'; option:
        set expandtab
With this option set, if you want to enter a real tab character use
Ctrl-V<Tab> key sequence.
To control the number of space characters that will be inserted when
the tab key is pressed, set the ';tabstop'; option.  For example, to
insert 4 spaces for a tab, use:
        set tabstop=4
After the ';expandtab'; option is set, all the new tab characters entered
will be changed to spaces.  This will not affect the existing tab
characters.  To change all the existing tab characters to match the
current tab settings, use
        :retab
To change the number of space characters inserted for indentation, use
the ';shiftwidth'; option:
        set shiftwidth=4
For example, to get the following coding style,
        - No tabs in the source file
        - All tab characters are 4 space characters
use the following set of options:
        set tabstop=4
        set shiftwidth=4
        set expandtab
Add the above settings to your .vimrc file.
To get more help on these options, use
:help tabstop
:help shiftwidth
:help expandtab
 楼主| 发表于 2007-10-2 02:13:09 | 显示全部楼层

show line number and fill tab with spaces in vi

Often, you might want to delete a set of arguments within bash scripts in Unix/Linux environments as an admin.
So you might think "dw" (delete word) does the job, because it often does it actually. BUT! In Unix/Linux environments
you might also interpret a word in a different way, e.g. a "/path/to/file" can be seen as just one word in terms of the
number of arguments. In that case, "dw" will not delete "/path/to/file", instead it will interpret every slash "/" as a seperate
word, so you have to enter "dw" 6 times.
Instead, you can dynamically enter your own, currently needed delimiter without changing vim';s global behavior in .vimrc
by just typing "df " (d like Donald, f like **** and then just a whitespace). By doing this, you tell vim to interpret its current
position until the next occurance of " " (whitespace) as a word.
You can easily adapt this style of deleting "words" by replacing whitespace by your own character.
Maybe you want to delete a whole sentence, then you want to type "df.". There are many thinkable usages.
Once you get used to it you can work "yet another bit" more productive. There no limit to productivity.
Thank what i like about vi(m).
 楼主| 发表于 2007-10-2 02:14:55 | 显示全部楼层

show line number and fill tab with spaces in vi

Windows files has line feed and carriage return. When such files are copied to *nix like OS, vim / vi shows ^M characters at the end of each line.
To get rid of those ^M use:
1,&#36; s/^M//gc
or
% s/^M//gc
To type ^M hit ctrl+v first and then M.
 楼主| 发表于 2007-10-2 02:18:26 | 显示全部楼层

show line number and fill tab with spaces in vi

more tips: http://www.vim.org/tips/tip_search_results.php
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表