Is there a way to increment %z
hex numbers with VIM? Typically I can do this by just doing ctrl + a
for normal numbers. But unfortunately I am using a old school system that uses %z
rather than 0x
to denote hexadecimal numbers. I've tried
Set nf=hex
But that sadly only works for 0x
hex numbers. Anyone come across this before? I haven't found much on the google machine.
答案 0 :(得分:1)
我不知道这个%z
前缀;但我尝试了一个快速而又脏的函数,增加了像%z0f这样的数字;这是你想要的吗?然后你应该能够添加一个映射(但不是它本身,因为它在函数中使用!),如:map <C-p> :call MyIncrement()<CR>
当然你应该根据你的需要定制它;第17行在进行后重置光标的位置;您可能希望将l:c
替换为l:b
(或者甚至是l:a
)并选择您最喜欢的内容。
function! MyIncrement()
let l:l = line(".")
let l:c = col(".")
let l:a = 0
let l:b = 0
let l:s = search('%z[0-9a-f]\+', 'bcW',l:l)
if l:s == l:l
let l:a = col(".")
let l:s = search('%z[0-9a-f]\+', 'ecW',l:l)
let l:b = col(".")
if ((l:a<=l:c)&&(l:c<=l:b))
call cursor(l:l, l:a+2)
silent exe "normal i 0x\e\<C-a>"
call cursor(l:l, l:a+2)
silent exe "normal 3x"
call cursor(l:l, l:c)
endif
endif
endfunction
答案 1 :(得分:1)
使用@oobivat评论:
:map \a Fza0x<ESC><C-a>Fzlxx
现在,\a
- (请选择更好的密钥)将:
z
(Fz
)0x
(a0x<ESC>
)<C-a>
)0x
(Fzlxx
)