this post was submitted on 21 Jul 2023
139 points (97.9% liked)
Linux
48083 readers
931 users here now
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I guess a few hours until I had memorised basic stuff like moving around, copy-paste, etc. Then maybe a week or two before I really felt comfortable with it. There's some point where you actually understand vim and start using it more like a programming language and less like a traditional text editor. For example I love the "repeat last command" (default bound to . key), but to use it effectively you need to create a command that will be usable everywhere you want it to, and there are many different commands that do the same thing.
Here's a random example:
Let's say you have the following text in a document you're editing with vim, and you want to delete the word "dance". Vim is currently in normal mode, and with the cursor placed on the highlighted "c":
If your brain is still in Notepad.exe mode, you might achieve this by pressing "i" to go into insert mode and using a combination of backspace and delete to edit the line.
A vim beginner might know that "x" and "X" in normal mode works like delete and backspace, without going to insert mode, so "XXXxx" does the same.
Someone who has learned basic movement could instead solve this by combining two commands, first "b" to move the cursor back to the beginning of the word, followed by "dw" (delete to next word).
But there's also a single command that deletes the current word, regardless of where the cursor is in it, which is "daw". And since this is a single command, you can repeat it with the "." key to delete a different word.
Now here comes the vim magic: If you instead want to replace the word "dance" with "pool" you just modify the above commands by replacing "d" (delete) with "c" (change). So in our example you could type "caw" in normal mode, which deletes the word under the cursor and places you in insert mode. There you write "pool" and press Escape to go back to normal mode. Now you have a single command that replaces any word under the cursor with the word pool, which you can repeat anywhere you like.
And if it's not just the current word you want to change, then replace the "w" in the command with something else, for example "ca)" will change a pair of parenthesis and everything inside them, which is very useful when programming C/C++/etc.. And if you have nested parentheses and want do something with two levels at the same time, the command becomes "c2a)" which might look complicated, but it's basically just simple rules that you string together.
https://vim-adventures.com/ might be a fun way to get started, then look up some nice vim cheat sheet and keep that nearby. I would also recommend looking up some example vim configs, because the editor is very bare bones with the defaults. I like relative line numbers for easy jumping between lines, so give that a try.
When you've mastered (?) vim you'll also see less (the program) keyboard shortcuts make a lot more sense. You can also change your shell to vi mode for faster editing of commands.
I will look into vim adventures. Trying to learn Vim at the same time as learning everything else is hard. So hopefully, a Vim game will be more palatable.