Live data from Hacker News

Vim – Minimal Setup Explained

guckes.net

61–70 of 114 posts

Re: Vim – Minimal Setup Explained

#61

Question for Vim users: how do you get used to hitting Esc very often? I know some switch Cap with Esc but still clunky.

I remapped caps lock, to be control when you hold it and escape when you use it alone.

However, for a long time I used Ctrl-c instead of escape, which is 99% the same except in some odd corner cases (not recommending that, just mentioning my history).

These days I use the common vi tweak of 'jk' being mapped to escape.

Re: Vim – Minimal Setup Explained

#62

Question for Vim users: how do you get used to hitting Esc very often? I know some switch Cap with Esc but still clunky.

I use ctrl+c. Since I'm already used to ctrl+c while using a terminal, it became easy even in vim. By default vim goes to normal mode when you press ctrl+c

I mentioned in another comment that I used to do this, note there are some rare cases when it's not the same as esc. You can remap Ctrl-c to be exactly the same though.

Re: Vim – Minimal Setup Explained

#63

Many decades ago, you had to resort to abbreviations so that you could use memory in the most efficient way possible. Computer hardware at that time was more expensive than labor. People having to adapt to how computers worked was the doctrine at that time. But in 2022, this is no longer true. Even the most limited platform you can think of can comfortably run vim. A $5 Raspberry Pi Zero is overkill for vim. And now,…

Quite apart from the fact that many (most?) vim short forms have long form equivalents, and vim has autocomplete - this argument feels misguided to me, mostly because I don't see why it would be limited to just vim. It seems natural, if you hold such a position, to also advocate abandoning CLIs like `ls`, `cd`, `jq`, `aws`, et al? - and I would despise having to put up with stuff like:

    $ change-directory foo/bar
    $ amazon-web-services elastic-compute-cloud describe-instances
    $ javascript-object-notation-query ...
Not to mention short parameters: `ls -AF`, `grep -v`, `curl -H`, ...

One of my most valuable resources is time. I would rather invest it in learning each tool's vocabulary than spend so much time typing (a prefix longer than the existing name, tab, then pick the answer) in an "everything is spelt out in full, acronyms and abbreviations are banned" world.

Re: Vim – Minimal Setup Explained

#64
post #60

The only thing I've really struggled with when trying to get into using vim full-time is navigating my project. In VSCode I basically hit CTRL+SHIT+F -> "portion_of_a_function_name_or_something" constantly. I abuse the heck out of global search. Is there a way of navigating your project in vim that's similar/easier? How do vim people quickly navigate their code without going "what was the name of that file with that…

Vim supports ctags[0] lookup out of the box which fits your need somewhat. I tend to use FZF[1] which has functions for leveraging ripgrep and silver surfer for searches. It can also use find. FZF also has dialogues for paring down results in real time (i.e., as you type) There are also plugins that are much more nuanced and more involved for searching symbols and providing autocomplete. Duoplete, vimcomplete, youcom…

Yep that’s what I do too. ctags are fast and low overhead to generate.

The other alternative is to set up a Language Server (LSP) for navigation and you can use the same ones as VSCode uses.

Re: Vim – Minimal Setup Explained

#65

Since I was in university 15 years ago I promised myself to learn Vim commands seriously. Well I see that finally I did my programmer life learning only switching insert mode / edit mode, maybe 5 commands like A x etc...,and :q or :wq!

I relate quite heavily to this when using vi to do all my git-related activities. git rebase -i ... followed by ↓dw ↓←dw ↓←dw ↓←dw ↓←dw ↓←dw i s ↓s ↓s ↓s ↓s ↓s because I keep forgetting :s/pick/s/g is a thing i, a, :q, :wq, dd, xdd, and D are all the ones I remember, but cutting/yanking pasting is still something I don't have the muscle memory for. Shift+G takes me to the bottom of a file, but I don't know how to get…

Thank you everyone for the _really_ helpful responses!

It is immediately apparent to me that my interaction with vim has been heavily informed and limited by my preconceptions and previous text editing experiences.

Time to start engaging with vim as its own entity, with its own conventions and idiosyncrasies.

EDIT: Formatting

Re: Vim – Minimal Setup Explained

#66

Question for Vim users: how do you get used to hitting Esc very often? I know some switch Cap with Esc but still clunky.

First I “live” in command mode and only visit insert mode to …insert stuff afterwards which I always leave with escape.

So using vim becomes a series of small edits.

I map caps to Ctrl and use Ctrl-[ for escape.

That means I can still use Ctrl for insert mode shortcuts such as

  Ctrl-w (delete last word)
  Ctrl-r to insert a register  (eg Ctrl-r% for filename)
  Ctrl-h instead of reaching for backspace.
There’s loads of them.

It just takes a bit of muscle memory but if you’re a touch typist it’s well worth it IMHO.

Doing it this way, rather than say ‘jk’ in insert mode, also has the advantage of working in other vim-like programs where you’d have to repeat the mapping. If that’s even possible.

Re: Vim – Minimal Setup Explained

#67

Question for Vim users: how do you get used to hitting Esc very often? I know some switch Cap with Esc but still clunky.

Its the weakest part of the vim keyboard scheme IMO for ergonomics, and switching modes in general. I wish there was an alternative that gave a nod to vim but remained in 'input' mode without loss of capability, you know...without having to be vscode. If the key layout wasnt even worse, and it wasn't a bloated mess (on windows at least) I'd have switched to Emacs. Capslock is mostly a redundant button so I wholey sup…

Now I wouldn’t do this myself but…

If you want stay in insert mode most of the time you could use Ctrl-o to switch to command mode for a single command and then be immediately returned to insert mode.

Eg

  Ctrl-o de
To delete to the end of the current word.

Again, I definitely wouldn't do it that way but vim makes pretty much everything possible.

Re: Vim – Minimal Setup Explained

#68

The only thing I've really struggled with when trying to get into using vim full-time is navigating my project. In VSCode I basically hit CTRL+SHIT+F -> "portion_of_a_function_name_or_something" constantly. I abuse the heck out of global search. Is there a way of navigating your project in vim that's similar/easier? How do vim people quickly navigate their code without going "what was the name of that file with that…

Vim has the concept of and (you can :h these for more info), which are basically the things that vim will jump across when you press 'w' or 'W'.

You can combine this with grep and the location list to find symbol usage across multiple files.

    nnoremap g :grep 
You can then use :cnext and :cprev (or focusing the window and selecting an entry) to navigate between them.

As others have stated, you can also use ctags (plugins like https://github.com/ludovicchabant/vim-gutentags are useful for refreshing tags in a project), but for some languages you may need to add a tag definition (e.g. for something like rust or zig). For older languages like C you should be fine.

Re: Vim – Minimal Setup Explained

#69
post #45

Earlier quoted context omitted.

I use macros way more often than dot. With a macro I can include the movement action of getting to the correct position before the edit takes place, I'm not sure if this can be done with the dot key alone.

Whether one uses . or a macro (manual or recorded) should depend on the current situation. It's really not a "pick one and stick with" it kind of situation.

I agree, so many ways to do it it’s horses for courses.

Eg from the first “pick” you could press * to highlight occurrences and move to the next one use cw to change it to “s” and bounce on n to move to the next one you to squash and use . to repeat the change.

That’s visual and lets you decide which commits to squash.

If I wanted to squash all the other commits I’d probably use visual block and } instead, but that’s just me.

I’d save a macro for more complex edits.

Re: Vim – Minimal Setup Explained

#70

Many decades ago, you had to resort to abbreviations so that you could use memory in the most efficient way possible. Computer hardware at that time was more expensive than labor. People having to adapt to how computers worked was the doctrine at that time. But in 2022, this is no longer true. Even the most limited platform you can think of can comfortably run vim. A $5 Raspberry Pi Zero is overkill for vim. And now,…

It’s just me but I think it’s still worth knowing the abbreviations just in case you want to type them.

Personally I try to avoid mappings as much as makes sense.

So I’d use

  :noh
to clear highlighting instead of making a nohighlight mapping for it.

Simply because it’s still quick to type from muscle memory and more portable. I also find them easier to remember than custom mappings.

Post reply on HN