用vim二次开发别人的项目,感觉很不得劲

117 views
Skip to first unread message

Gandalf

unread,
Aug 21, 2011, 12:04:29 PM8/21/11
to Vim.cn
用vim自己从头开始写项目比较好,具体到每一个文件每一行代码,都是自己码字出来的,自己都摸的一清二楚,整个项目的所有文件每一行代码都在自己的脑
海形成蓝图了,这样用vim的时候指哪打哪。

但是接手别人的项目的时候,用vim打开别人的项目,感觉到眼前一片黑,读别人的代码的时候,有时候一屏看完了最好的体验是用鼠标逐行下来,下面的代码
慢慢浮现出来,跟上面的代码浑然一体,就像浏览网页,文字逐行滚动,甚至平滑滚动。

而用vim浏览别人的代码,用ctrl+f一次滚一屏,或者用ctrl+d一次滚半屏,这样读陌生的代码很吃力,猛的一下整个屏幕的代码都变了,跟上页
的缩进在脑海中形成的蓝图一下子全乱了。比如看一个函数,函数的上半部在一个屏幕,函数的下半部在另一个屏幕,这样用vim一屏一屏的向下翻很难在脑海
中整体把握这个函数的结构

当然了,会有高手说“你的理解代码能力的问题不要归罪到vim”,当然细细品读代码用vim也可以,但不如用滚动条逐行滚屏或平滑滚屏更省精力,这样可
以节省下来精力做其他事情。

用vim逐行滚屏我也找到了一个办法shift+l,然后j

另:mac下编辑器能像网页一样平滑滚屏,mac的用户体验确实不是盖的

Guodong Liang

unread,
Aug 21, 2011, 9:43:54 PM8/21/11
to vim...@googlegroups.com
很牵强。不就是读个代码么。。。而且读代码也不是顺序的,而是经常使用查找功能,不断跳转分析的。

2011/8/22 Gandalf <geng...@gmail.com>

--
要退订此论坛,请发邮件至 Vim-cn-un...@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/Vim-cn 访问该论坛

tocer

unread,
Aug 21, 2011, 9:56:56 PM8/21/11
to vim...@googlegroups.com
在 2011年8月22日 上午12:04,Gandalf <geng...@gmail.com> 写道:
> 用vim自己从头开始写项目比较好,具体到每一个文件每一行代码,都是自己码字出来的,自己都摸的一清二楚,整个项目的所有文件每一行代码都在自己的脑
> 海形成蓝图了,这样用vim的时候指哪打哪。
>
> 但是接手别人的项目的时候,用vim打开别人的项目,感觉到眼前一片黑,读别人的代码的时候,有时候一屏看完了最好的体验是用鼠标逐行下来,下面的代码
> 慢慢浮现出来,跟上面的代码浑然一体,就像浏览网页,文字逐行滚动,甚至平滑滚动。

ctrl-e 可以么? 当然不够平滑

>
> 而用vim浏览别人的代码,用ctrl+f一次滚一屏,或者用ctrl+d一次滚半屏,这样读陌生的代码很吃力,猛的一下整个屏幕的代码都变了,跟上页
> 的缩进在脑海中形成的蓝图一下子全乱了。比如看一个函数,函数的上半部在一个屏幕,函数的下半部在另一个屏幕,这样用vim一屏一屏的向下翻很难在脑海
> 中整体把握这个函数的结构

ctrl-d 可以设置设置滚动行数,参见 :h ctrl-d

依云

unread,
Aug 21, 2011, 9:56:30 PM8/21/11
to vim...@googlegroups.com

1. 一个函数最好不要超过一屏;
2. 自带有个 less.vim,可以一行行滚动,你可以参考下配置;
3. 我顺序阅读时一般是用的 j 或者鼠标滚轮。

--
Best regards,
lilydjwg

Linux Vim Python 我的博客
http://lilydjwg.is-programmer.com/

AleiPhoenix (A.K.A Areverie)

unread,
Aug 21, 2011, 10:03:23 PM8/21/11
to vim...@googlegroups.com
+1

一般某的代码是折叠的,加ctags跳转。不觉得阅读代码是很累的事情……倒是代码本身很烂就……

2011/8/22 依云 <lily...@gmail.com>
--
要退订此论坛,请发邮件至 Vim-cn-un...@googlegroups.com
 更多选项,请通过 http://groups.google.com/group/Vim-cn 访问该论坛



--
The enemy is always yourself.

twitter: @areverie
wikipedia: AleiPhoenix
blog: weblog.areverie.org
wiki: wiki.areverie.org


Eric Leung

unread,
Aug 21, 2011, 10:06:31 PM8/21/11
to Vim.cn
看代码用鼠标或键盘逐行滚动不就行了,哪个编辑器不是这样。平滑滚动无非增加视觉效果,用滚屏或者半屏看不明白的代码,加了个不到300ms的缓冲就能
看明白了?

Jian Cheng

unread,
Aug 21, 2011, 10:41:00 PM8/21/11
to vim...@googlegroups.com
re, ��������j���߷��򽡿����룬û�ù�ƽ������������

On 08/22/2011 10:06 AM, Eric Leung wrote:
> ������������������й����������ˣ��ĸ��༭����������ƽ�������޷������Ӿ�Ч���ù������߰����������׵Ĵ��룬���˸�����300ms�Ļ������
> �������ˣ�
>
> On 8��22��, ����12ʱ04��, Gandalf <gengsh...@gmail.com> wrote:
>> ��vim�Լ���ͷ��ʼд��Ŀ�ȽϺã����嵽ÿһ���ļ�ÿһ�д��룬�����Լ����ֳ����ģ��Լ�������һ������������Ŀ�������ļ�ÿһ�д��붼���Լ�����
>> ���γ���ͼ�ˣ�������vim��ʱ��ָ�Ĵ��ġ�
>>
>> ���ǽ��ֱ��˵���Ŀ��ʱ����vim�򿪱��˵���Ŀ���о�����ǰһƬ�ڣ������˵Ĵ����ʱ����ʱ��һ����������õ��������������������������Ĵ���
>> �����ֳ�����������Ĵ����Ȼһ�壬���������ҳ���������й���������ƽ��������
>>
>> ����vim������˵Ĵ��룬��ctrl+fһ�ι�һ����������ctrl+dһ�ι������������İ��Ĵ���ܳ������͵�һ�������Ļ�Ĵ��붼���ˣ�����ҳ
>> ���������Ժ����γɵ���ͼһ����ȫ���ˡ����翴һ����������ϰ벿��һ����Ļ��������°벿����һ����Ļ��������vimһ��һ�������·��������Ժ�
>> ����������������Ľṹ
>>
>> ��Ȼ�ˣ����и���˵��������������������ⲻҪ���ﵽvim������ȻϸϸƷ��������vimҲ���ԣ��������ù��������й�����ƽ��������ʡ�����������
>> �Խ�ʡ�����������������顣
>>
>> ��vim���й�����Ҳ�ҵ���һ���취shift+l��Ȼ��j
>>
>> �?mac�±༭��������ҳһ��ƽ��������mac���û�����ȷʵ���Ǹǵ�

Gandalf

unread,
Aug 22, 2011, 4:26:31 AM8/22/11
to Vim.cn
看看discuz的这段代码吧,光一个if一个else下面就700多行代码,里面又有层层嵌套的很多判断,这种代码必须按顺序读,并且不能一页一页的
翻,不然当前代码区块是在那个条件判断之内的都容易弄混,读这种代码滚屏的时候越平滑越好,因为这样700多行代码容易在脑海中形成一个整体的概念,而
不是来回跳转形成一个个的片段

editpost.inc.php的一段代码:

if(!submitcheck('editsubmit')) {


$icons = '';
if(!$special && is_array($_DCACHE['icons']) && $isfirstpost) {
$key = 1;
foreach($_DCACHE['icons'] as $id => $icon) {
$icons .= ' <input class="radio" type="radio" name="iconid"
value="'.$id.'" '.($thread['iconid'] == $id ? 'checked="checked"' :
'').' /><img src="images/icons/'.$icon.'" alt="" />';
$icons .= !(++$key % 10) ? '<br />' : '';
}
}

$postinfo = $db->fetch_first("SELECT * FROM {$tablepre}posts WHERE
pid='$pid' AND tid='$tid' AND fid='$fid'");

$usesigcheck = $postinfo['usesig'] ? 'checked="checked"' : '';
$urloffcheck = $postinfo['parseurloff'] ? 'checked="checked"' : '';
$smileyoffcheck = $postinfo['smileyoff'] == 1 ? 'checked="checked"' :
'';
$codeoffcheck = $postinfo['bbcodeoff'] == 1 ? 'checked="checked"' :
'';
$tagoffcheck = $postinfo['htmlon'] & 2 ? 'checked="checked"' : '';
$htmloncheck = $postinfo['htmlon'] & 1 ? 'checked="checked"' : '';
$showthreadsorts = ($thread['sortid'] || !empty($sortid)) &&
$isfirstpost;
$sortid = empty($sortid) ? $thread['sortid'] : $sortid;

$poll = $temppoll = '';
if($isfirstpost) {
if($special == 127) {
$sppos = strrpos($postinfo['message'], chr(0).chr(0).chr(0));
$specialextra = substr($postinfo['message'], $sppos + 3);
if($specialextra && array_key_exists($specialextra, $threadplugins)
&& in_array($specialextra, unserialize($forum['threadplugin'])) &&
in_array($specialextra, $allowthreadplugin)) {
$postinfo['message'] = substr($postinfo['message'], 0, $sppos);
} else {
$special = 0;
$specialextra = '';
}
}
$thread['freecharge'] = $maxchargespan && $timestamp -
$thread['dateline'] >= $maxchargespan * 3600 ? 1 : 0;
$freechargehours = !$thread['freecharge'] ? $maxchargespan -
intval(($timestamp - $thread['dateline']) / 3600) : 0;
if($thread['special'] == 1 && ($alloweditpoll || $thread['authorid']
== $discuz_uid)) {
$query = $db->query("SELECT polloptionid, displayorder, polloption,
multiple, visible, maxchoices, expiration, overt FROM {$tablepre}
polloptions AS polloptions LEFT JOIN {$tablepre}polls AS polls ON
polloptions.tid=polls.tid WHERE polls.tid ='$tid' ORDER BY
displayorder");
while($temppoll = $db->fetch_array($query)) {
$poll['multiple'] = $temppoll['multiple'];
$poll['visible'] = $temppoll['visible'];
$poll['maxchoices'] = $temppoll['maxchoices'];
$poll['expiration'] = $temppoll['expiration'];
$poll['overt'] = $temppoll['overt'];
$poll['polloptionid'][] = $temppoll['polloptionid'];
$poll['displayorder'][] = $temppoll['displayorder'];
$poll['polloption'][] = stripslashes($temppoll['polloption']);
}
$maxpolloptions = $maxpolloptions - $db->num_rows($query);
} elseif($thread['special'] == 3) {
$rewardprice = abs($thread['price']);
} elseif($thread['special'] == 4) {
$activitytypelist = $activitytype ? explode("\n",
trim($activitytype)) : '';
$activity = $db->fetch_first("SELECT * FROM {$tablepre}activities
WHERE tid='$tid'");
$activity['starttimefrom'] = gmdate("Y-m-d H:i",
$activity['starttimefrom'] + $timeoffset * 3600);
$activity['starttimeto'] = $activity['starttimeto'] ? gmdate("Y-m-d
H:i", $activity['starttimeto'] + $timeoffset * 3600) : '';
$activity['expiration'] = $activity['expiration'] ? gmdate("Y-m-d
H:i", $activity['expiration'] + $timeoffset * 3600) : '';
} elseif($thread['special'] == 5 ) {
$debate['endtime'] = $debate['endtime'] ? gmdate("Y-m-d H:i",
$debate['endtime'] + $timeoffset * 3600) : '';
}
}

if($thread['special'] == 2 && $allowposttrade) {
$query = $db->query("SELECT * FROM {$tablepre}trades WHERE
pid='$pid'");
$tradetypeselect = '';
if($db->num_rows($query)) {
$trade = $db->fetch_array($query);
$trade['expiration'] = $trade['expiration'] ? date('Y-m-d',
$trade['expiration']) : '';
$trade['costprice'] = $trade['costprice'] > 0 ?
$trade['costprice'] : '';
$trade['message'] = dhtmlspecialchars($trade['message']);
$tradetypeid = $trade['typeid'];
$forum['tradetypes'] = $forum['tradetypes'] == '' ? -1 :
unserialize($forum['tradetypes']);
if((!$tradetypeid || !isset($tradetypes[$tradetypeid]) && !
empty($forum['tradetypes']))) {
$tradetypeselect = '<select name="tradetypeid"
onchange="ajaxget(\'post.php?action=threadsorts&tradetype=yes&sortid=
\'+this.options[this.selectedIndex].value+\'&sid='.$sid.'\',
\'threadtypes\', \'threadtypeswait\')"><option value="0">&nbsp;</
option>';
foreach($tradetypes as $typeid => $name) {
if($forum['tradetypes'] == -1 || @in_array($typeid,
$forum['tradetypes'])) {
$tradetypeselect .= '<option value="'.
$typeid.'">'.strip_tags($name).'</option>';
}
}
$tradetypeselect .= '</select><span id="threadtypeswait"></span>';
} else {
$tradetypeselect = '<select disabled><option>'.
$tradetypes[$trade['typeid']].'</option></select>';
}
$expiration_7days = date('Y-m-d', $timestamp + 86400 * 7);
$expiration_14days = date('Y-m-d', $timestamp + 86400 * 14);
$expiration_month = date('Y-m-d', mktime(0, 0, 0, date('m')+1,
date('d'), date('Y')));
$expiration_3months = date('Y-m-d', mktime(0, 0, 0, date('m')+3,
date('d'), date('Y')));
$expiration_halfyear = date('Y-m-d', mktime(0, 0, 0, date('m')+6,
date('d'), date('Y')));
$expiration_year = date('Y-m-d', mktime(0, 0, 0, date('m'),
date('d'), date('Y')+1));
} else {
$tradetypeid = $special = 0;
$trade = array();
}
}

if($isfirstpost && $specialextra) {
@include_once DISCUZ_ROOT.'./plugins/'.$threadplugins[$specialextra]
['module'].'.class.php';
$classname = 'threadplugin_'.$specialextra;
if(method_exists($classname, 'editpost')) {
$threadpluginclass = new $classname;
$threadplughtml = $threadpluginclass->editpost($fid, $tid);
}
}

$postinfo['subject'] = str_replace('"', '&quot;',
$postinfo['subject']);
$postinfo['message'] = dhtmlspecialchars($postinfo['message']);
include_once language('misc');
$postinfo['message'] = preg_replace($language['post_edit_regexp'],
'', $postinfo['message']);

if($special == 5) {
$standselected = array($firststand => 'selected="selected"');
}

if($allowpostattach) {
$attachlist = getattach();
$attachs = $attachlist['attachs'];
$imgattachs = $attachlist['imgattachs'];
unset($attachlist);
$attachfind = $attachreplace = array();
if($attachs['used']) {
foreach($attachs['used'] as $attach) {
if($attach['isimage']) {
$attachfind[] = "/\[attach\]$attach[aid]\[\/attach\]/i";
$attachreplace[] = '[attachimg]'.$attach['aid'].'[/attachimg]';
}
}
}
if($imgattachs['used']) {
foreach($imgattachs['used'] as $attach) {
$attachfind[] = "/\[attach\]$attach[aid]\[\/attach\]/i";
$attachreplace[] = '[attachimg]'.$attach['aid'].'[/attachimg]';
}
}
$attachfind && $postinfo['message'] = preg_replace($attachfind,
$attachreplace, $postinfo['message']);
}
if($special == 2 && $trade['aid'] && !empty($imgattachs['used']) &&
is_array($imgattachs['used'])) {
foreach($imgattachs['used'] as $k => $tradeattach) {
if($tradeattach['aid'] == $trade['aid']) {
unset($imgattachs['used'][$k]);
break;
}
}
}

include template('post');

} else {

$redirecturl = "viewthread.php?tid=$tid&page=$page&extra=$extra".
($vid && $isfirstpost ? "&vid=$vid" : '')."#pid$pid";

if(empty($delete)) {

if($post_invalid = checkpost($isfirstpost && $special)) {
showmessage($post_invalid);
}

if(!$isorigauthor && !$allowanonymous) {
if($orig['anonymous'] && !$isanonymous) {
$isanonymous = 0;
$authoradd = ', author=\''.addslashes($orig['author']).'\'';
$anonymousadd = ', anonymous=\'0\'';
} else {
$isanonymous = $orig['anonymous'];
$authoradd = $anonymousadd = '';
}
} else {
$authoradd = ', author=\''.($isanonymous ? '' :
addslashes($orig['author'])).'\'';
$anonymousadd = ", anonymous='$isanonymous'";
}

if($isfirstpost) {

if($subject == '') {
showmessage('post_sm_isnull');
}

if(!$sortid && !$thread['special'] && $message == '') {
showmessage('post_sm_isnull');
}

$typeid = isset($forum['threadtypes']['types'][$typeid]) ?
$typeid : 0;
$sortid = isset($forum['threadsorts']['types'][$sortid]) ?
$sortid : 0;
$iconid = isset($_DCACHE['icons'][$iconid]) ? $iconid : 0;

if(!$typeid && $forum['threadtypes']['required'] && !
$thread['special']) {
showmessage('post_type_isnull');
}

$readperm = $allowsetreadperm ? intval($readperm) :
($isorigauthor ? 0 : 'readperm');
if($thread['special'] == 3) {
$price = $thread['price'];
}
$price = intval($price);
$price = $thread['price'] < 0 && !$thread['special']
?($isorigauthor || !$price ? -1 : $price)
:($maxprice ? ($price <= $maxprice ? ($price > 0 ? $price : 0) :
$maxprice) : ($isorigauthor ? $price : $thread['price']));

if($price > 0 && floor($price * (1 - $creditstax)) == 0) {
showmessage('post_net_price_iszero');
}

$polladd = '';
if($thread['special'] == 1 && ($alloweditpoll || $isorigauthor) && !
empty($polls)) {
$pollarray = '';
foreach($polloption as $key => $value) {
if($value === '') {
unset($polloption[$key], $displayorder[$key]);
}
}
$pollarray['options'] = $polloption;
if($pollarray['options']) {
if(count($pollarray['options']) > $maxpolloptions) {
showmessage('post_poll_option_toomany');
}
foreach($pollarray['options'] as $key => $value) {
if(!trim($value)) {
$db->query("DELETE FROM {$tablepre}polloptions WHERE
polloptionid='$key' AND tid='$tid'");
unset($pollarray['options'][$key]);
}
}
$polladd = ', special=\'1\'';
foreach($displayorder as $key => $value) {
if(preg_match("/^-?\d*$/", $value)) {
$pollarray['displayorder'][$key] = $value;
}
}
$pollarray['multiple'] = !empty($multiplepoll);
$pollarray['visible'] = empty($visibilitypoll);
$pollarray['expiration'] = $expiration;
$pollarray['overt'] = !empty($overt);
foreach($polloptionid as $key => $value) {
if(!preg_match("/^\d*$/", $value)) {
showmessage('submit_invalid');
}
}
$maxchoices = !empty($multiplepoll) ? (!$maxchoices ||
$maxchoices >= count($pollarray['options']) ?
count($pollarray['options']) : $maxchoices) : '';
if(preg_match("/^\d*$/", $maxchoices)) {
if(!$pollarray['multiple']) {
$pollarray['maxchoices'] = 1;
} elseif(empty($maxchoices)) {
$pollarray['maxchoices'] = 0;
} else {
$pollarray['maxchoices'] = $maxchoices;
}
}
$expiration = intval($expiration);
if($close) {
$pollarray['expiration'] = $timestamp;
} elseif($expiration) {
if(empty($pollarray['expiration'])) {
$pollarray['expiration'] = 0;
} else {
$pollarray['expiration'] = $timestamp + 86400 * $expiration;
}
}
$optid = '';
$query = $db->query("SELECT polloptionid FROM {$tablepre}
polloptions WHERE tid='$tid'");
while($tempoptid = $db->fetch_array($query)) {
$optid[] = $tempoptid['polloptionid'];
}
foreach($pollarray['options'] as $key => $value) {
$value = dhtmlspecialchars(trim($value));
if(in_array($polloptionid[$key], $optid)) {
if($alloweditpoll) {
$db->query("UPDATE {$tablepre}polloptions SET displayorder='".
$pollarray['displayorder'][$key]."', polloption='$value' WHERE
polloptionid='$polloptionid[$key]' AND tid='$tid'");
} else {
$db->query("UPDATE {$tablepre}polloptions SET displayorder='".
$pollarray['displayorder'][$key]."' WHERE
polloptionid='$polloptionid[$key]' AND tid='$tid'");
}
} else {
$db->query("INSERT INTO {$tablepre}polloptions (tid,
displayorder, polloption) VALUES ('$tid', '".$pollarray['displayorder']
[$key]."', '$value')");
}
}
$db->query("UPDATE {$tablepre}polls SET
multiple='$pollarray[multiple]', visible='$pollarray[visible]',
maxchoices='$pollarray[maxchoices]',
expiration='$pollarray[expiration]', overt='$pollarray[overt]' WHERE
tid='$tid'", 'UNBUFFERED');
} else {
$polladd = ', special=\'0\'';
$db->query("DELETE FROM {$tablepre}polls WHERE tid='$tid'");
$db->query("DELETE FROM {$tablepre}polloptions WHERE
tid='$tid'");
}

} elseif($thread['special'] == 3 && ($allowpostreward ||
$isorigauthor)) {

if($thread['price'] > 0 && $thread['price'] != $rewardprice) {
$rewardprice = intval($rewardprice);
if($rewardprice <= 0){
showmessage("reward_credits_invalid");
}
$addprice = ceil(($rewardprice - $thread['price']) +
($rewardprice - $thread['price']) * $creditstax);
if(!$forum['ismoderator']) {
if($rewardprice < $thread['price']) {
showmessage("reward_credits_fall");
} elseif($rewardprice < $minrewardprice || ($maxrewardprice > 0
&& $rewardprice > $maxrewardprice)) {
showmessage("reward_credits_between");
} elseif($addprice > $_DSESSION["extcredits
$creditstransextra[2]"]) {
showmessage('reward_credits_shortage');
}
}
$realprice = ceil($thread['price'] + $thread['price'] *
$creditstax) + $addprice;

$db->query("UPDATE {$tablepre}members SET extcredits
$creditstransextra[2]=extcredits$creditstransextra[2]-$addprice WHERE
uid='$thread[authorid]'");
$db->query("UPDATE {$tablepre}rewardlog SET
netamount='$realprice' WHERE tid='$tid' AND
authorid='$thread[authorid]'");
}

if(!$forum['ismoderator']) {

if($thread['replies'] > 1) {
$subject = addslashes($thread['subject']);
}

if($thread['price'] < 0) {
$rewardprice = abs($thread['price']);
}
}

$price = $thread['price'] > 0 ? $rewardprice : -$rewardprice;

} elseif($thread['special'] == 4 && $allowpostactivity) {

$activitytime = intval($activitytime);
if(empty($starttimefrom[$activitytime])) {
showmessage('activity_fromtime_please');
} elseif(strtotime($starttimefrom[$activitytime]) === -1 ||
@strtotime($starttimefrom[$activitytime]) === FALSE) {
showmessage('activity_fromtime_error');
} elseif($activitytime && ((@strtotime($starttimefrom) >
@strtotime($starttimeto) || !$starttimeto))) {
showmessage('activity_fromtime_error');
} elseif(!trim($activityclass)) {
showmessage('activity_sort_please');
} elseif(!trim($activityplace)) {
showmessage('activity_address_please');
} elseif(trim($activityexpiration) &&
(@strtotime($activityexpiration) === -1 ||
@strtotime($activityexpiration) === FALSE)) {
showmessage('activity_totime_error');
}

$activity = array();
$activity['class'] = dhtmlspecialchars(trim($activityclass));
$activity['starttimefrom'] =
@strtotime($starttimefrom[$activitytime]);
$activity['starttimeto'] = $activitytime ?
@strtotime($starttimeto) : 0;
$activity['place'] = dhtmlspecialchars(trim($activityplace));
$activity['cost'] = intval($cost);
$activity['gender'] = intval($gender);
$activity['number'] = intval($activitynumber);
if($activityexpiration) {
$activity['expiration'] = @strtotime($activityexpiration);
} else {
$activity['expiration'] = 0;
}

$db->query("UPDATE {$tablepre}activities SET
cost='$activity[cost]', starttimefrom='$activity[starttimefrom]',
starttimeto='$activity[starttimeto]', place='$activity[place]',
class='$activity[class]', gender='$activity[gender]',
number='$activity[number]', expiration='$activity[expiration]' WHERE
tid='$tid'", 'UNBUFFERED');

} elseif($thread['special'] == 5 && $allowpostdebate) {

if(empty($affirmpoint) || empty($negapoint)) {
showmessage('debate_position_nofound');
} elseif(!empty($endtime) && (!($endtime = @strtotime($endtime))
|| $endtime < $timestamp)) {
showmessage('debate_endtime_invalid');
} elseif(!empty($umpire)) {
if(!$db->result_first("SELECT COUNT(*) FROM {$tablepre}members
WHERE username='$umpire'")) {
$umpire = dhtmlspecialchars($umpire);
showmessage('debate_umpire_invalid');
}
}
$affirmpoint = dhtmlspecialchars($affirmpoint);
$negapoint = dhtmlspecialchars($negapoint);
$db->query("UPDATE {$tablepre}debates SET
affirmpoint='$affirmpoint', negapoint='$negapoint',
endtime='$endtime', umpire='$umpire' WHERE tid='$tid' AND
uid='$discuz_uid'");

} elseif($specialextra) {

@include_once DISCUZ_ROOT.'./plugins/'.
$threadplugins[$specialextra]['module'].'.class.php';
$classname = 'threadplugin_'.$specialextra;
if(method_exists($classname, 'editpost_submit')) {
$threadpluginclass = new $classname;
$threadpluginclass->editpost_submit($fid, $tid);
}

}

$optiondata = array();
if($forum['threadsorts']['types'][$sortid] && $checkoption) {
$optiondata = threadsort_validator($typeoption);
}

if($forum['threadsorts']['types'][$sortid] && $optiondata &&
is_array($optiondata)) {
foreach($optiondata as $optionid => $value) {
if($_DTYPE[$optionid]['type'] == 'image') {
$oldvalue = $db->result_first("SELECT value FROM {$tablepre}
typeoptionvars WHERE tid='$tid' AND optionid='$optionid'");
if($oldvalue != $value) {
if(preg_match("/^\[aid=(\d+)\]$/", $oldvalue, $r)) {
$attach = $db->fetch_first("SELECT attachment, thumb, remote
FROM {$tablepre}attachments WHERE aid='$r[1]'");
$db->query("DELETE FROM {$tablepre}attachments WHERE
aid='$r[1]'");
dunlink($attach['attachment'], $attach['thumb'],
$attach['remote']);
}
}
}
$db->query("UPDATE {$tablepre}typeoptionvars SET value='$value',
sortid='$sortid' WHERE tid='$tid' AND optionid='$optionid'");
}
}

$db->query("UPDATE {$tablepre}threads SET iconid='$iconid',
typeid='$typeid', sortid='$sortid', subject='$subject',
readperm='$readperm', price='$price' $authoradd $polladd ".
($auditstatuson && $audit == 1 ? ",displayorder='0', moderated='1'" :
'')." WHERE tid='$tid'", 'UNBUFFERED');

if($tagstatus) {
$tags = str_replace(array(chr(0xa3).chr(0xac),
chr(0xa1).chr(0x41), chr(0xef).chr(0xbc).chr(0x8c)), ',',
censor($tags));
if(strexists($tags, ',')) {
$tagarray = array_unique(explode(',', $tags));
} else {
$tags = str_replace(array(chr(0xa1).chr(0xa1),
chr(0xa1).chr(0x40), chr(0xe3).chr(0x80).chr(0x80)), ' ', $tags);
$tagarray = array_unique(explode(' ', $tags));
}
$threadtagsnew = array();
$tagcount = 0;
foreach($tagarray as $tagname) {
$tagname = trim($tagname);
if(preg_match('/^([\x7f-\xff_-]|\w|\s){3,20}$/', $tagname)) {
$threadtagsnew[] = $tagname;
if(!in_array($tagname, $threadtagary)) {
$query = $db->query("SELECT closed FROM {$tablepre}tags WHERE
tagname='$tagname'");
if($db->num_rows($query)) {
if(!$tagstatus = $db->result($query, 0)) {
$db->query("UPDATE {$tablepre}tags SET total=total+1 WHERE
tagname='$tagname'", 'UNBUFFERED');
}
} else {
$db->query("INSERT INTO {$tablepre}tags (tagname, closed,
total)
VALUES ('$tagname', 0, 1)", 'UNBUFFERED');
$tagstatus = 0;
}
if(!$tagstatus) {
$db->query("INSERT {$tablepre}threadtags (tagname, tid) VALUES
('$tagname', '$tid')", 'UNBUFFERED');
}
}
}
$tagcount++;
if($tagcount > 4) {
unset($tagarray);
break;
}
}
foreach($threadtagary as $tagname) {
if(!in_array($tagname, $threadtagsnew)) {
if($db->result_first("SELECT count(*) FROM {$tablepre}threadtags
WHERE tagname='$tagname' AND tid!='$tid'")) {
$db->query("UPDATE {$tablepre}tags SET total=total-1 WHERE
tagname='$tagname'", 'UNBUFFERED');
} else {
$db->query("DELETE FROM {$tablepre}tags WHERE
tagname='$tagname'", 'UNBUFFERED');
}
$db->query("DELETE FROM {$tablepre}threadtags WHERE
tagname='$tagname' AND tid='$tid'", 'UNBUFFERED');
}
}
}

} else {

if($subject == '' && $message == '') {
showmessage('post_sm_isnull');
}

}

if($editedby && ($timestamp - $orig['dateline']) > 60 && $adminid !=
1) {
include_once language('misc');

$editor = $isanonymous && $isorigauthor ? $language['anonymous'] :
$discuz_user;
$edittime = gmdate($_DCACHE['settings']['dateformat'].' '.
$_DCACHE['settings']['timeformat'], $timestamp + $timeoffset * 3600);
eval("\$message = \"$language[post_edit]\".\$message;");
}

$bbcodeoff = checkbbcodes($message, !empty($bbcodeoff));
$smileyoff = checksmilies($message, !empty($smileyoff));
$tagoff = $isfirstpost ? !empty($tagoff) : 0;
$htmlon = bindec(($tagstatus && $tagoff ? 1 : 0).($allowhtml && !
empty($htmlon) ? 1 : 0));

$uattachment = ($allowpostattach && $uattachments =
attach_upload('attachupdate', 1)) ? 1 : 0;
if($uattachment) {
$query = $db->query("SELECT aid, tid, pid, uid, attachment, thumb,
remote FROM {$tablepre}attachments WHERE pid='$pid'");
while($attach = $db->fetch_array($query)) {
$paid = 'paid'.$attach['aid'];
$attachfileadd = '';
if($uattachment && isset($uattachments[$paid])) {
dunlink($attach['attachment'], $attach['thumb'],
$attach['remote']);
$attachfileadd = 'dateline=\''.$timestamp.'\',
filename=\''.$uattachments[$paid]['name'].'\',
filetype=\''.$uattachments[$paid]['type'].'\',
filesize=\''.$uattachments[$paid]['size'].'\',
attachment=\''.$uattachments[$paid]['attachment'].'\',
thumb=\''.$uattachments[$paid]['thumb'].'\',
isimage=\'-'.$uattachments[$paid]['isimage'].'\',
remote=\''.$uattachments[$paid]['remote'].'\',
width=\''.$uattachments[$paid]['width'].'\'';
unset($uattachments[$paid]);
}

if($attachfileadd) $db->query("UPDATE {$tablepre}attachments SET
$attachfileadd WHERE aid='$attach[aid]'");
}
}

$allowpostattach && ($attachnew || $attachdel || $special == 2 &&
$tradeaid || $isfirstpost && $sortid) && updateattach();

if($uattachment || $attachdel) {
$tattachment = $db->result_first("SELECT count(*) FROM {$tablepre}
posts p, {$tablepre}attachments a WHERE a.tid='$tid' AND a.isimage IN
('1', '-1') AND a.pid=p.pid AND p.invisible='0' LIMIT 1") ? 2 :
($db->result_first("SELECT count(*) FROM {$tablepre}posts p,
{$tablepre}attachments a WHERE a.tid='$tid' AND a.pid=p.pid AND
p.invisible='0' LIMIT 1") ? 1 : 0);

$db->query("UPDATE {$tablepre}threads SET attachment='$tattachment'
WHERE tid='$tid'");
}

if($special == 2 && $allowposttrade) {

$oldtypeid = $db->result_first("SELECT typeid FROM {$tablepre}
trades WHERE pid='$pid'");
$oldtypeid = isset($tradetypes[$oldtypeid]) ? $oldtypeid : 0;
$tradetypeid = !$tradetypeid ? $oldtypeid : $tradetypeid;
$optiondata = array();
threadsort_checkoption($oldtypeid, 1);
$optiondata = array();
if($tradetypes && $typeoption && is_array($typeoption) &&
$checkoption) {
$optiondata = threadsort_validator($typeoption);
}

if($tradetypes && $optiondata && is_array($optiondata)) {
foreach($optiondata as $optionid => $value) {
if($oldtypeid) {
$db->query("UPDATE {$tablepre}tradeoptionvars SET value='$value'
WHERE pid='$pid' AND optionid='$optionid'");
} else {
$db->query("INSERT INTO {$tablepre}tradeoptionvars (sortid, pid,
optionid, value)
VALUES ('$tradetypeid', '$pid', '$optionid', '$value')");
}
}
}

if(!$oldtypeid) {
$db->query("UPDATE {$tablepre}trades SET typeid='$tradetypeid'
WHERE pid='$pid'");
}

if($trade = $db->fetch_first("SELECT * FROM {$tablepre}trades WHERE
tid='$tid' AND pid='$pid'")) {
$seller = dhtmlspecialchars(trim($seller));
$item_name = dhtmlspecialchars(trim($item_name));
$item_price = floatval($item_price);
$item_credit = intval($item_credit);
$item_locus = dhtmlspecialchars(trim($item_locus));
$item_number = intval($item_number);
$item_quality = intval($item_quality);
$item_transport = intval($item_transport);
$postage_mail = intval($postage_mail);
$postage_express = intval(trim($postage_express));
$postage_ems = intval($postage_ems);
$item_type = intval($item_type);
$item_costprice = floatval($item_costprice);

if(!trim($item_name)) {
showmessage('trade_please_name');
} elseif($maxtradeprice && $item_price > 0 && ($mintradeprice >
$item_price || $maxtradeprice < $item_price)) {
showmessage('trade_price_between');
} elseif($maxtradeprice && $item_credit > 0 && ($mintradeprice >
$item_credit || $maxtradeprice < $item_credit)) {
showmessage('trade_credit_between');
} elseif(!$maxtradeprice && $item_price > 0 && $mintradeprice >
$item_price) {
showmessage('trade_price_more_than');
} elseif(!$maxtradeprice && $item_credit > 0 && $mintradeprice >
$item_credit) {
showmessage('trade_credit_more_than');
} elseif($item_price <= 0 && $item_credit <= 0) {
showmessage('trade_pricecredit_need');
} elseif($item_number < 1) {
showmessage('tread_please_number');
}

if($trade['aid'] != $tradeaid) {
$attach = $db->fetch_first("SELECT attachment, thumb, remote FROM
{$tablepre}attachments WHERE aid='$trade[aid]'");
$db->query("DELETE FROM {$tablepre}attachments WHERE
aid='$trade[aid]'");
dunlink($attach['attachment'], $attach['thumb'],
$attach['remote']);
}

$expiration = $item_expiration ? @strtotime($item_expiration) : 0;
$closed = $expiration > 0 && @strtotime($item_expiration) <
$timestamp ? 1 : $closed;

switch($transport) {
case 'seller':$item_transport = 1;break;
case 'buyer':$item_transport = 2;break;
case 'virtual':$item_transport = 3;break;
case 'logistics':$item_transport = 4;break;
}
if(!$item_price || $item_price <= 0) {
$item_price = $postage_mail = $postage_express = $postage_ems =
'';
}

$db->query("UPDATE {$tablepre}trades SET aid='$tradeaid',
account='$seller', subject='$item_name', price='$item_price',
amount='$item_number', quality='$item_quality', locus='$item_locus',
transport='$item_transport', ordinaryfee='$postage_mail',
expressfee='$postage_express', emsfee='$postage_ems',
itemtype='$item_type', expiration='$expiration', closed='$closed',
costprice='$item_costprice', credit='$item_credit',
costcredit='$item_costcredit' WHERE tid='$tid' AND pid='$pid'",
'UNBUFFERED');

if(!empty($infloat)) {
$viewpid = $db->result_first("SELECT pid FROM {$tablepre}posts
WHERE tid='$tid' AND first='1' LIMIT 1");
$redirecturl = "viewthread.php?tid=$tid&viewpid=$viewpid#pid
$viewpid";
} else {
$redirecturl = "viewthread.php?do=tradeinfo&tid=$tid&pid=$pid";
}
}

}

$feed = array();
if($special == 127) {

$message .= chr(0).chr(0).chr(0).$specialextra;

}

if($auditstatuson && $audit == 1) {
updatepostcredits('+', $orig['authorid'], ($isfirstpost ?
$postcredits : $replycredits));
updatemodworks('MOD', 1);
updatemodlog($tid, 'MOD');
}

$message = preg_replace('/\[attachimg\](\d+)\[\/attachimg\]/is',
'[attach]\1[/attach]', $message);
$db->query("UPDATE {$tablepre}posts SET message='$message',
usesig='$usesig', htmlon='$htmlon', bbcodeoff='$bbcodeoff',
parseurloff='$parseurloff',
smileyoff='$smileyoff', subject='$subject' ".($db-
>result_first("SELECT aid FROM {$tablepre}attachments WHERE pid='$pid'
LIMIT 1") ? ", attachment='1'" : '')." $anonymousadd ".($auditstatuson
&& $audit == 1 ? ",invisible='0'" : '')." WHERE pid='$pid'");

$forum['lastpost'] = explode("\t", $forum['lastpost']);

if($orig['dateline'] == $forum['lastpost'][2] && ($orig['author'] ==
$forum['lastpost'][3] || ($forum['lastpost'][3] == '' &&
$orig['anonymous']))) {
$lastpost = "$tid\t".($isfirstpost ? $subject :
addslashes($thread['subject']))."\t$orig[dateline]\t".($isanonymous ?
'' : addslashes($orig['author']));
$db->query("UPDATE {$tablepre}forums SET lastpost='$lastpost' WHERE
fid='$fid'", 'UNBUFFERED');
}

if($thread['lastpost'] == $orig['dateline'] && ((!$orig['anonymous']
&& $thread['lastposter'] == $orig['author']) || ($orig['anonymous'] &&
$thread['lastposter'] == '')) && $orig['anonymous'] != $isanonymous) {
$db->query("UPDATE {$tablepre}threads SET lastposter='".
($isanonymous ? '' : addslashes($orig['author']))."' WHERE
tid='$tid'", 'UNBUFFERED');
}

$attentionon = empty($attention_add) ? 0 : 1;
$attentionoff = empty($attention_remove) ? 0 : 1;
if($discuz_uid) {
$stataction = '';
if($attentionon) {
$stataction = 'attentionon';
$db->query("REPLACE INTO {$tablepre}favoritethreads (tid, uid,
dateline) VALUES ('$tid', '$discuz_uid', '$timestamp')",
'UNBUFFERED');
}
if($attentionoff) {
$stataction = 'attentionoff';
$db->query("DELETE FROM {$tablepre}favoritethreads WHERE
tid='$tid' AND uid='$discuz_uid'", 'UNBUFFERED');
}
if($stataction) {
//统计各类通知条数
write_statlog('', 'item=attention&action=editpost_'.$stataction,
'', '', 'my.php');
}
}

if(!$isorigauthor) {
updatemodworks('EDT', 1);
require_once DISCUZ_ROOT.'./include/misc.func.php';
modlog($thread, 'EDT');
}

if($thread['special'] == 3 && $isfirstpost) {
$pricediff = $rewardprice - $thread['price'];
$db->query("UPDATE {$tablepre}members SET extcredits
$creditstransextra[2]=extcredits$creditstransextra[2]-$pricediff WHERE
uid='$orig[authorid]'", 'UNBUFFERED');
}

} else {

if($isfirstpost && $thread['replies'] > 0) {
showmessage(($thread['special'] == 3 ?
'post_edit_reward_already_reply' : 'post_edit_thread_already_reply'),
NULL, 'HALTED');
}

if($thread['special'] == 3) {
if($thread['price'] < 0 && ($thread['dateline'] + 1 ==
$orig['dateline'])) {
showmessage('post_edit_reward_nopermission', NULL, 'HALTED');
}
}

updatepostcredits('-', $orig['authorid'], ($isfirstpost ?
$postcredits : $replycredits));

if($thread['special'] == 3 && $isfirstpost) {
$db->query("UPDATE {$tablepre}members SET extcredits
$creditstransextra[2]=extcredits$creditstransextra[2]+$thread[price]
WHERE uid='$orig[authorid]'", 'UNBUFFERED');
$db->query("DELETE FROM {$tablepre}rewardlog WHERE tid='$tid'",
'UNBUFFERED');
}

$thread_attachment = $post_attachment = 0;
$query = $db->query("SELECT pid, attachment, thumb, remote FROM
{$tablepre}attachments WHERE tid='$tid'");
while($attach = $db->fetch_array($query)) {
if($attach['pid'] == $pid) {
$post_attachment ++;
dunlink($attach['attachment'], $attach['thumb'],
$attach['remote']);
} else {
$thread_attachment = 1;
}
}

if($post_attachment) {
$db->query("DELETE FROM {$tablepre}attachments WHERE pid='$pid'",
'UNBUFFEREED');
$db->query("DELETE FROM {$tablepre}attachmentfields WHERE
pid='$pid'", 'UNBUFFERED');
updatecredits($orig['authorid'], $postattachcredits, -
($post_attachment));
}

$db->query("DELETE FROM {$tablepre}posts WHERE pid='$pid'");
if($thread['special'] == 2) {
$db->query("DELETE FROM {$tablepre}trades WHERE pid='$pid'");
}

if($isfirstpost) {
$forumadd = 'threads=threads-\'1\', posts=posts-\'1\'';
$tablearray =
array('threadsmod','relatedthreads','threads','debates','debateposts','polloptions','polls','typeoptionvars');
foreach ($tablearray as $table) {
$db->query("DELETE FROM {$tablepre}$table WHERE tid='$tid'",
'UNBUFFERED');
}
if($globalstick && in_array($thread['displayorder'], array(2, 3)))
{
require_once DISCUZ_ROOT.'./include/cache.func.php';
updatecache('globalstick');
}
} else {
$forumadd = 'posts=posts-\'1\'';
$query = $db->query("SELECT author, dateline, anonymous FROM
{$tablepre}posts WHERE tid='$tid' AND invisible='0' ORDER BY dateline
DESC LIMIT 1");
$lastpost = $db->fetch_array($query);
$lastpost['author'] = !$lastpost['anonymous'] ?
addslashes($lastpost['author']) : '';
$db->query("UPDATE {$tablepre}threads SET replies=replies-'1',
attachment='$thread_attachment', lastposter='$lastpost[author]',
lastpost='$lastpost[dateline]' WHERE tid='$tid'", 'UNBUFFERED');
}

$forum['lastpost'] = explode("\t", $forum['lastpost']);
if($orig['dateline'] == $forum['lastpost'][2] && ($orig['author'] ==
$forum['lastpost'][3] || ($forum['lastpost'][3] == '' &&
$orig['anonymous']))) {
$lastthread = daddslashes($db->fetch_first("SELECT tid, subject,
lastpost, lastposter FROM {$tablepre}threads
WHERE fid='$fid' AND displayorder>='0' ORDER BY lastpost DESC
LIMIT 1"), 1);
$forumadd .= ", lastpost='$lastthread[tid]\t$lastthread[subject]\t
$lastthread[lastpost]\t$lastthread[lastposter]'";
}

$db->query("UPDATE {$tablepre}forums SET $forumadd WHERE
fid='$fid'", 'UNBUFFERED');

}

if($specialextra) {

@include_once DISCUZ_ROOT.'./plugins/'.$threadplugins[$specialextra]
['module'].'.class.php';
$classname = 'threadplugin_'.$specialextra;
if(method_exists($classname, 'editpost_submit_end')) {
$threadpluginclass = new $classname;
$threadpluginclass->editpost_submit_end($fid, $tid);
}

}

// debug: update thread caches ?
if($forum['threadcaches']) {
if($isfirstpost || $page == 1 || $thread['replies'] <
$_DCACHE['pospperpage'] || !empty($delete)) {
$forum['threadcaches'] && deletethreadcaches($tid);
} else {
if($db->result_first("SELECT COUNT(*) FROM {$tablepre}posts WHERE
tid='$tid' AND pid<'$pid'") < $_DCACHE['settings']['postperpage']) {
$forum['threadcaches'] && deletethreadcaches($tid);
}
}
}

if($auditstatuson) {
if($audit == 1) {
showmessage('auditstatuson_succeed', $redirecturl);
} else {
showmessage('audit_edit_succeed');
}
} else {
if(!empty($delete) && $isfirstpost) {
showmessage('post_edit_delete_succeed', "forumdisplay.php?fid=
$fid");
} elseif(!empty($delete)) {
showmessage('post_edit_delete_succeed', "viewthread.php?tid=
$tid&page=$page&extra=$extra".($vid && $isfirstpost ? "&vid=$vid" :
''));
} else {
showmessage('post_edit_succeed', $redirecturl);
}
}

}

On 8月22日, 上午9时43分, Guodong Liang <name5...@gmail.com> wrote:
> 很牵强。不就是读个代码么。。。而且读代码也不是顺序的,而是经常使用查找功能,不断跳转分析的。
>
> 2011/8/22 Gandalf <gengsh...@gmail.com>

tocer

unread,
Aug 22, 2011, 4:33:47 AM8/22/11
to vim...@googlegroups.com
在 2011年8月22日 下午4:26,Gandalf <geng...@gmail.com> 写道:
> 看看discuz的这段代码吧,光一个if一个else下面就700多行代码,里面又有层层嵌套的很多判断,这种代码必须按顺序读,并且不能一页一页的
> 翻,不然当前代码区块是在那个条件判断之内的都容易弄混,读这种代码滚屏的时候越平滑越好,因为这样700多行代码容易在脑海中形成一个整体的概念,而
> 不是来回跳转形成一个个的片段
>
> editpost.inc.php的一段代码:


好家伙,这样的代码该怎么进行单元测试的呢?

書瀚張

unread,
Aug 22, 2011, 4:36:42 AM8/22/11
to vim...@googlegroups.com
好强大的代码,但是VIM不是不支持鼠标慢慢滚吧?
只不过是支持滚屏的方式更多样而已……

在 2011年8月22日 下午4:26,Gandalf <geng...@gmail.com>写道:

Eric Leung

unread,
Aug 22, 2011, 4:39:20 AM8/22/11
to Vim.cn
康盛是用错误的编程方法写出热卖产品的光辉典范......
IE9的滚动是平滑滚动的,而且还是硬件加速的哦,您可以将你的php文件导出html,放到ie9里平滑滚屏,看能不能把原本读不懂的代码看懂。祝你
好运。
> ...
>
> 阅读更多 >>

書瀚張

unread,
Aug 22, 2011, 4:40:54 AM8/22/11
to vim...@googlegroups.com
赞【康盛是用错误的编程方法写出热卖产品的光辉典范......】
我说VIM一次好像就是固定滚三行吧?很有定位感啊亲!有那么令人讨厌么?

Gandalf

unread,
Aug 22, 2011, 4:58:22 AM8/22/11
to Vim.cn
产品优雅跟代码优雅经常会有冲突,康盛只不过把产品的优雅放在了第一位,毕竟用户操作的是产品,而不关心产品后面的代码是否优雅。

Luo Jiesi

unread,
Aug 22, 2011, 5:05:41 AM8/22/11
to vim...@googlegroups.com
求证+OT一下,duscuz在chrome下有问题吧,注册新用户或发贴什么要手动刷新才能见到效果吧?

2011/8/22 Gandalf <geng...@gmail.com>
--
要退订此论坛,请发邮件至 Vim-cn-un...@googlegroups.com

 更多选项,请通过 http://groups.google.com/group/Vim-cn 访问该论坛



--
luojiesi@zju

Guodong Liang

unread,
Aug 22, 2011, 5:14:20 AM8/22/11
to vim...@googlegroups.com
读代码能力和 VIM 无关,鉴定完毕。

2011/8/22 Luo Jiesi <luoji...@gmail.com>

Eric Leung

unread,
Aug 22, 2011, 5:24:11 AM8/22/11
to Vim.cn
还真没听过产品跟代码有冲突的,只听说过优雅的接口背后大多都有龌龊的实现……我的意思不是说康盛的水平低,discuz历史悠久包袱沉重,不大可能不
顾市场重写代码,discuz很多功能点的实现还是值得借鉴的,但绝对不赞成那种代码编写方式。毕竟,php4之后地球已经转了好多好多圈了……

args

unread,
Aug 22, 2011, 5:30:32 AM8/22/11
to Vim.cn
我又想起来phpwind的代码,这货输出居然是用here document。而且处处充满了quick&dirty 当年自定义的时候那个崩溃啊。

Jacky Liu

unread,
Aug 22, 2011, 6:56:45 PM8/22/11
to vim...@googlegroups.com
Emacs 能在不同窗口使用不同大小的字体,所以可以用很小的字体在副窗口做一个文件的“缩略图”,对浏览很有帮助。以前在网上见过图片但是找不到了。

Vim 没法做这个功能,所以对大的文件,只能提取文件内的结构形成一个目录。还不知道哪个插件有这个功能。ctags 只是提取定义,没有地图的功用。我很需要这个功能,一直想写一个关于 python 的但没时间。

--
http://bluegene8210.is-programmer.com/

Jacky Liu

unread,
Aug 22, 2011, 7:18:12 PM8/22/11
to vim...@googlegroups.com
我的设置:

set scrolloff=999

这样光标一直保持在中间,感觉好一些。

我觉得文件或者函数长一点有时没法避免,这个不应该是问题,只要有合适的辅助工具,比如提取文件结构形成目录,显示在副窗口里,里面用语法标出当前编辑的位置(比默认的 xx% 直观得多),再用自动命令关联到源码的编辑操作上,随着操作自动重新提取并刷新,再加上一些快捷键跳转功能,用起来一定很方便。在源码窗口里,用 :help sign 特性来记录之前的编辑位置也不错。限制文件或函数长度的做法太 weak 了,Vim 这么强一定能处理这些小 case 的。另外注释也很重要。

--
http://bluegene8210.is-programmer.com/

Jacky Liu

unread,
Aug 22, 2011, 7:34:46 PM8/22/11
to vim...@googlegroups.com
想浏览“平滑”一点也是有办法的:

nnoremap    ^F    jzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzzjzz
nnoremap    ^B   kzzkzzkzzkzzkzzkzzkzzkzzkzzkzzkzzkzz

后面跟多少个自己控制,缺点是对于不同类型的文件,速度的体验不同。如果太慢可以:

nnoremap    ^F    2jzz2jzz2jzz2jzz2jzz2jzz2jzz2jzz2jzz2jzz

或者:

nnoremap    ^F    3jzz3jzz3jzz3jzz3jzz3jzz3jzz

依此类推。但是辅助浏览的插件仍然是王道。Vim 这么强,这些应该是小 case 才对。



--
http://bluegene8210.is-programmer.com/

依云

unread,
Aug 22, 2011, 9:21:30 PM8/22/11
to vim...@googlegroups.com
On Tue, Aug 23, 2011 at 06:56:45AM +0800, Jacky Liu wrote:
> Emacs 能在不同窗口使用不同大小的字体,所以可以用很小的字体在副窗口做一个文件的“缩略图”,对浏览很有帮助。以前在网上见过图片但是找不到了。
>
> Vim 没法做这个功能,所以对大的文件,只能提取文件内的结构形成一个目录。还不知道哪个插件有这个功能。ctags
> 只是提取定义,没有地图的功用。我很需要这个功能,一直想写一个关于 python 的但没时间。

你可以写个 IDE 来生成代码缩略图什么的,只有编辑区使用 Vim。

tocer

unread,
Aug 22, 2011, 10:46:46 PM8/22/11
to vim...@googlegroups.com
在 2011年8月23日 上午6:56,Jacky Liu <bluege...@gmail.com> 写道:
> Emacs 能在不同窗口使用不同大小的字体,所以可以用很小的字体在副窗口做一个文件的“缩略图”,对浏览很有帮助。以前在网上见过图片但是找不到了。
>
> Vim 没法做这个功能,所以对大的文件,只能提取文件内的结构形成一个目录。还不知道哪个插件有这个功能。ctags
> 只是提取定义,没有地图的功用。我很需要这个功能,一直想写一个关于 python 的但没时间。

看看 tabbar 和 voom 插件,是否符合你的要求

Jacky Liu

unread,
Aug 22, 2011, 10:56:37 PM8/22/11
to vim...@googlegroups.com


2011/8/23 依云 <lily...@gmail.com>

On Tue, Aug 23, 2011 at 06:56:45AM +0800, Jacky Liu wrote:
> Emacs 能在不同窗口使用不同大小的字体,所以可以用很小的字体在副窗口做一个文件的“缩略图”,对浏览很有帮助。以前在网上见过图片但是找不到了。
>
> Vim 没法做这个功能,所以对大的文件,只能提取文件内的结构形成一个目录。还不知道哪个插件有这个功能。ctags
> 只是提取定义,没有地图的功用。我很需要这个功能,一直想写一个关于 python 的但没时间。

你可以写个 IDE 来生成代码缩略图什么的,只有编辑区使用 Vim。


其实我喜欢提取目录的方式,比缩略图好。我说“地图”是打个比方,只要目录里的位置跟源文件的位置有对应就行。缩略图对于辨别代码段的上下文环境其实用处不大,顶多起到提示作用。我需要目录的功能,因为遇到一个文件里有几处代码比较类似而分不清楚是很危险的事。有时间一定写出来。

另外上面那个 mapping 其实不顶用,有点想当然。这里订正一下:

nnoremap ^F    :call <SID>NmodeMapping('C-f')<CR>
nnoremap ^B    :call <SID>NmodeMapping('C-b')<CR>

function! s:NmodeMapping(inputkey)
    if a:inputkey == 'C-f'
        for i in range(8)
            normal 3kzz
            "    sleep 10m
            redraw!
        endfor
    else
        for i in range(8)
            normal 3izz
            "    sleep 10m
            redraw!
        endfor
    endif
endfunction

里面参数可以调。这个能实现“平滑”的效果,但是看起来不怎么样。终端版的 Vim 应该好些。

--
http://bluegene8210.is-programmer.com/

Jacky Liu

unread,
Aug 22, 2011, 11:00:48 PM8/22/11
to vim...@googlegroups.com

看看 tabbar 和 voom 插件,是否符合你的要求



OK 我看看,多谢。


--
http://bluegene8210.is-programmer.com/

Jacky Liu

unread,
Aug 22, 2011, 11:22:52 PM8/22/11
to vim...@googlegroups.com

看看 tabbar 和 voom 插件,是否符合你的要求


对,就是 voom 那样的功能。voom 是用来提取文本标题的,我想提取的 python 源码里的定义,以及自定义的注释格式。或许可以把多种文件类型综合到一个插件里,包括 txt,py,以及 c。回头真要写的话参考一下,thanks!



--
http://bluegene8210.is-programmer.com/

ZhUgEr

unread,
Aug 23, 2011, 8:10:20 AM8/23/11
to vim...@googlegroups.com
本来php写出来的代码就逃不了dirty了,不过搞到康盛这样也算是奇葩了……

闲耘(tm)

unread,
Aug 23, 2011, 9:37:17 AM8/23/11
to vim...@googlegroups.com
<C-f> , <C-b>
<C-u> , <C-d>
<C-e> , <C-y>
ctags+taglist
mark
%
/, * , # , n , N

--
闲耘™ (@hotoo, hotoo.me)


Jacky Liu

unread,
Aug 23, 2011, 12:48:08 PM8/23/11
to vim...@googlegroups.com

但是接手别人的项目的时候,用vim打开别人的项目,感觉到眼前一片黑,读别人的代码的时候,有时候一屏看完了最好的体验是用鼠标逐行下来,下面的代码
慢慢浮现出来,跟上面的代码浑然一体,就像浏览网页,文字逐行滚动,甚至平滑滚动。

用vim逐行滚屏我也找到了一个办法shift+l,然后j

另:mac下编辑器能像网页一样平滑滚屏,mac的用户体验确实不是盖的


以上这些 gvim 应该都可以。所以不用那么麻烦,试试 gvim 就好了。



--
http://bluegene8210.is-programmer.com/

bill

unread,
Aug 27, 2011, 1:29:24 AM8/27/11
to vim...@googlegroups.com
����ܾ���ǰ�����ֳɵIJ����
http://www.vim.org/scripts/script.php?script_id=1601

�� 2011/8/23 10:56, Jacky Liu �:
>
>
> 2011/8/23 ���� <lily...@gmail.com <mailto:lily...@gmail.com>>


>
> On Tue, Aug 23, 2011 at 06:56:45AM +0800, Jacky Liu wrote:

> > Emacs ���ڲ�ͬ����ʹ�ò�ͬ��С�����壬���Կ����ú�С�������ڸ���
> ����һ���ļ��ġ�����ͼ������������а�����ǰ�����ϼ��ͼƬ�����Ҳ����ˡ�
> >
> > Vim û����������ܣ����ԶԴ���ļ���ֻ����ȡ�ļ��ڵĽṹ�γ�һ��
> Ŀ¼������֪���ĸ������������ܡ�ctags
> > ֻ����ȡ���壬û�е�ͼ�Ĺ��á��Һ���Ҫ������ܣ�һֱ��дһ������
> python �ĵ�ûʱ�䡣
>
> �����д�� IDE ����ɴ�������ͼʲô�ģ�ֻ�б༭��ʹ�� Vim��
>
>
> ��ʵ��ϲ����ȡĿ¼�ķ�ʽ��������ͼ�á���˵����ͼ���Ǵ���ȷ���ֻҪĿ¼���
> λ�ø�Դ�ļ���λ���ж�Ӧ���С�����ͼ���ڱ�����ε������Ļ�����ʵ�ô���
> �󣬶�������ʾ���á�����ҪĿ¼�Ĺ��ܣ���Ϊ����һ���ļ����м�������Ƚ�
> ���ƶ�ֲ�����Ǻ�Σ�յ��¡���ʱ��һ��д������
>
> ���������Ǹ� mapping ��ʵ�����ã��е��뵱Ȼ�����ﶩ��һ�£�


>
> nnoremap ^F :call <SID>NmodeMapping('C-f')<CR>
> nnoremap ^B :call <SID>NmodeMapping('C-b')<CR>
>
> function! s:NmodeMapping(inputkey)
> if a:inputkey == 'C-f'
> for i in range(8)
> normal 3kzz
> " sleep 10m
> redraw!
> endfor
> else
> for i in range(8)
> normal 3izz
> " sleep 10m
> redraw!
> endfor
> endif
> endfunction
>

> ���������Ե��������ʵ�֡�ƽ������Ч���ǿ���������ô���ն˰�� Vim
> Ӧ�ú�Щ��
>
> --
> http://bluegene8210.is-programmer.com/
>
> --
> Ҫ�˶�����̳���뷢�ʼ��� Vim-cn-un...@googlegroups.com
> ���ѡ���ͨ�� http://groups.google.com/group/Vim-cn ���ʸ���̳

Jacky Liu

unread,
Aug 27, 2011, 5:09:37 AM8/27/11
to vim...@googlegroups.com


2011/8/27 bill <bil...@gmail.com>
这个很久以前就有现成的插件了
http://www.vim.org/scripts/script.php?script_id=1601


看了。思路一样,所以 linux + gvim 下面效果应该一样不好,闪得厉害。console vim 或者 Windows 下应该效果不错。

可能是公开发布的最短的 vim 插件。

--
http://bluegene8210.is-programmer.com/

mbbill

unread,
Aug 27, 2011, 6:04:51 AM8/27/11
to vim...@googlegroups.com
���radraw�����! ȥ������

�� 2011/8/27 17:09, Jacky Liu �:
>
>
> 2011/8/27 bill <bil...@gmail.com <mailto:bil...@gmail.com>>
>
> ����ܾ���ǰ�����ֳɵIJ����
> http://www.vim.org/scripts/script.php?script_id=1601
>
>
> ���ˡ�˼·һ������ linux + gvim ����Ч��Ӧ��һ��ã�����������
> console vim ���� Windows ��Ӧ��Ч��?
>
> �����ǹ�����������̵� vim �����

Jacky Liu

unread,
Aug 27, 2011, 6:40:15 AM8/27/11
to vim...@googlegroups.com


2011/8/27 mbbill <bil...@gmail.com>
你把radraw后面的! 去掉试试


闪是因为 GUI 实现的关系,在 VimScript 这个层级是解决不了的。想不闪可能得到 vim 源码里把 C-f , C-b 的实现改掉。

在 gvim 里用鼠标拖分隔栏的速度很快,所以不是 gnome/kde 的问题,但是 Windows 的 GUI 确实比 gnome/kde 好,速度快而且不出错,用过 linux gvim 跟 windows gvim 的人应该有体会。



--
http://bluegene8210.is-programmer.com/

mbbill

unread,
Aug 27, 2011, 7:29:49 AM8/27/11
to vim...@googlegroups.com
���Թ�ô��
���Ƕνű�������������������Ǹ��������������Ҫ�������Ǹ�̾�ţ���
gnome����x������û̫���ϵ��
Linux��win��ƽʱ���߶��ã��󲿷�ʱ����Linux���棬���Dz�û�о���GUIЧ�ʲ�
��win��

�� 2011/8/27 18:40, Jacky Liu �:
>
>
> 2011/8/27 mbbill <bil...@gmail.com <mailto:bil...@gmail.com>>
>
> ���radraw�����! ȥ������
>
>
> ������Ϊ GUI ʵ�ֵĹ�ϵ���� VimScript ����㼶�ǽ�����˵ġ��벻�����ܵ�
> �� vim Դ����� C-f , C-b ��ʵ�ָĵ���
>
> �� gvim ��������Ϸָ������ٶȺܿ죬���Բ��� gnome/kde �����⣬����
> Windows �� GUI ȷʵ�� gnome/kde �ã��ٶȿ���Ҳ����?�ù� linux gvim ��
> windows gvim ����Ӧ������ᡣ

Jacky Liu

unread,
Aug 27, 2011, 8:19:29 AM8/27/11
to vim...@googlegroups.com


2011/8/27 mbbill <bil...@gmail.com>
你试过么?
你那段脚本闪得厉害,而我贴的那个插件不会闪。主要区别就是那个叹号,和
gnome或者x的性能没太大关系。
Linux和win我平时两者都用,大部分时间在Linux桌面,但是并没有觉得GUI效率不
如win。


很对!加个叹号会多一步,看来关系很大,我又想当然了。效果狠好。

gvim 在 win 跟 linux 下的区别还是有的,在 syntax highlighting 任务比较重的时候能感觉出来。那个插件如果你把中间智能延时的处理去掉(while 1 那一段)然后编辑一个很长很复杂的 .vim 文件(开启 syntax),滚动的时候就能感觉到速度有区别。

另外不同程序间切换的时候 linux gvim 的显示时常扰乱(也是当前窗口的 syntax 任务重的时候),需要 <Ctrl-l> 刷新,win 下面从未遇到过。



--
http://bluegene8210.is-programmer.com/

distortion.png

依云

unread,
Aug 27, 2011, 8:28:20 AM8/27/11
to vim...@googlegroups.com

这个貌似是一个已解决的 bug。

Jacky Liu

unread,
Aug 27, 2011, 8:37:38 AM8/27/11
to vim...@googlegroups.com


这个貌似是一个已解决的 bug。


我想有可能是 bug,因为其它的 GUI 程序不会这样扰乱。但是我的 gvim 是上次从你那拿到的 7.3.161 版,应该已经比较新了呀



--
http://bluegene8210.is-programmer.com/

依云

unread,
Aug 28, 2011, 7:26:23 AM8/28/11
to vim...@googlegroups.com
On Sat, Aug 27, 2011 at 08:37:38PM +0800, Jacky Liu wrote:
> >
> > 这个貌似是一个已解决的 bug。
> >
> >
> 我想有可能是 bug,因为其它的 GUI 程序不会这样扰乱。但是我的 gvim 是上次从你那拿到的 7.3.161 版,应该已经比较新了呀
>

已经很旧了。我现在用的是 7.3.280,而且不是最新的。

蓝色基因

unread,
Aug 29, 2011, 5:52:12 AM8/29/11
to Vim.cn

> 已经很旧了。我现在用的是 7.3.280,而且不是最新的。
>
> --
> Best regards,
> lilydjwg
>
> Linux Vim Python 我的博客http://lilydjwg.is-programmer.com/

我搜了一下,没有头绪。记得很早之前就有这状况。你还记得这个 bug 是哪一个吗?161 版到现在时间刚好 4 个月,如果不是这四个月内
fix 的,那应该就不是了吧

Fermat 618

unread,
Mar 12, 2012, 11:19:36 AM3/12/12
to vim...@googlegroups.com

你要觉得那效果好,自己再把vim的gui实现一个那种效果也不错呢。

这个问题不光在vim上,整个电脑上都差不多。我就喜欢看书,而不喜欢看电脑上的东西,原因就是电脑上看的东西很难相互连系起来,印象不深,不如看书舒服。

现在在快速看的时候就翻页,慢速看的时候就用鼠标慢慢地滚。翻半屏最难受了,很难一下接到原先看的位置。
On Monday, August 22, 2011 12:04:29 AM UTC+8, Gandalf wrote:
用vim自己从头开始写项目比较好,具体到每一个文件每一行代码,都是自己码字出来的,自己都摸的一清二楚,整个项目的所有文件每一行代码都在自己的脑
海形成蓝图了,这样用vim的时候指哪打哪。

但是接手别人的项目的时候,用vim打开别人的项目,感觉到眼前一片黑,读别人的代码的时候,有时候一屏看完了最好的体验是用鼠标逐行下来,下面的代码
慢慢浮现出来,跟上面的代码浑然一体,就像浏览网页,文字逐行滚动,甚至平滑滚动。

而用vim浏览别人的代码,用ctrl+f一次滚一屏,或者用ctrl+d一次滚半屏,这样读陌生的代码很吃力,猛的一下整个屏幕的代码都变了,跟上页
的缩进在脑海中形成的蓝图一下子全乱了。比如看一个函数,函数的上半部在一个屏幕,函数的下半部在另一个屏幕,这样用vim一屏一屏的向下翻很难在脑海
中整体把握这个函数的结构

当然了,会有高手说“你的理解代码能力的问题不要归罪到vim”,当然细细品读代码用vim也可以,但不如用滚动条逐行滚屏或平滑滚屏更省精力,这样可
以节省下来精力做其他事情。

Reply all
Reply to author
Forward
0 new messages