Получите смещение текущего буфера в энергии (в частности, с помощью сценариев Python)

Я узнал много о Python путем чтения источника стандартной библиотеки, которая поставлется с Python. Я, кажется, не забываю иметь некоторых "a-ha!" моменты при чтении urllib2.py в частности.

13
задан Jörg Haubrichs 27 September 2009 в 15:36
поделиться

2 ответа

If your vim is compiled with the +byte_offset option, then in a Python script after the usual import vim, you can use, e.g.:

vim.eval('line2byte(line("."))+col(".")')

to get the byte offset from start of file of the cursor position, and similarly for other marks. More generally, if you have a line/column pair this (assuming +byte_offset is how your vim was compiled with) is the way to get a byte offset (there's also a byte2line function to go the other way).

While the vim module does make a lot of functionality available directly to Python scripts in vim, I've found that vim.eval and vim.command are often the handiest (and sometimes the only;-) way to get in just as deep as needed;-). Oh, and I always try to have a vim compiled with +justabouteverything whenever I can;-).

14
ответ дан 1 December 2019 в 21:25
поделиться

You may also want to look at the statusline setting. This will add the bye offset to the statusline:

set statusline+=%o

See :h statusline

Just be careful because the default statusline is blank, and by appending the %o to it, you loose all the defaults.

12
ответ дан 1 December 2019 в 21:25
поделиться
Другие вопросы по тегам:

Похожие вопросы: