免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1296 | 回复: 2

[学习共享] vim 小知识 [复制链接]

论坛徽章:
0
发表于 2017-02-02 11:57 |显示全部楼层
本帖最后由 wyc198801wyc 于 2017-02-02 12:01 编辑

在vim网站上看到了个有意思的用法跟大家分享一下,共同学习。

      Sessions 用法

Suppose you are editing along, and it is the end of the day.  You want to quitwork and pick up where you left off the next day.  You can do this by savingyour editing session and restoring it the next day.   A Vim session contains all the information about what you are editing.This includes things such as the file list, window layout, global variables,options and other information.  (Exactly what is remembered is controlled bythe 'sessionoptions' option, described below.)   The following command creates a session file:
:mksession vimbook.vim

Later if you want to restore this session, you can use this command:

:source vimbook.vim

If you want to start Vim and restore a specific session, you can use thefollowing command:

vim -S vimbook.vim

This tells Vim to read a specific file on startup.  The 'S' stands forsession (actually, you can source any Vim script with -S, thus it might aswell stand for "source").The windows that were open are restored, with the same position and size asbefore.  Mappings and option values are like before.   What exactly is restored depends on the 'sessionoptions' option.  The default value is "blank,buffers,curdir,folds,help,options,winsize".  

      blank                   keep empty windows     
      buffers                 all buffers, not only the ones in a window      
      curdir                   the current directory   
      folds                    folds, also manually created ones   
      help                     the help window      
      options                 all options and mappings      
      winsize                 window sizesChange this to your liking.  

To also restore the size of the Vim window, forexample, use:

  :set sessionoptions+=resize

SESSION HERE, SESSION THEREThe obvious way to use sessions is when working on different projects.Suppose you store you session files in the directory "~/.vim".  You arecurrently working on the "secret" project and have to switch to the "boring"project:

   :wall
   :mksession! ~/.vim/secret.vim
   :source ~/.vim/boring.vim

This first uses ":wall" to write all modified files.  Then the current sessionis saved, using ":mksession!".  This overwrites the previous session.  Thenext time you load the secret session you can continue where you were at thispoint.  And finally you load the new "boring" session.If you open help windows, split and close various window, and generally messup the window layout, you can go back to the last saved session:

   :source ~/.vim/boring.vim

论坛徽章:
0
发表于 2017-02-02 23:56 |显示全部楼层
本帖最后由 wyc198801wyc 于 2017-02-03 00:07 编辑

vim -x secret_file          为文件加密码

g CTRL-G                 显示光标在第几byte等信息
200go                      到第200byte

`"                           光标移到上次退出的地方
`.                           光标移到上次改变的地方

论坛徽章:
6
程序设计版块每日发帖之星
日期:2015-12-05 06:20:00数据库技术版块每日发帖之星
日期:2016-02-06 06:20:00数据库技术版块每日发帖之星
日期:2016-03-07 06:20:00程序设计版块每日发帖之星
日期:2016-06-04 06:20:00黑曼巴
日期:2017-02-06 16:31:2615-16赛季CBA联赛之广夏
日期:2017-05-07 09:02:07
发表于 2017-02-06 16:13 |显示全部楼层
谢谢分享 man vim
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP