微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Vim:如何恢复光标的逻辑和物理位置?

当我打开文件时如何恢复光标的“逻辑”和“物理”位置?

那是:

>光标应位于文件中的最后一行逻辑行.
>根据vim窗口,光标应位于最后的物理线上

我注意到了this post.它将光标放在正确的逻辑行上.但光标在窗口中的物理位置是第一行或中间.

更新:
解决方案是@sehe所指出的mkview和loadview.

为了使其与其他插件(在我的情况下,胶乳文件latex-box)一起工作,以下将是有用的:

au BufWinLeave * .tex mkview

au VimEnter * .tex loadview

从VimEnter的Vim文档:

>执行所有启动的东西,包括加载.vimrc文件,执行“-c cmd”参数,创建所有窗口并加载它们中的缓冲区.

UPDATE2:为了更好地启动“视图快照文件

通过创建一个文件夹〜/ .vim / view,你将保留所有的“view-snapshot-files”.

如果您正在使用git来跨计算机同步〜/ .vim,也许你想要

>忽略〜/ .vim / view中的文件,
>但保留您的回购中的空文件夹.

那么你需要(根据答案here添加)

>创建一个文件:〜/ .vim / view / .gitignore
>把view / *和!.gitignore放在〜/ .vim / .gitignore中

好消息:mkview已经有了(参见下面的文档摘录).

最具体地说:如果viewoptions包括光标,折叠,则loadview将恢复滚动位置以及折叠状态.

更好的消息是,如果您愿意,您可以透明地启用所有打开的文件的视图.例如.为了启用所有C源文件的视图保存,将其添加到$MYVIMRC:

au BufWinLeave *.c mkview
au BufWinEnter *.c silent loadview

编辑根据Hongying的意见,结合某些插件,如果您使用VimEnter auto命令加载视图,则可能会更好.

(可选)使用viewdir选项来定义已保存视图的位置.

确保同时查看:mksession,因为它更强大,因为它可以恢复多个窗口,制表符及其位置,映射,注册,选项,折叠状态等.

怎么运行的

Vim:mkview保存ex命令恢复位置,如下所示:

silent! normal! zE
let s:l = 88 - ((4 * winheight(0) + 4) / 9)
if s:l < 1 | let s:l = 1 | endif
exe s:l
normal! zt
88
normal! 025l

:loadview只是来源那些命令,像任何vimscript.

从文档

注意这是从文档剪辑,确保阅读更多做他:mkview

*:mkvie* *:mkview*
:mkvie[w][!] [file] Write a Vim script that restores the contents of the
            current window.
            When [!] is included an existing file is overwritten.
            When [file] is omitted or is a number from 1 to 9,a
            name is generated and 'viewdir' prepended.  When the
            last directory name in 'viewdir' does not exist,this
            directory is created.
            An existing file is always overwritten then.  Use
            |:loadview| to load this view again.
            When [file] is the name of a file ('viewdir' is not
            used),a command to edit the file is added to the
            generated file.

The output of ":mkview" contains these items:
1. The argument list used in the window.  When the global argument list is
   used it is reset to the global list.
   The index in the argument list is also restored.
2. The file being edited in the window.  If there is no file,the window is
   made empty.
3. Restore mappings,abbreviations and options local to the window if
   'viewoptions' contains "options" or "localoptions".  For the options it
   restores only values that are local to the current buffer and values local
   to the window.
   When storing the view as part of a session and "options" is in
   'sessionoptions',global values for local options will be stored too.
4. Restore folds when using manual folding and 'viewoptions' contains
   "folds".  Restore manually opened and closed folds.
5. The scroll position and the cursor position in the file.  Doesn't work very
   well when there are closed folds.
6. The local current directory,if it is different from the global current
   directory.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


解决方案:解决linux下vim乱码的情况:(修改vimrc的内容)全局的情况下:即所有用户都能用这个配置文件地址:/etc/vimrc在文件中添加:setfileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936settermencoding=utf-8setencoding=utf-8如果只修改个人的vim配置情况:需要把/etc/
Linuxvi/vim所有的UnixLike系统都会内建vi文书编辑器,其他的文书编辑器则不一定会存在。但是目前我们使用比较多的是vim编辑器。vim具有程序编辑的能力,可以主动的以字体颜色辨别语法的正确性,方便程序设计。相关文章:史上最全Vim快捷键键位图—入门到进阶什么是vim
      vim正则匹配:空行:/^$/  /^[\t]*$/注释行:/^#/ /^[\t]*#/:1,$s/\([Rr]\)oot/\1ename/:1,$s/\(square\)and\(fair\)/\2and\1/ 
$select-editorSelectaneditor.Tochangelater,run'select-editor'.1./bin/ed2./binano<----easiest3./usr/bin/code4./usr/bin/vim.basic5./usr/bin/vim.tinyChoose1-5[2]:4
上次手贱忘了保存,这次就简单做个备忘吧,把踩过的坑记一下预览图安装工具:u盘、manjarokdeminimal20.0.3、win32DiskImager提取码:qt9f进bios、选择u盘启动、改语言、改时区、挂载分区(文件系统ext4、在200M左右的一个FAT分区上挂载/boot/efi)、安装安装很简单,按提示
Linux之文本编译器小结vim的优势所有的UNIX-LIKE习通都会内置vi文本编译器,其他的文本编译器则不一定存在很多软件的编译接口都会主动调用vivim有很强的程序编译能力,可以主动的一字体颜色辨别语法的正确性,方便程序设计因为程序简单,编译速度相当快vi的使用一般命令模
主机名字太长,怎么修改?  1.sudovim/etc/hostname 修改内容为wel,  本地主机名 2.sudovim/etc/hosts      修改主机名为wel,用于网络连接中主机名的识别 3.reboot 
目录#事故现场#事故原因#解决方法方法一:使用notepad转换方法二:使用vscode转换方法三:使用vim转换#参考#事故现场执行shell脚本文件,报错::notfound.sh:6:coreinstall.sh:查看脚本文件第6行,发现是空行;#事故原因window下的换行是回车符+换行符,也就是\r\n,而unix下是换行符\n
1、保存并退出linux下安装好了vim以及gcc后,我们开始新建一个c文件,例如:vimtest.c之后进入vim的编辑框中,点击i进入插入模式,开始编辑程序,当你编写好自己的程序之后,按Esc退出插入编辑状态,然后输入冒号加wq,点击Enter即可,完整的命令如下:wq如下图:  退出后,如果想要编译
概述使用VIM作简单字数统计背景想做一个简单的字数统计环境OSwin10shellmintty-2.9.41.需求概述需求需求统计文段内字符的数量支持自定义字符集2.方案1:vim自带统计概述vim自带方案操作定位到文段内某行vi