4 ms·
These are excellent. I didn't know about gi, and that's very useful. Today I accidentally learned that ctrl-a and ctrl-x increment or decrement the number und
by blunte 8y ago
These are excellent. I didn't know about gi, and that's very useful.
Today I accidentally learned that ctrl-a and ctrl-x increment or decrement the number under the cursor. That's not terribly useful unless you're dealing with a lot of numbers, but if you are, it will save a lot of keystrokes.
One set of movement keys the article didn't mention but which I use all the time are H M and L (shift-h, etc.) They jump to top (high), middle, and bottom (low) of the editor window, respectively.
- h43z 8y agoEven better you don't have to be with the cursor on the number you want to increment or decrement with Ctrl-A and Ctrl-X. It will work with the next number to the right of the cursor. The same goes for ci' or ci". a = 'foo' // imagine the cursor on the letter a Executing ci'bar will change foo to bar.
- blunte 8y agoWow! Thank you.
- yjftsjthsd-h 8y ago> Even better you don't have to be with the cursor on the number you want to increment or decrement with Ctrl-A and Ctrl-X. It will work with the next number to the right of the cursor. To the point that I have used c-x c-a as a stupid shortcut to jump to the next number on a line. I'm sure there's a better way to do this, but it's fast so...
- edanm 8y agoSurprisingly, there actually isn't an out-of-the-box way to jump to numbers that I know of! I personally added a "number" text object, so that I can treat numbers just like "words", and also created a "jump to number" shortcut.
- vbsteven 8y agoAnd just for completeness: ci' and ci" replace everything within the quotes, ca' and ca" replace everything including the quotes.
- toupeira 8y agoCheck out https://github.com/zef/vim-cycle https://github.com/zef/vim-cycle to extend Ctrl-A/Ctrl-X to arbitrary groups of words, e.g. to cycle between true and false.
- fourseventy 8y agoctrl-a is the most useful in a macro, for example if you want to increment a number on the next 100 lines.
- kurtisc 8y agoOr implement fizzbuzz
- Izkata 8y agoThere's a similar set I use often alongside those three: zt, zz, and zb. They scroll the buffer so the cursor is at the top, middle, and bottom.
- mrzool 8y ago> That's not terribly useful unless you're dealing with a lot of numbers Make no mistake: that is terribly useful, even if you're not dealing with a lot of numbers. You just found out about it so maybe you haven't realized it just yet. The mere fact that it accepts a count (i.e. 10<C-X>) and it's repeatable with the dot operator makes it a killer feature. To make the shortcut smarter and able to deal with dates and times I recommend vim-speeddating by Tim Pope: https://github.com/tpope/vim-speeddating https://github.com/tpope/vim-speeddating
- bspammer 8y agoEven more useful - it works flawlessly with octal and hex, detected by the 0 and 0x prefixes respectively.