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

前端之家收集整理的这篇文章主要介绍了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.
原文链接:https://www.f2er.com/bash/386045.html

猜你在找的Bash相关文章