vim 多行同时输入,且输入数值递增

很有用的命令。

很给力的说。

http://vim.wikia.com/wiki/Making_a_list_of_numbers

我在 html中需要增加新的标签的时候,就有用到过。

原来的html代码为:

 

            <div class="edit_box" id="box1">
                <label>
<
h1 class="title">Title1</h1>
<
p class="description">很好</p>
</
label> </div> <div class="edit_box" id="box2"> <label>
<
h1 class="title">Title2</h1>
<
p class="description">非常好</p>
</
label> </div> <div class="edit_box" id="box3"> <label>
<
h1 class="title">Title3</h1>
<
p class="description">相当好</p>
</
label>
</div>

 

先是用这个在html标签下增加了一行标签。

下面是vim命令,变成了如下的效果。

:g/<p class="description"/normal o<input type="hidden" id="hidden1" value=""/>

<
div class="edit_box" id="box1"> <label> <h1 class="title">Title1</h1> <p class="description">真好啊</p> <input type="hidden" id="hidden1" value=""/> </label> </div> <div class="edit_box" id="box2"> <label> <h1 class="title">Title2</h1> <p class="description">非常好</p> <input type="hidden" id="hidden1" value=""/> </label> </div> <div class="edit_box" id="box3"> <label> <h1 class="title">Title3</h1> <p class="description">相当好</p> <input type="hidden" id="hidden1" value=""/> </label> </div>

 上面的id="hidden1" 都是1的。我要将他们改变成1,2,3.。。依次递增的。所以,需要用到一点正则表达式,

还有特别有用的管道。我很钟爱哟~  :)

 

 

然后,又用这行,使标签中的id的值,依次递增。

 

:let i = 1 | g/id="hidden/s/\d/\=i/ | let i+=1
<div class="edit_box" id="box1">
                <label>
                    <h1 class="title">学习</h1>
                    <p class="description">如何在学业上掌握先机</p>
                    <input type="hidden" id="hidden1" value=""/>
                </label>

            </div>
            <div class="edit_box" id="box2">
                <label>
                    <h1 class="title">婚恋</h1>
                    <p class="description">你的爱情密码</p>
                    <input type="hidden" id="hidden2" value=""/>
                </label>

            </div>
            <div class="edit_box" id="box3">
                <label>
                    <h1 class="title">事业</h1>
                    <p class="description">成功的钥匙就在自己手中</p>
                    <input type="hidden" id="hidden3" value=""/>
                </label>

            </div>

然后,就成了这样,id="hidden3" 了。非常不错吧。

可以增加随意行,随意递增数啦。

 

各种加,非常爽的说。编程无极限啦~

 

这篇文章比较有用的 “Increasing or decreasing numbers” 地址:http://vim.wikia.com/wiki/Increasing_or_decreasing_numbers

好好看看吧。

 

————————————————————————NOTICE***NOTICE***Hahaha——————————————————————

不过要说的一点是,关于自动缩进,我已经安装好了如下的环境:

1.vim-pathogen 地址 https://github.com/tpope/vim-pathogen

2.NERDTree https://github.com/scrooloose/nerdtree (先装完vim-pathogen后再装NERDTree, 请看其github reference)

3.vim-sensible https://github.com/tpope/vim-sensible (先装完vim-pathogen后再装vim-sensible, 请看其github reference)

而我的 .vimrc 文件是下面这样的:

set expandtab
set tabstop=4
set shiftwidth=4
set softtabstop=4
set hls

execute pathogen#infect()
syntax on
filetype plugin indent on

解释为将tab更换成4个空格了,shiftwidth也等于4. 设置了搜索高亮。 set hls

设置了,用删除键删除4个空格的tab时,可以一键删除。

下面的是表示载入的~/.vim/autoload/pathogen.vim 中的这个函数infect()

  这个函数是导向 ~/.vim/bundle/   中的所有插件的地址,这样安装管理插件十分方便。大赞啊!!

就这么简单的设置,不算太复杂,用起来非常爽的说,你可以在代码的世界里任意傲游了,随意修改任何你想修改的部分,按照一定规律。 :)

 

Hv Fun :)

 

posted @ 2013-06-21 01:05  spaceship9  阅读(893)  评论(0编辑  收藏  举报