Intro to Vim for no0bs (part 2 of 2)

Welcome to vim part 2

I intend this blog post to be a very basic guide on how to set up Vim on mac (if you’re on another OS the same principles will apply), as well as some very basic vocab plus things you need to understand about Vim and its functionality…(in no0B speak). So again, even if you’re on a different os you will still get a lot out of this.

Step 1. Get Vim

~ You have two options here: neovim or Vim8, I highly suggest that you go with neovim. The creator of the original Vim Bram moolenar, self proclaimed “benevolent dictator for life” refused to add more functionality and refactor the code base. neovim is an open source project with a community behind it, it offers fixes to bugs and things like Asynchronous API’s (plugins). Other than that it’s the same thing, the same plugins that work for vim will work for neovim and vice versa.

If you have Homebrew:

$ brew install neovim

if you don’t have homebrew, here is the curl:

$ curl -LO
https://github.com/neovim/neovim/releases/download/nightly/nvim-macos.tar.gz tar xzf
nvim-macos.tar.gz ./nvim-osx64/bin/nvim

If you’re on a different OS here is the github, instructions are here:
https://github.com/neovim/neovim/wiki/Installing-Neovim

Step 2. zsh configure

~This step isn’t essential but important to me, and that is set up/alias vim in my terminal. All unix operating systems come with Vim8, if you’re on a mac just type into your terminal:

$ vimtutor 

you should get a helpful guide on how to use Vim basics! At any point in your vim career feel free to come back here and practice (To exit this hold down shift and hit: ZQ). Since Vim8 is already on your computer, lets change it so that when you when you type vim (the command to open a file in vim) you pull up neovim (nvim) instead. I am using zsh, so if you’re using bash I believe it is the same but if not, just look up how to alias something.

Lets get started, from the root in your terminal:

$ nvim ~/.zshrc 

This will open your terminal rc file in nvim! (you’re already using vim! don’t panic I am here for you!)
-use hjkl to move
-press i to insert text and start typing, when you’re done press escape to
go back to normal mode.

NOW, from normal mode, type a capital G, (Shift + G) and you should teleport to the bottom of your zshrc. At the bottom, type:

alias vim =’nvim’ 
export EDITOR=’nvim’

Now, exit your zshrc by pressing ZZ (<Shift> + Z + Z), this exits AND saves…You should now be back at your editor, and you’re gonna wanna reload your shell config so enter:

$ . ./.zshrc

If you can now type vim from the terminal and it opens NVIM then you are good to go. If you are having trouble, here is a video of someone doing this very thing (it starts at 2:30):

3. Make a config file (vimrc)

~Vim needs a config file, every-time you fire it up it will look for a special file
and in it will include: all of your plugins (more on that later but by plugin I mean an external modification that you can add to your setup) and custom key remaps etc. Vim8 uses vimrc, but neovim needs you to make a file called init.vim that is in the path of : ~/.config/nvim

So, from the root in your terminal run:

$ mkdir -p .config/nvim

This makes sure you have this little path (it was probably there already!). Note, this path is hidden because of the period so if you try to look for it from your root, the command you need is:

$ ls -a 

or

$ ls -la

Other wise it won’t show up. Now cd into the nvim folder, and check to see if there is a file called init.vim (in the path /.config/nvim/init.vim), If there isn’t then make one with:

$ touch init.vim

Now open your init.vim file in vim with:

$ vim init.vim

If it opens, in nvim, congrats this will be your config file! (If not check out the video above)

4. Get a plug manager

The plugin manager will go to the plugins you specify (githubs with the mods, anyone can write one), and grab them. You will make a function that lives in your init.vim you specify I use Vim-plug, here is the git hub: https://github.com/junegunn/vim-plug

So what you have to do:

go back to your path: ~./config/nvim and from here make a directory called autoload

$ mkdir autoload 

SO, you should have a path that is /.config/nvim/autoload…. We need to download the plug manager in your autoload directory, so. cd into autoload and paste:

curl https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

give it an ls -la when it’s done and if you see a plug.vim (among some other stuff) you are in business. If any of steps 2–4 got confusing, the man in the video above will do all of this so just check that out

5. Grab some plugins

From here I am going to just give you premium dotfiles, they are Kyle Coberly’s (to which I owe my entire vim career to, so thank you kyle…)

Go to his git hub:

https://github.com/kylecoberly/dotfiles/blob/master/dotfiles/.vimrc

  • Click on raw at the top right of the code box
  • Highlight it all and copy it (command + v)
  • Open your init.vim in vim (vim init.vim) and type:
“*P 

This command should paste everything from your system clipboard into clipboard into your init.vim file

  • type :w and hit enter -type
  • :PlugInstall and hit enter, some stuff should happen, after hit q. then (<shift> + ZZ)
  • open your vim init fill back up and it should be completely different.

Notice your plug function at the top there the syntax goes like:

Plug ‘tpope/vim-surround’

the ‘tpope/vim-surround’ is a github link for that specific plugin! if you go to:

https://github.com/tpope/vim-surround

You will get details on what this plugin does and hot to use it! Just know that to get a plugin, all you need to do is put its github in the Plugin function, save the file (:w) and run :PlugInstall. If you want to do something in Vim that is’nt default, there is probably a plugin for it.

I would also suggest ranger, you can just type

$ brew install ranger 

from the root and be good to go. When your at a directory, type in ranger and you should be able to visually move thru your files like a GUI, but when you arrive at one, it will open up in Vim

As far as learning commands I would point you again to the Primeagen:

his philosophy is, learn these basic commands:
w b h j k l y p d dd v V :w (<shift> + ZQ) (<Shift + ZZ>) <esc>

make sure you have them down pat! When you’re annoyed and want to learn more, lean into that and learn more! (Also look into tmux)

GOOD LUCK!!!!

A Fullstack Web Dev-arino, part time ‘cool guy’. My website is https://jacksanders.xyz