8 ms·
Tell HN: '' in Vim moves cursor to recent line
'' Recent line
`` Recent line and column
(It's two single-quotes, not a double quote.)
- crickey 3y agoCool, i guess
- sja 3y agoTotally! Thanks for sharing. This is part of the “marks” functionality of vim, where you can essentially set bookmarks explicitly, and there are some default ones (like going to the last jump which you described here). Check out the “Marks and positions” part of the cheatsheet here for more useful tricks: https://vim.rtorr.com/ https://vim.rtorr.com/
- k0k0r0 3y agoBest vim cheatsheet I have seen so far. OTOH I haven't looked at one in a while, and back then my understanding of vim may have been insufficient to appreciate other lists.
- y7 3y agoAlso Ctrl-O for back, and Ctrl-I for forward, are useful. And '. for line of the most recent change in the current buffer.
- jstimpfle 3y ago'<character> jumps to the location register identified by <character>. ' is just a special register that holds the "last position", and '' then jumps there. You can explicitly set marks using m<character>, and go back using '<character>. For example, 100Gmagg'a
- kps 3y agoAnd to be more specific about the OP entry, 'x (apostrophe) moves to the line of location register x, and `x (backtick) moves to the line and column of x.
- rane 3y agoIsn't <Ctrl-o> more useful in general?
- johncoltrane 3y agoNot to "recent line". To "line before latest jump". This is in section 10 of chapter 3 of the :help user-manual. That's like… day 1 material. Not worthy of HN, IMO.
- yjftsjthsd-h 3y ago> This is in section 10 of chapter 3 of the :help user-manual. That's like… day 1 material. Not worthy of HN, IMO. I assure you, nobody makes it to chapter 3 of the manual on day 1. Not to mention that the manual is long enough that most people don't seriously read it (much like bash: Yes, the manpage documents it well, but there's too much material to expect everyone to go through it all)
- number6 3y agoThere is a manual? I thought vim was tough through verbal anecdotes from generation to generation
- foobarbaz33 3y agoThe bundled manual is really good. vim :help :only Don't skip the intro text at the top. You need to know the key binds it describes to navigate the manual. Jump to subject: Control-] Jump back: Control-o
- armonge 3y agobeen using vim for 10 years, I didn't know this, and it's on the frontpage of HN, that would make it worthy, IMO
- johncoltrane 3y agoMaybe it's not too late to start learning it properly instead of relying on random posts.
- tambourine_man 3y ago:h jumplist :h jump-motions "gi" is also useful.
- teddyh 3y agoAlso usable in less(1), for those who don’t usually run vim/vi, but often run less(1).
- danielvaughn 3y agoI've been experimenting a bit with Vim, and so far I'm _really_ not convinced. I know VSCode is slow, but I have an intuitive set of keyboard commands that accomplish 80% of what I need to do throughout the day: move to end of line: cmd + right move to begin of line: cmd + left move to end of file: cmd + down move to begin of file: cmd + up select to begin of line: cmd + shift + left select to end of line: cmd + shift + right There are several others but they're all similar in that they feel logical and intuitive. By contrast, in Vim you use $ to move to end of line, and ^ to move to begin of line. Not only is it unintuitive, it requires more strain of my hands/fingers, and I could easily see myself feeling the pain if I used it full time. Unless I switch keyboards or something. I'm still giving it a shot because everyone raves about how Vim makes them so much faster, but am I crazy for being highly skeptical at this stage?
- numboreal 3y agoOf course the bindings you create are inherently going to be more intuitive to you, but Vim bindings are designed so you can do all the editing you need without moving your hands (like moving your hand over to the arrow keys).
- otterpro 3y agoYes, if you like VSCode, keep using it. I say that everyone's preference is different. As for me, I use both vim (for general editing) and vscode (javascript coding), depending on what I'm working on. As for the keyboard command, I prefer not to use arrow key since it takes my hands off the optimal position as I need to reach for that arrow key, which puts a slight pause in thought of all the code that I'm thinking in my head. Sure a loss of one second may not be much, but when I'm in the flow / zone, I just want to move as fast as possible.
- messe 3y ago> in Vim you use $ to move to end of line, and ^ to move to begin of line. Not only is it unintuitive To be fair, that is intuitive if you learned regexes before VIM. The important part is those motion commands compose. If I wanted to visually select up until the end of the line, I can type v$ — if I want to delete everything from this position to the start of the line, I could type d^. In the middle of a word that needs to disappear? diw (delete in-word). Do I want to copy that word? yiw (yank in-word). Eventually, outside of composing macros (another great feature), you don't really think about the underlying letters of finger movements to perform a certain task; you just do it. It's not for everyone, and it does come with a downside of making every other code editor feel borderline unusable unless it comes with a good VIM plugin (Jetbrains' suite of IDEs are great for this, and VSCode is pretty good).
- trollied 3y agoHow to quit it, just in case you're unsure: :q!
- YeGoblynQueenne 3y ago?
- navan 3y agog; has been more useful for me than this one. It goes to the most recent change location. I edit a little, then move around in the same file for reference or check signatures and then continue editing by going to previous edit location using g;.
- deleted 3y ago[deleted]
- linsomniac 3y agoI use '" (tick, double quote) all the time, after exiting and coming back into a file it jumps back to where I was. Time travel in vim is insanely cool. ":earlier 5m" undoes changes to the buffer to make it like it was 5 minutes ago. ":later 1m" will travel the other direction. Also useful in undo/redo is "g-" and "g+" which undo and redo non-linearly. With just "u" and "^r" you can get to where some undo states are reachable, g-/g+ can get you to those missing states.
- hirundo 3y agoDoctor Strange did a specific kind of time travel in a Marvel movie that I want in vim. He did it to an apple, but not the surrounding area. I would like to be able to highlight a selection in vim and just do time travel in that part, so that my changes elsewhere are not reverted. Does that exist?
- phyrex 3y agoIt exists in emacs. Blew my mind when I first saw it!
- satvikpendem 3y agoWhat's the feature called?
- phyrex 3y agoApparently “selective undo”: https://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Un...
- satvikpendem 3y agoI've been looking for this in a code editor for so long. I just want to undo inside a specific set of lines, is that so hard?
- Bjartr 3y agoI love Vim and use it (and Vim modes in IDEs frequently), but this isn't exclusive to Vim. Alt-Left in Eclipse and Intellij will move back through recent positions, and Alt-Right moves forwards. Though I think it's different between the two out of the box. (I use Eclipse keybinds in Intellij)