Adding and subtracting
*CTRL-A*
CTRL-A Add [count] to the number or alphabetic character at
or after the cursor. {not in Vi}
*CTRL-X*
CTRL-X Subtract [count] from the number or alphabetic
character at or after the cursor. {not in Vi}
The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
octal and hexadecimal numbers and alphabetic characters. This depends on the
'nrformats' option.
- When 'nrformats' includes "alpha", Vim will change the alphabetic character
under or after the cursor. This is useful to make lists with an alphabetic
index.
- When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
'0X' are hexadecimal. The case of the rightmost letter in the number
determines the case of the resulting hexadecimal number. If there is no
letter in the current number, Vim uses the previously detected case.
- When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
to be octal. Other numbers are decimal and may have a preceding minus sign.
If the cursor is on a number, the commands apply to that number; otherwise
Vim uses the number to the right of the cursor.
For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible. CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff". Note that
when 'nrformats' includes "octal", decimal numbers with leading zeros are
impossible because they are indistinguishable from octal numbers.
The CTRL-A command is very useful in a macro. Example: Use the following
steps to make a numbered list.
1. Create the first list entry, make sure it starts with a number.
2. qa - start recording into buffer 'a'
3. Y - yank the entry
4. p - put a copy of the entry below the first one
5. CTRL-A - increment the number
6. q - stop recording
7.@a - repeat the yank, put and increment times
2008/12/18
VIM is so cool
VIM is really cool, you can increase/decrease a number in the text directly by with CTRL-A and CTRL-X!
订阅:
博文评论 (Atom)
BlockChain 相关电子书
@copyright of Sam Chadwick - https://thehub.thomsonreuters.com/groups/bitcoin/blog/2017/09/10/blockchain-paper Blockchain Papers A c...
-
兴趣是最好的老师, 世界上没有完美的系统,电子车票系统也是如此。 这个PDF里讲述了一个MIT的三位学生发现了波士顿地铁电子车票系统的漏洞的故事。 国内的这种研究的精神似乎少了一些! 我们的教育导向太死板了!
-
火车停了 话说列宁,斯大林,赫鲁晓夫,勃列日涅夫,戈尔巴乔夫五人同坐一列社会主义号火车前进, 突然火车停了,车长过来报告,前面铁路断了,列宁:"说发动一次星期六义务劳动把它修好",斯大林一瞪眼:"一定有阶级敌人搞破坏,抓起来枪毙",赫若有 ...
-
Apple (TM) iPhone (TM) 3G 版本 Zippy 2008年6月9日在旧金山发布。 看看这次 Steve Jobs 给我们带来了什么? 8G内存的版本价格为 $199 = ¥1400 : 3G UMTS, Wifi, Apple's design. ...
2 条评论:
vim often comes with surprise.
真是太酷了。
发表评论