1

我正在使用vim来管理一个程序会使用的数据文件,数据文件的格式如下:

<Header line 1>
<Header line 2>
<Header line 3>
<Data line 1>
<Data line 2>
...
<Data line N>

使用这种我无法更改的格式,数据值直到文件中的第 4 行才开始。但是,程序的输出是按数字引用数据值,这使得很难快速搜索文件以找到正确的行。我尝试了 vim 7.3+ 的:set relativenumber( :set rnu) 选项,但它旨在不断更新用于计算相对行号的基线。

我想知道是否有办法在第 3 行修复基线,以便第 4、5 和 6 行将显示为第 1、2 和 3 行(与程序输出一致)。任何帮助,将不胜感激!

更新:我最终做的是在源代码中手动添加这个选项。只需要很少的改动;我所做的只是将所有代码复制:set relativenumber到一个名为的新选项:set fixednumber中,然后禁用在行更改时自动更新行号的部分(此部分在 vim 源文件 move.c 中)。现在有三种互斥模式:

:set number -- normal line numbers  
:set relativenumber -- automatically updating relative numbers  
:set fixednumber -- relative line numbers that are fixed against the currently selected row when the option was set
4

2 回答 2

2

No. The 0 in relativenumber is always the line on which your cursor is and the 1 in number is always line 1 of the buffer/file.

You could, however, open a new window with only the lines 4 -> N and work there.

Or add a +3 to each "jump to line n"…

With this mapping:

nnoremap <F9> :3+

you'd just need to hit <F9>, type the line number and hit <Enter>.

于 2012-11-02T20:42:49.107 回答
0

Vim 旨在按原样编辑文本文件,因此需要进行一些变形才能满足您的需求。

G您可以在数据文件的缓冲区中重新定义命令,如下所示:

:nnoremap <buffer> G :<C-u>execute (v:count ? v:count + 3 : line('$'))<CR>

但是,数字列仍将关闭。要纠正这个问题,您必须在加载缓冲区时删除三个初始标题行(可能将它们存储在缓冲区局部变量中),并在保存缓冲区之前短暂地重新插入它们。这可以通过 autocmds 来实现,但要做到正确有点棘手。

另一种选择是使用像NarrowRegion这样的插件,它在暂存缓冲区中打开选定的范围,并在保存时同步内容。

于 2012-11-02T20:46:18.283 回答