Why Vim
Introduction
Vim is a terminal-based text editor like Nano "not really" . lightweight and popular for being hard to use, Vim is known for its steep learning curve, which makes you less productive initially, But after you get the hang of it you will be better than ever before.
Currently, I use neovim "it is not a rewrite but a continuation and extension of Vim" according to theNvim About Page I use it because it allows me to use lua to configure it which is far easier and well-documented than Vim script (a language that meant to configure vim in the first place)
I don't want to make this post a full tutorial to Vim (nvim) instead I want it to be a quick showcase some of the amazing Vim (nvim) features and how to start with your nvim journey.
Vim is Faster
it's faster then any other text editor or "IDEs" because of starting time, Hopping between files and even navigating between projects
But why? it's faster because its a TUI program that runs on the terminal compare to vscode a program that has been created using JS/TS build on the Electron framework, JS/TS is a technology that runs fairly good on the browser because of the v8 engine, So it is not meant to create these kinds of programs, this documentary tells you a lot about how ts and vscode inventedTypeScript Origins: The Documentary
Moving
If you want to jump between projects, Use tmux. if you want to move between files, Use harpoon or telescope. I use both, And these tools made my life easier
For example I always have App.jsx and App.css files in my react projects, I want to move between them I can use harpoon to do that, And for the other files I use telescope to fuzzy find my way thePrimeagen made a video demonstrate harpoon
here's an example of what harpoon can do:
Vim Motions
Vim motions, Which are built-in features of vim (nvim), ThePrimeagen once said "I don't understand why anyone who's programming doesn't use those, Those are extremely efficient and they're very well done"
Vim motions are available on vscode and I think on every other text editor
Vim motions allows to do every thing on your keyboard instead of reaching to your mouse to do the most obvious things, Like text selection, For example if you want to delete a line of text with the mouse you should select the line from start to finish then deleting it with backspace, With nvim you can select the entire line and deleting it at the same time by pressing shift+v+d you may see it something complicated but its just shift+v to enter selection mode and select entire line d to delete the line and that's it once you do it for like 10 times you will never forget it again, You may say why, The answer is pressing ci( is far easier then selecting the entire text inside of () and deleting it then start typing again.
Enough talking about them let's use them:
cw => change a word, dw => delete a word, ci( => change inside (), ci{ => change inside {}, Shift+v+d => selecting the line and then deleting it Shift+v+y => selecting the line then yank it "copy it to the buffer register"and much more
btw thePrimeagen made a really good sequence of videos that techs Vim motions I do recommend watching it.ThePrimeagen Playlist
Easy to Configure
You can configure Vim to your needs adding new plugins, keymaps, and discovering things, 99% of the things you desire have been already created and maintained by other developers *chads btw*, If you can't find something that you want you can create it and maintain it yourself.
Vim Keymaps
You can set keymaps that fits your needs and be creative, Do you want to see something awesome?Vim.keymap.set("n", "<C-f>", "<cmd>silent !tmux neww tmux-sessionizer<CR>")This is one of the best keymaps ever, By pressing CTRL + f (while you are in a tmux session, I discovered this the hard way) you can fuzzy find through directories, Obviously you have to add the directories that you want to fuzzy find through them by modifying the script *tmux-sessionizer*created by ThePrimeagen , btw this keymap also has been created by ThePrimeagen.
Let's say that you are in a directory working on something and you want to configure something in nvim.rc file in the same time you don't want to mess up your current workflow so you use this keymap to trigger the tmux-sessionizer script then you can run the nvim.rc file in a separated tmux session without messing your current workflow and you can go back and continue your previous work how cool is that.
This is a video that demonstrate that:
Vim Macros
Vim macros one of the greatest things about vim they allows you to do a sequence of steps over and over again, Just by doing them once like this:
I love to write my script in obsidian first then copy and paste the script to .jsx file, I should wrap each paragraph with p tag:<p className="post__text"></p> and give it a class of .post__text or other class names so I do it by giving the macro a letter to name it then I do the sequence of steps once I finish doing them pressing q to save the macro then, I can trigger it by pressing @ and the letter (the name of the macro), Imagine trying to do such a thing in vscode. this is a really good video tutorial and showcase of vim macros byVim Diesel
Nvim + Tmux
As I mentioned earlier, You can use tmux for easy moving between projects. What I mean by that is you can have multiple tmux sessions opened to multiple projects and move between them without having to close the current session or messing your workflow, Although this article focuses on Vim, I must mention that tmux is one of the greatest tools I discovered in the previous months besides nvim. and I think these tools goes hand and hand together to make your workflow better, Easier and less frustrating.
Better Understanding of things
One of the best things about Vim is that you can understand the behind the scenes part of your "IDE" so you will never says such thing: vscode provides me with really good formatting", Or even worse "vscode provide me auto completion " because its the LSP job to do that, One of the things that I discovered is in the past months is: the difference between prettier (code formatter) and eslint (code linter) and there is a big difference between the two, Because a formatter (prettier) just formats the code and makes it looks better, And a linter (eslint) diagnosis the code you wrote and find out about the variables that you didn' use or other mistakes in the code in production, So now instead of downloading random extensions in my vscode without knowing what is the benefit of such extensions now i know.
Benefit Of this Experience
Last but not least the knowledge that you get from this experience can be easily applied to other text editors or "IDEs" like:
- 1. Vim motions
- 2. Understaing what is happening behind the scenes in your "iDE"
- 3. Experience using terminal and cli tools
- 4. Tmux if you are willing to integrate this piece of technology to your workflow
How to Vim
There is no 'best' way to learn something; everyone has their own methods for learning. I'll share my approach, Which works well for me, But remember, What works for me doesn't necessary works for you.
I did uninstall windows after watching couple of videos for thePrimeagen he was moving so fast and I remember that I was pissed off because I can't do the same thing with my vscode so after days I install ubuntu as my main os and I have been using ubuntu since then.
to be far I tried to quit one time but because I don't have windows I couldn't go back, I watched the playlist I have mentioned before about vim motions from thePrimeagen and I watched his vim.rc video (to configure nvim) half an hour first of all I didn't understand 80% of the things so I was figuring stuff out, The comments helped me a lot I couldn't be able to do most of the things without them , I was going back to the same vim.rc video over and over again and his workflow video. so I didn't do everything at once, I didn't even know that I could clone the repo from github at that time so i typed the code by following along with him and let me tell you this experience was painful but it was worth it.
Through this article I was mentioning ThePrimeagen a lot because he got me to all of this in the first place, It's not about copying his workflow though you can have your own workflow, But if you set down to learn all of these stuff you will never going to learn ever, These stuff are boring as fuck I want something that works even with letter effort then I will learn how to configure it and make it mine. So his videos were helpful to me, It's fine to copy someone's workflow at first but you should understand it gradually and make your own later.
This is a really good series too calledUnderstanding Neovim. goes over the main concepts of nvim and make a configuration from the start, There are a lot of other Youtube tutorials out there, And of course the user manual tj deVries read the user manual for over 9 hours on one single stream you can find ithere.
i didn't finished it though.
I learned from this experience that I shouldn't ask for validation from anybody if I want to learn something like The C programming language I will go do it, Even if I am a front-end web developer I will learn C to discover things, Have fun and most importantly figuring out how things work behind the scenes, Learning something new will never make you worse in fact, It will add to your skills and knowledge, Especially if it's something challenging like Vim.
in the end I am still learning about nvim and I hope to refacter this article and make it better and hopefully learning from it as much as you.