[实践OK]vi行移动:vim上下移动一行或一段代码,vim回到最近修改位置的vim快捷键,回到倒数第二次修改的位置,vim一下知道所在行的函数名设置方法。在文件中快速查找光标处一样的单词。

jackxiang 2012-4-10 13:35 | |
[vim]移动一行或一段代码 ,[Alt]+[j] 或[Alt]+[k] 可控制代码向上、向下移:


把上面代码放到vim的配置文件_vimrc: vi /root/.vimrc.

下面这段代码实现的效果是(secureCRT确实有问题):
在普通模式 或可视模式下选择一段代码,同时按[Alt]+[j] 或[Alt]+[k] 可控制代码向上、向下移。

注,下面这段代码是来自网络。。。,没实践。
有兄弟留言说Alt键有问题,用secureCRT确实有问题,后修改为Control+j,Control+k可控制代码向上、向下移:



在文件中快速查找光标处一样的单词:
把光标挪动到要在打开的文本里查找的单词上,后按:shift + 3,也就是#号即可。



—————————————vim一下知道所在行的函数名设置方法—————————————————————
在 .vimrc里添加:


按一下 f 键就能显示函数名字。

来自:http://blog.csdn.net/caspiansea/article/details/42570311


——————————————————————————————————————————————————————
键表 |key-notation|
<k0> - <k9> 小键盘 0 到 9 *keypad-0* *keypad-9*
<S-...> Shift+键 *shift* *<S-*
<C-...> Control+键 *control* *ctrl* *<C-*
<M-...> Alt+键 或 meta+键 *meta* *alt* *<M-*
<A-...> 同 <m-...> *<A-*
<t_xx> termcap 里的 "xx" 入口键


参考:
http://blog.csdn.net/riag/article/details/3469464
http://hi.baidu.com/drmingdrmer/item/5b9f5e354efbcbb8633aff0c

[实践OK]Vi注释多行的方法,附带整个代码缩进:
http://jackxiang.com/post/4298/
————————————————————————————————————————————————————————
有兄弟回复说没有用alt,在SecureCRT下这个alt好像确实是不能用的跑到文件(F)去了,不光是这个alt,还有ctrl:
http://blog.csdn.net/maojudong/article/details/6324757
SecureCRT突然假死的问题(Ctrl+S)
SecureCRT作为著名的SSH客户端,经常用于登陆远程服务器。在上面编辑文本,特别是用vi打开两个文本,并且需要切换时,很容易出现卡死的现象,不能接受任何的键盘输入。很是郁闷。以前每次遇到这个问题,我只有关掉那个session重新打开一个。这次又遇上,是在不能忍,试着解决一下。

仔细观察会发现,在vi下切换文本“ctrl+w+w”时,很容易输入成”ctrl+s”。随便拿一个session试试就发现,果然是ctrl+s在作怪。只要输入这个,就会卡死。搜索了一下,发现果然是有原因的:
CTRL-S and CTRL-Q are called flow-control characters. They represent an antiquated way of stopping and restarting the flow of output from one device to another (e.g., from the computer to your terminal) that was useful when the speed of such output was low. They are rather obsolete in these days of high-speed networks. In fact, under the latter conditions, CTRL-S and CTRL-Q are basically a nuisance. The only thing you really need to know about them is that if your screen output becomes “stuck,” then you may have hit CTRL-S by accident. Type CTRL-Q to restart the output; any keys you may have hit in between will then take effect.

CTRL-S and CTRL-Q are called flow-control characters. They represent an antiquated way of stopping and restarting the flow of output from one device to another (e.g., from the computer to your terminal) that was useful when the speed of such output was low. They are rather obsolete in these days of high-speed networks. In fact, under the latter conditions, CTRL-S and CTRL-Q are basically a nuisance. The only thing you really need to know about them is that if your screen output becomes “stuck,” then you may have hit CTRL-S by accident. Type CTRL-Q to restart the output; any keys you may have hit in between will then take effect.ctrl+s是一个古老的shell控制键,在输入ctrl+q就可以恢复了

【转自 http://xok.la/2009/09/securecrt_ctrl_s.html】

被这个问题困扰好几次了,CTRL+S,CTRL+Q,很好,以后就不需要重新开一个了。
————————————————————————————————————————————————————————
<转载>vim map nmap:
http://www.cnblogs.com/lq0729/archive/2011/12/24/2300189.html



1)回到最近修改的位置:
还有 %(跳转到与之匹配的括号处),`.(跳转到最近修改过的位置并定位编辑点),'.(跳转到最近修改过的位置但不定位编辑点)这三个命令也非常重要,在 Vi/Vim 中灵活使用会极大提高效率。% 除用于光标移动之后,还可用于检测源码中各种括号的匹配情况。
实践:tab键上面那个`加一个点,的确能跳转到最近修改的位置~ 再就是双引号这个键的单引号按一下,' 再点按点这个键盘,一样的效果感觉,但的确是相当好使,因为你在编码时还会在修改的同时会看其它部分的代码,但怎么快速回到最后修改的位置呢?该命令就很好使用。
摘自:http://www.ibm.com/developerworks/cn/linux/l-cn-tip-vim/

2)回到倒数第二次修改的位置:
Esc下面这个按键,连续按两次,就回到倒数第二次修改的位置。
————————————————————————————————————————————————————————
应用场景:  
在每次退出一份文件后再重新打开该文件时,希望光标停留在当时退出的地方;也就是说当我程序写到hello.c的第100列时突然有事必须关电脑了,那在我下次打开电脑以vim打开hello.c, 希望光标还是停留在第100列,怎么办?


解决方案就是在.vimrc里面加上这一行即可:
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif  

链接:http://blog.longwin.com.tw/2012/09/vim-last-read-line-2012/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+tsungblog+(Tsung%27s+Blog)



作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/5113/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!


最后编辑: jackxiang 编辑于2019-12-10 00:00
评论列表
2014-1-29 23:10 | Ph智 Email
亲测可行,不过我改成C-S-j/k,估计是linux下的alt被占用。
分页: 1/1 第一页 1 最后页
发表评论

昵称

网址

电邮

打开HTML 打开UBB 打开表情 隐藏 记住我 [登入] [注册]