Vim for starters - the minimum you need to know

Hamza Tamenaoul on December 25, 2017

The first time I heard about Vim, it was 5 years ago. And my natural reaction was : " Why in God's name, will I sacrifice the comfort of a modern... [Read Full]
markdown guide
 

Why in God's name, will I sacrifice the comfort of a modern text editor like sublime text, for an outdated, ugly, and complicated text editor?

Definitely my first reaction too 😄

 

Sorry but this comment looks anything but constructive.

Not only vi is an important historical editor (as emacs), but it is also available on almost any linux/bsd server or embedded os which becomes even more important in current IoT area.

Oh I forgot... it's also natively on windows now
blogs.windows.com/buildingapps/201...

Sure, Sublime, WebStorm, VS Code, plenty IDE or modern text editor can be preferred on day to day basis development. But such simple tutorial should not be denigrated as you sure will be happy to know those basis one day.

 

Eh, when I get stuck working on something remotely and am forced to use something for a quick patch, I'll just use nano.

Heck, I even got a workflow set up where I can edit remote files locally using VS Code (using this solution: codepen.io/ginfuru/post/remote-edi...)

Between these two methods, I really don't need to learn Vim or Emacs. I've given Emacs (via spacemacs) a fair trial, but honestly, some of us just prefer a GUI Text Editor and the ability to use a mouse on occasion :/

Saying that you can also use nano, or or scp to edit locally, can be a constructive comment. :-)

But even with that, it doesn't means that:

  • knowing about vim is useless
  • writing a vim tuto is a waste of time

I don't get the point to go reading let's say a Webstorm tutorial and comment "Hey! this tuto is shit, just use VS Code it's free..."
The title clearly states what the content is about, read it if your interested, add hints about other solutions if you want, but DON'T DENIGRATE, otherwise your just trolling

I'm more comfortable with vim than with nano...
I occasionally use SCP to edit remote JSON configs locally
I like very much VS Code
I mainly use Webstorm at work.

That's me, I won't denigrate nano or any editor, neither tutorial about any of them

Any tuto about any editor is interesting

Are we reading the same comment here? I don't see anything that indicates the tutorial is useless. It's just a joke.

My reply was initially against that reaction:

Why in God's name, will I sacrifice the comfort of a modern text editor like sublime text, for an outdated, ugly, and complicated text editor?

The comment looks to have been deleted but the quote from Ben Halpern on which I replied remains here.

In short it is saying: "Vim sucks (outdated, ugly, complicated). Hey everyone use other things (like sublime), so don't bother with this tuto..."

The blog post isn't asking anyone to change its editor, it is just providing a tutorial.

Maybe I over-reacted a little, but way too much often we see such comments with for main effect to discourage people to share their experiences and bring their contributions (tuto, tools, bug reports) to the community.

So no for me, it is not that much a "joke"

 

Asking such question to those who use vim for a couple of years does not make any sense. Why? Knowing vim enough will completely change your mind, believe me! To me, it sounds like someone who uses java arguing why people like using python. After becoming used to modal editing and some powerful features like global commands and text-objects I can say that I will never use another editor.

 

As soon as you have Git installed on Windows and are required to make changes not supported by your GUI, as soon as you commit your changes, you will be confronted with vim, because it is the default editor. Yes, you can change the default editor or you can then commit on the GUI, but that would be, im my opinion, counterproductive.
Also, as soon as you start with Containers (like Dockers), you have no GUI. If you don't use volumes, you probably can work by copying files back and forth, but that is also not really useful. So therefore, a basic knowledge of vim is always helpful.

 

Vim's plugins are what make it useful for me. I usually work in an IDE, but for a few things, I'll open a terminal, navigate to the file, and then use vim for a small change. One such plugin that is invaluable is vimawesome.com/plugin/vim-easy-align. With a handful of keystrokes, I can align an enormous block of lines with, say, the = sign on each line.

 

Maybe. One day you'll be sysadmin, and you will need to edit a config file in a terminal. This could happen to you. Expect the unexpected.

 

This day is here for any developer working with docker and needs to troubleshoot a running container :)

 
 

Vim is my text editor of choice. It is my workhorse text editor, I use it day-in and day-out. It is available on every platform I work on -- and I've worked on a lot of different platforms. According to StackOverflow polls, it is one of the more popular text editors by developers.

Whenever I hear anyone asking how to get started with Vim or vi, my first reaction is "It's too late for me, save yourself!" (It's a "ha-ha, only serious" comment.)

My fingers tacitly know Vim. It gets out of my way. I can become one with my keyboard; it is a zen experience.

I used emacs for 2 years before trying to use vi. It was on a bet, and I had to use vi for 6 months; the other developer had to use emacs for 6 months. After the 6 months was up, I never went back to emacs, and the other developer couldn't wait to get back to vi.

Bill Joy, the creator of vi, has expressed that vi was created at a time of 300 baud modems, and optimized for minimal bandwidth. And with todays modern machines, the reason for vi to exist has passed.

Yet, it remains quite popular.

The reward for the steep learning curve is a highly efficient, powerful, and elegant text editor. Beautiful in its simplicity. When I have to use an IDE (these days Visual Studio and Xcode), I feel hobbled until I can get back to Vim to do serious editing on the source code I work on.

 

The first few months of vim were trying, and the next 2 years were mostly amazing except for never really understanding how I triggered and could exit macro recording. I'll use a graphical editor for big, heavy projects, but nothing beats vim for regexes and ssh'ing into the production server for a hotfix.

 

That's what I tell all my colleagues: you never know when you're connecting to a remote server through SSH and you'll have to make due with Vim or similar.
All Dev should at least know the basics to Vim. At least opening a file, editing and saving.

 

Also with the syntastic plugin you get syntax check for many languages (including bash), which is also a big help when in a limited tty environment.

 

You missed the truly best feature of vim, the i directive.

Say you have this code:

function(foo, bar) {
  // some stuff
}

To select the entire params list, with the cursor in command mode and inside of the params type:

vi(

Now you can copy it or what ever

To select the entire function body

vi{

Better yet, you may want to redefine the param list:

ci(

Which deletes the params and switches you into insert mode

And finally say you are editing some HTML,

<p>Delete this message</p>

You can use:

cit

To clear everything inside of a tag.

 
 

I used to say that I love Vim, but I've started to realize that I actually just love Vim key bindings. Vim as a program is great, but I like to have something my coworkers can put their hands on and not feel scared. It's gotten to the point that I've even tracked down a tamper monkey script to enable Vim keys on glitch.com!

The first thing I do in any new sublime set up is enable "vintage" mode. This allows me to let someone take over the reigns if they're helping me debug, but still use most of the vim comforts.

When I learned it back in college, I remember reading an interesting analogy. It was something like, "Learning Vim is like learning an instrument. At first it feels awkward and frustrating, but after much practice it'll be like an extension of your body." I think almost everyone would love to learn it, but it can be a daunting task. An interactive vim training program/playground could be a cool side project 🤔

 

I've also noticed that my interest in Vim has mostly to do with the key bindings. What I don't want to have to do is dive into the Vim configuration rabbit-hole. Right now I'm enjoying Atom paired with the vim-mode-plus package.

 

As a 20+year vi/vim-user I think I'd like to agree about the key-bindings.

Vim to me is not an IDE, it is an editor with a certain mental model. I use the vim key-bindings in IntelliJ, and indeed do not want to go into the deep configuration rabbithole of vim itself.

My use started at university terminals in the nineties; other students were navigating all across the screen without moving their hands :)

 
 

there is a slight interactive training program -- vim-tutor. It doesn't cover everything, but it is enough to get folks started.

 
 

You forgot to mention some history of Vim... and it's predecessor, vi.

You see, vi was built when terminals themselves weren't quite good enough and the good ones you could run Emacs on were expensive. Yes, I'm talking the DEC VT52's. The ones with good cursor addressing and dedicated commands to do non-destructive movement. Expensive buggers.

No, vi was built for brain-damaged terminals like the Wyse 50. The ones where up and down were defined but left was BACKSPACE and right was SPACE. So putting in a dedicated non-edit mode was worth while back then.

I'm not old enough to have regularly used a Wyse 50. But I'm old enough that I had to work through their legacy at a government transit agency. Yes, I had to deal with a terminal emulation of a Wyse 50 because all the old software was specific to the Wyse 50, and one of the old coders was adamant on using a custom TERMCAP even if the Linux version was even better. The text editors you had to use got cut down to two because of the mandate to use Wyse 50: Vim, or ed.

Needless to say, I'm in private industry now, and I hear that said agency is moving to a different payroll system which would cut out the need for the Linux setup.

 

If you need a command line editor, nano is much more user friendly. I make sure all the command line tools that open a text editor for any reason (like when git wants a merge comment) it opens nano. Vim needs to be left where it came from: the past. #myopinion

 

nano is great in that it is easy to learn, but it also not nearly as powerful.

An example as a sysadmin modifying/working on a log file (columnar data) -- If you want to work on lets say, the first 8 characters of a specific block of text across multiple lines, how would you select only those 8 characters on each of the lines without going one by one in nano? With vim, you have visual block mode, which makes selecting this columnar group easy, and then you can run your command operations on that selection only.

 

I'm an Emacs guy, but I've been experimenting with Vim. I'm not leaving Emacs, but I would like an editor in the terminal that can be made pretty darn useful with a portable dot file. Terminal Emacs is fine for a quick visit, but I wouldn't want to live there. So I'd like to have just some basic Vim literacy. I don't think I'm going to get too crazy with it. And with a few plugins I've already got a decent looking editor in my terminal window. So there you go, a hat tip to Vim.

 

I've used Sublime Text and Atom for a while... and then tried VSCode. That was the final point that made me switch to VIM!

Vim is awesome, the learning proccess is what makes me more excited to use it and I never get bored of it. There's always new tricks, you can program scripts to better your workflow... It's more than my text editor of choice, it's my videogame 😂.

After using Vim for a while, I decided to write quick tips and tutorials for Vim beginners, to help them deal with specific configs and get excited with tricks you can use.

You can check it on medium.com/vim-drops !

Cheers!✌️👨‍💻⌨️👩‍💻✌️

 

Thanks for the article! I'm a beginner in vim and I learned some new commands from your article! I used to think the same too, but then I had so ssh into my amazon ecs server and all I could use was command line and hence vim.

 

The most irritating thing about vim in the first time was 'hell,how do I get out of this programme' . I bet even today if you introduce a new web developer with vim his first reaction will be "how do I close this shit?"

 

Not a bad bit of information for those starting out. There is another shortcut that seems to be regularly overlooked - 'ZZ' -- Shift - z - z -- which roughly maps to :wq! ( the difference is that wq! explicitly writes the file before quitting, ZZ only writes if modified, otherwise it just quits - aka :x for the literal folks )

 

You can also do

:set number relative number

to have line numbers and relative numbers at the same time so you can copy/delete lines of code easier without losing which line you are on in your code :)

 

Nice to see someone discovering the pleasures of VI!
I've used it extensively during 1990-2000 and only very sporadic since.

Here are some movement commands that are still in my fingers;

WBhjklHML0$
(while pressing [ctrl]) fbud

all these works with numbers in front, like this: 9L

 

Thanks Hamza, I believe that all devs should at least know the basics for Vim. You never know when you're going to need to edit a file over SSH on a remote server on nothing but a console.

 

I believe people should know how to "edit a file over SSH on a remote server on nothing but a console", but whatever way they know it doesn't matter so long as it's portable and they're comfortable with it. Using nano, which is nearly as ubiquitous as vim, using sshfs, using rsync or scp to copy the file locally, using sed to change the parts they need in-place... there are loads of ways to do these things where learning one particular technology isn't necessary.

 

Been using vi since 1989 (switching to vim as Linux came to supplant legacy commercial Linux OSes) - could never quite make the leap to other editors that lacked all the power/features that were in my preferred editor (and stubbornly ingrained in my finger-memory). And now that you can get extensions to vim (some that even make it IDE-like), I've even less inclination.

 

The minimum you need to know is

<Esc><Esc><Esc><Esc><Esc><Esc><Esc><Esc><Esc>:q!

or alternatively killall -9 vim

and

export EDITOR=<any other editor>

:)

 

I use ":zz" to save and quit. That is my daily tribute to Zinedine Zidane accomplishments!

 
 

I used vim for few mouths, and I deeply falling in love with it, this is my vim config, as well as tmux and zsh, welcome to reference and exchange.
to-vim-tmux-zsh

 
 

For those who do not yet know: vim-bootstrap.com/ (A generator which provides a simple method of generating a .vimrc configuration for vim)

 

I love vim but I only use it my my server (remote through SSH), with big file vim doesnt have any advantages like visual code and sublime text

 

Off the top of my head:

With big files, it usually opens faster and can be told to run a script on that file such as a saved bit of command history. It runs in the context of your terminal and has access to all your local scripts.

It's obvious advantage vs Sublime Text regardless of file size is that it's free software.

 

No way I'm installing this on my Windows. I use Windows mostly because I want to be the farther the possible from vim. LOL

 

If you NEED to torture yourself in linux console, just use nano

 

Not forget the ":x" in case you want to exit and save the changes.

code of conduct - report abuse