DEV Community

loading...
Cover image for Vim .. best code editor ?

Vim .. best code editor ?

bekbrace profile image Bek Brace ・Updated on ・2 min read

Vim, a text editor for writing code where you navigate around the screen with your keyboard instead of a mouse.
It's based on the original Unix text editor VI which was created by Bill Joy in 1976,

Alt Text

then VI improved or VIM followed it in 1991; but why would you ever want to use a keyboard-based text editor in 2021 if you have a lot of easy to use mouse-based IDEs ?

When you write code everyday, your fingers should be glued to the keyboard at all times, every time you touch your mouse, your productivity declines; and learning to code with VIM is like learning to play an instrument, it will be painful at first but that pain will lead to more precise and productive code editing in the future.

VIM runs in the terminal and it's installed on almost every machine, and at some point you'll likely find yourself accidently dropped into VIM with no way to escape - which is a joke I always heard in my classes , if you want to mess with someone who doesn't know VIM, let them enter nonsense/crap in VIM editor on their machine, but they don't know how unpredictable it is to escape the main page - in other words, shut down VIM.

If you find yourself there you can quit VIM by typing :q that will close and modify the file, or if it has been modified and saved, you can use :q! to discard any other changes, or :wq to save and quit VIM peacefully.

You can open a file in VIM like so :

terminal > vim bek.py

You can toggle between different modes
Normal mode, where you can navigate with your H J K L keys

H -> Left
J -> Up
K -> Down
L -> Right

You have INSERT mode, you can access it by hitting i for insert, logical right?
You have COMMMAND mode, and for that to happen you can hit on :
And VISUAL mode by hitting v

Alt Text

If there is a character you want to delete, you can hit (x) [ Delete Character ]
Or, double (d) to quickly delete an entire line.
To undo it, hit (u) to Undo it.
To add line number, got to command mode by hitting semicolon : then type set number, and now you can navigate any line with :(number), so to got to line 5 -> :5 and so on.

While navigating the document, if you want to modify something, you can hit (i) for insert mode , modify what you want then hit (Esc) button to exit to normal mode.

If you want to copy and paste code, you can paste from system clipboard using (+p).
To save the changes, you can hit (:w) to save it, then run the program directly using (:!) followed by the command we want to run, in this example it will be:
terminal > :! python bek.py

Credit: Fireship - VIM in 100 seconds

Discussion (20)

pic
Editor guide
Collapse
eljayadobe profile image
Eljay-Adobe

I've been using Vim for 25 years. I can't figured out how to quit.

Collapse
maurothecreator profile image
Mauro R. Torres Neto

I can't even make a "hello world" using Vim, give me one week cus I'll figure out

Collapse
francescadev profile image
Francesca

😂 I got lost in VIM in the beginning and was initially scared to go back in for fear I might not get out.

Collapse
krrishdhaneja profile image
Krrish Dhaneja

Can you please tell me how to download a vim plugin?

Collapse
barelyhuman profile image
Reaper

the manual way needs a lot of commands, you can instead setup something like VimPlug and then just name the github repository and vimplug will download it for you.

github.com/junegunn/vim-plug

here's the repository for it

Collapse
maurothecreator profile image
Mauro R. Torres Neto

You can install it manually (which require vim script and boring stuff) or use a plugin manager for Vim, I recommend vim-plug (github.com/junegunn/vim-plug)

Collapse
bekbrace profile image
Bek Brace Author

Friends have answered already, I arrived late :)

Collapse
krrishdhaneja profile image
Krrish Dhaneja

Lol!😂

Collapse
gealber profile image
Gealber Morales

I've been using Vim almost one year. At first it was a painful, really, but right now I don't feel comfortable using another Text Editor. Anytime I try to scape from Vim, end up trying to use the keyboard shortcuts learned in Vim😂

Collapse
bekbrace profile image
Bek Brace Author

I know what you mean :)

Collapse
jackosh profile image
Ruslan Rybak

Use vscode vim plugin to get vim key bindings in Vscode
github.com/VSCodeVim/Vim

Collapse
gealber profile image
Gealber Morales

Yes I tried it too, but my machine is very old and vscode takes a lot of time to just start up. That's one of the reason I started with Vim, given the fast start up and performance in general. I'm not saying that vscode is slow. It is just that when you have vscode, Postman, Chrome, maybe another Electron based application, all at the same time opened is not so pleasure. My machine start crying 😭😭😭. And having this three application opened is not so uncommon or at least not for a web developer.

Collapse
anargu101 profile image
Anthony Arostegui

The feature I look for is a good debugger tool like vscode. I have to editin vim editor but then open vscode to debug. I found out vimspector but it has some crashes does not perform very well. Does anyone know a good debug tool for vim?

Collapse
darkwiiplayer profile image
DarkWiiPlayer

Does anyone know a good debug tool for vim?

print /s

Collapse
alexsaplacan profile image
AlexSaplacan

Depends on what language you are coding, I write python code and I find the python debugger being enough.

Collapse
bekbrace profile image
Bek Brace Author

I totally agree with you, I myself don't use VIM in writing code, but for editing and only when needed, otherwise i use VScode

Collapse
darkwiiplayer profile image
DarkWiiPlayer

but why would you ever want to use a keyboard-based text editor in 2021 if you have a lot of easy to use mouse-based IDEs?

This is like asking "would you ever want to code on a desktop PC in 2021 if you have a lot of easy to use smartphones?"

I've used vim as my one and only editor for years now and I wouldn't trade it for anything else (even stuff that has vim bindings, honestly).

Collapse
bekbrace profile image
Bek Brace Author

I understand you, totally
I myself started to code in Basic language in 1989 on my ATARI 800xl, and I got used to work solely with a keyboard, then with the appearance of Ms-DOS I was feeling very comfortable, and when I started working on win 3.1 , I had no idea what I am doing - so I understand perfectly being attached to a keyboard :) - cheers

Collapse
francescadev profile image
Francesca

I 💗 VIM !!!!!!!!!!!!!!!

Collapse
idchef profile image