Tell HN: '' in Vim moves cursor to recent line
50 points| surprisetalk | 2 years ago
'' Recent line
`` Recent line and column
(It's two single-quotes, not a double quote.)50 points| surprisetalk | 2 years ago
'' Recent line
`` Recent line and column
(It's two single-quotes, not a double quote.)
[+] [-] linsomniac|2 years ago|reply
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|2 years ago|reply
[+] [-] jstimpfle|2 years ago|reply
[+] [-] kps|2 years ago|reply
[+] [-] navan|2 years ago|reply
[+] [-] jstimpfle|2 years ago|reply
[+] [-] n8henrie|2 years ago|reply
[+] [-] y7|2 years ago|reply
And '. for line of the most recent change in the current buffer.
[+] [-] sja|2 years ago|reply
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/
[+] [-] k0k0r0|2 years ago|reply
[+] [-] danielvaughn|2 years ago|reply
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?
[+] [-] messe|2 years ago|reply
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).
[+] [-] hexfish|2 years ago|reply
The $ and ^ probably come from regex but I agree they feel a bit unergonomic on a standard keyboard. You can remap them if you're really bothered by it.
Personally I tend to use 'A' and 'I' a lot more because I tend to want to insert/append directly after moving anyway. And if I don't: just press escape. A bit of a hack but at this point it's just muscle memory.
And maybe in the end it all just doesn't work for you, and that's fine too! Vim is about ergonomics for a big part, and that is just a very personal thing.
[+] [-] masukomi|2 years ago|reply
I have keybindings which i'm comfortable with. Vim has different ones. It requires work and retraining to change?
What keybindings do you use in VSCode to delete to the next slash? In vim I type d t / "delete to slash" how about changing everything within parens ? c i ( "change in parentheses"
how about copying the entire "paragraph" of text? how about cutting the current line and the next 3 to move them elsewhere?
just because THOSE SPECIFIC things aren't as intuitive or "logical" doesn't mean vim isn't built on a foundation of VERY VERY sensible logical (to english speakers) defaults.
People joke about quitting vim ":wq" w = write q = quit and you can write them out in full. :write followed by :quit Yes you have to know about modes and the colon but if you can't wrap your head around modes, you're not going to wrap your head around loops in programming either and thus you don't need vim.
> but am I crazy for being highly skeptical at this stage?
no, and i mean this in the most literal sense, you're just ignorant. You don't know what you don't know and you assume that the one little thing you tried is representative. It's not.
yes, vim has some weird non-intuitive quirks. hjkl - for example - is based on the location of the arrow keys on a keyboard built into a computer that hasn't existed for like 50+ years. But EVERY complex tool (vscode included) has some weird quirks.
[+] [-] reg_dunlop|2 years ago|reply
My introduction to keyboard shortcut navigation (like, heavy use of keyboard shortcuts) was through VSCode.
I've been gradually trending towards Vim as another tool, however, full adoption of Vim is not an "all-or-nothing" proposition for me.
VSC already has so much built into it; and all this conversation about not taking your hands away from the home row is BS... my counter argument to those arguments is: plenty of common commands in VIM require pulling your hands off the home row.
One place where VSC could really improve is making the customization of keyboard shortcuts simpler. I already know about recording my keystrokes to find the command and context, but customizing a key chord to a context is less than intuitive. What on earth are the various contexts I could use? A little help would be appreciated, Microsoft.
As far as VIM.... heavy usage leads to greater ability. Years of usage would definitely accelerate coding. For now though, I use it to pop open one-off files for quick checks, simple edits of config files, and the random simple edits.
[+] [-] otterpro|2 years ago|reply
[+] [-] johnchristopher|2 years ago|reply
You are not crazy. Vim default bindings are less intuitive than windows/macos/gedit/word default bindings which are all about using arrow keys with a combination of ctrl/alt/cmd. There's logic to vim bindings though but it's not the same. The ctrl/alt/cmd combos have equivalent in insert/visual/normal mode and <leader> (a special key, usullay "\") but there's nothing intuitive about those at first.
I think replacing vscode with vim can't be done in one hour. First one has to learn the modes and the bindings then there's the whole compiling/linting/fixing/debugging/custom_macros/snippets/etc to add. I love vim and its modal interface and how it's easier on my joints than default bindings and I can't use vscode without a vim extension but I am not sure I'd invest time in learning it if I had first started using vscode as my main editor. For instance: I am bad at replacing identical chunk of text in vim (I can do visual mode and shift insert and regex replace but I can see how column editing seem easier and looks better in vscode).
my 2ç:
Oh, and I use "0" to position the cursor at the beginning of the line. (and I just noticed by trying out what ^ does that I usually do 0e to position it at first word/character of the line to get the same result).
[+] [-] doix|2 years ago|reply
Once you learn the keys for certain operations and grok vim, you can combine them in a way that I would argue is actually the most consistent compared to any other editor.
In terms of strain, do you not feel strain moving your hand to the arrow keys every time you do those operations? If you do decide that you like those bindings (personally I avoid arrow keys), you can get those same bindings in vim. FWIW, I use `_` to go to the first none whitespace character in a line, not sure if that makes it any better.
Also the tabs in vim are second to none (only emacs and kakoune are equal). It's actually the biggest thing that annoys me about other editors. VSCode and JetBrains have good enough vim emulation, but their lack of vim-like tabs is my biggest complaint. I never see people advocate for vim tabs in these types of threads, so I've been championing them every time I can :).
[0] https://stackoverflow.com/questions/1218390/what-is-your-mos...
[+] [-] TwentyPosts|2 years ago|reply
Helix has much better default keybinds, it has a lot of stuff built into it which would require extensions in Vim, and it has a much smoother learning curve (partially due to better keybinds, and partially due to the fact that it will show you which options exist when you eg. press `g`).
As an example: Moving to the start or end of a line is just `gh` and `gl`, which makes a lot more sense than Vim's keybinds. It's still going to take a while to get used to modal editing, but if you don't care about learning vim specifically, then I think that it's an improvement in every single regard.
My personal favorite feature is the multi-cursor editing, especially when coupled with the `s` key.
[+] [-] mplanchard|2 years ago|reply
- bind going back to normal mode to something other than Esc. Popular ones are capslock, Ctrl-[, jj, and jk
- use forward/back by word (w, e, and b) rather than going by character. Add numeric prefixes for faster jumping, eg jump to end of 3rd word with 3e
- turn on relative line numbers and use prefixes to jump to the desired line, eg 10j to go down ten lines, copy lines (y10j), etc.
- use f to go forward to a desired character, eg fk to go to the next k
- use i to apply actions to whatever is inside of brackets/parens/etc. Eg delete everything inside of parens with di), copy everything inside of braces with yi}
- I don’t remember if you have to turn it on specifically, but the vim mode for vscode supports vim surround, so you can do stuff like: change surrounding single quotes to double quotes with cs’”, add double quotes to word with yse”, etc
[+] [-] gorjusborg|2 years ago|reply
Think of the difference between vscode and vi as similar to the difference between a game controller vs mouse and keyboard. They are very different ways to do the same thing.
Also, if you don't touch type (fingers on home row) it might not feel immediately better. For me, it made sense pretty quickly because it was clear the goal was to move as little as possible away from where my fingers rest.
The other thing to note is that there is a depth to vim's feature set you will not find in most software, so when people rave, they may be raving about different parts you haven't discovered yet.
[+] [-] nequo|2 years ago|reply
It is intuitive if you use regular expressions too because ^ and $ have (nearly) the same meaning there. But you’re right that your shortcuts work well too.
Other shortcuts that come in useful with no non-Vim equivalent that I know of:
[+] [-] ndr|2 years ago|reply
Note that it's not the only way to go to the end of line.
Home/End bring you to beginning/end of line like anywhere.
`I` is like `^` followed by `i`, brings you before the first non-empty char in insert mode.
`A` is like `$` followed by `a`, brings you after the last char in the line in insert mode (append).
If you'd like to select things press `v` in normal mode and move around with directions or Home/End or ^/$.
All things considered there are only so many keys to have meaningful/semantic shortcuts, you get used to the one you use the most.
[+] [-] CGamesPlay|2 years ago|reply
[+] [-] unknown|2 years ago|reply
[deleted]
[+] [-] numboreal|2 years ago|reply
[+] [-] olddustytrail|2 years ago|reply
Actually it's very intuitive, because ^ and $ mean start/end of line in regex.
[+] [-] guilherme-puida|2 years ago|reply
You can also use shift+i and shift+a to move o beggining/end of line and enter insert mode.
[+] [-] kobalsky|2 years ago|reply
one-handing two keys will hurt your hands in the long run.
[+] [-] teddyh|2 years ago|reply
[+] [-] Bjartr|2 years ago|reply
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)
[+] [-] unknown|2 years ago|reply
[deleted]
[+] [-] tambourine_man|2 years ago|reply
[+] [-] johncoltrane|2 years ago|reply
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|2 years ago|reply
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)
[+] [-] armonge|2 years ago|reply
[+] [-] number6|2 years ago|reply
[+] [-] rane|2 years ago|reply
[+] [-] crickey|2 years ago|reply
[+] [-] trollied|2 years ago|reply
:q!
[+] [-] YeGoblynQueenne|2 years ago|reply