Best Vim

Let’s learn the top 20 best Linux Vim commands that you must know to gain amazing levels of productivity. Remember, the VIM text editor has a pretty steep learning curve. But once you put in the time to get used to the commands, you will attain unmatched productivity in your day-to-day tasks that require working with text (perfect text-editor. Vim is a modal text editor, which means that it has a mode for writing text, a mode for running commands, etc. Vim has a total of 12 different editing modes. The three main modes are.

  1. Best Vim Themes
  2. Best Vim Books
  3. Best Vimeo

spf13 presents

spf13-vim is a distribution of vim plugins and resources for Vim, GVim and MacVim.
It is a completely cross platform distribution that stays true to the feel of vim while providing modern features like a plugin management system, autocomplete, tags and tons more.

  • Featured Plugins
  • Other Awesome stuff
  • Community
spf13-vim

Easy Installation *nix and os x

The easiest way to install spf13-vim is to use our automatic installer by simply copying and pasting the following line into a terminal. This will install spf13-vim and backup your existing vim configuration.

If you are upgrading from a prior version (before 3.0) this is also the recommended installation.

Updating to the latest version

Installing on Windows

On Windows and *nix Git and Curl are required.

Installing dependencies

Install msysgit

After installation try running git --version within command prompt (press Win-R, type cmd, press Enter) to make sure all good:

Setup Curl

Instructions blatently copied from vundle readmeInstalling Curl on Windows is easy as Curl is bundled with msysgit!But before it can be used with Vundle it's required make curl run in command prompt.The easiest way is to create curl.cmd with this content

And copy it to C:Program FilesGitcmdcurl.cmd, assuming msysgit was installed to c:Program FilesGit

to verify all good, run:

Installing spf13-vim on Windows

The easiest way is to download and run the spf13-vim-windows-install.cmd file.

The .vimrc file is suited to programming. It is extremely well organized and folds in sections. Each section is labeled and each option is commented.

It fixes many of the inconveniences of vanilla vim including

  • A single config can be used across Windows, Mac and linux
  • Eliminates swap and backup files from littering directories, preferring to store in a central location.
  • Fixes common typos like :W, :Q, etc
  • Setup a solid set of settings for Formatting (change to meet your needs)
  • Setup the interface to take advantage of vim's features including
    • omnicomplete
    • line numbers
    • syntax highlighting
    • A better ruler & status line
    • & more
  • Configuring included plugins

Customization

Create ~/.vimrc.local and ~/.gvimrc.local for any local customizations.

For example, to override the default color schemes:

Vundle The best plugin manager

Vundle is an excellent system built on the same principles as Pathogen, but with an integrated plugin management system that is Git and Github aware.

spf13-vim uses the Vundle plugin management system to have a well organized vim directory (Similar to mac's app folders). Vundle also ensures that the latest versions of your plugins are installed and makes it easy to keep them up to date.

NERDTreefile navigation

Best vimeo downloader

NERDTree is a file explorer plugin that provides 'project drawer' functionality to your vim editing. You can learn more about it with :help NERDTree or checkout my post on NERDTree.

QuickStart Launch using <Leader>e.

Customizations:

  • Use <C-E> to toggle NERDTree
  • Use <leader>e or <leader>nt to load NERDTreeFind which opens NERDTree where the current file is located.
  • Hide clutter ('.pyc', '.git', '.hg', '.svn', '.bzr')
  • Treat NERDTree more like a panel than a split.

ctrlpfast file finder

Ctrlp replaces the Command-T plugin with a 100% viml plugin. It provides an intuitive and fast mechanism to load files from the file system (with regex and fuzzy find), from open buffers, and from recently used files.

QuickStart Launch using <c-p>.

Surroundmanaging all the '[{}]' etc

This plugin is a tool for dealing with pairs of 'surroundings.' Examples of surroundings include parentheses, quotes, and HTML tags. They are closely related to what Vim refers to as text-objects. Provided are mappings to allow for removing, changing, and adding surroundings.

Details follow on the exact semantics, but first, consider the following examples. An asterisk (*) is used to denote the cursor position.

For instance, if the cursor was inside 'foo bar', you could type cs' to convert the text to 'foo bar'.

There's a lot more, check it out at :help surround

NERDCommentercomment++

NERDCommenter allows you to wrangle your code comments, regardless of filetype. View help :NERDCommenter for all the details.

QuickStart Toggle comments using <Leader>c<space> in Visual or Normal mode.

Syntasticintegrated syntax checking

Syntastic is a syntax checking plugin that runs buffers through external syntax checkers as they are saved and opened. If syntax errors are detected, the user is notified and is happy because they didn't have to compile their code or execute their script to find them.

numbers.vimbetter line numbers

Best Vim Themes

This plugin will alternate between relative numbering (normal mode) and absolute numbering (insert mode) depending on the mode you are in. This allows you to easily move code around with the relative line numbers when in normal mode. As well as providing accurate line numbers when writing code in insert mode

Vim

neocomplcacheautocomplete++

NeoComplCache is an amazing autocomplete plugin with additional support for snippets. It can complete simulatiously from the dictionary, buffer, omnicomplete and snippets. This is the one true plugin that brings Vim autocomplete on par with the best editors.

QuickStart Just start typing, it will autocomplete where possible

Customizations:

Best Vim
  • Automatically present the autocomplete menu
  • Support tab and enter for autocomplete
  • <C-k> for completing snippets.

Fugitive deep git integration

Fugitive adds pervasive git support to git directories in vim. For more information, use :help fugitive

Use :Gstatus to view git status and type - on any file to stage or unstage it. Type p on a file to enter git add -p and stage specific hunks in the file.

Use :Gdiff on an open file to see what changes have been made to that file

QuickStart<leader>gs to bring up git status

Customizations:

  • <leader>gs :Gstatus
  • <leader>gd :Gdiff
  • <leader>gc :Gcommit
  • <leader>gb :Gblame
  • <leader>gl :Glog
  • <leader>gp :Git push
  • :Git ___ will pass anything along to git.

PIV PHP editing

The most feature complete and up to date PHP Integration for Vim with proper support for PHP 5.3+ including latest syntax, functions, better fold support, etc.

PIV provides:

  • PHP 5.3 support
  • Auto generation of PHP Doc (,pd on (function, variable, class) definition line)
  • Autocomplete of classes, functions, variables, constants and language keywords
  • Better indenting
  • Full PHP documentation manual (hit K on any function for full docs)

Tabularize align everything

Tabularize lets you align statements on their equal signs and other characters

Customizations:

  • <Leader>a= :Tabularize /=
  • <Leader>a: :Tabularize /:
  • <Leader>a:: :Tabularize /:zs
  • <Leader>a, :Tabularize /,
  • <Leader>a<Bar> :Tabularize /

Tagbartag generation and navigation

spf13-vim includes the Tagbar plugin. This plugin requires exuberant-ctags and will automatically generate tags for your open files. It also provides a panel to navigate easily via tags

QuickStartCTRL-] while the cursor is on a keyword (such as a function name) to jump to it's definition.

Customizations: spf13-vim binds <Leader>tt to toggle the tagbar panel

Note: For full language support, run brew install ctags to install exuberant-ctags.

Tip: Check out :help ctags for information about VIM's built-in ctag support. Tag navigation creates a stack which can traversed via Ctrl-] (to find the source of a token) and Ctrl-T (to jump back up one level).

EasyMotionjump anywhere

EasyMotion provides an interactive way to use motions in Vim.

It quickly maps each possible jump destination to a key allowing very fast and straightforward movement.

QuickStart EasyMotion is triggered using the normal movements, but prefixing them with <leader><leader>

For example this screen shot demonstrates pressing ,w

Adding Your Own Bundles

Best vimeo videos

Create ~/.vimrc.bundles.local for any additional bundles.

To add a new bundle

Custom Settings

Create ~/.vimrc.local and ~/.gvimrc.local for any local customizations.

For example, to override the default color schemes:

Additional Syntaxes

spf13-vim ships with a few additional syntaxes:

  • Markdown (bound to *.markdown, *.md, and *.mk)
  • Twig
  • Git commits (set your EDITOR to mvim -f)

Amazing Colors

spf13-vim includes solarized and spf13 vim color pack:

  • ir_black
  • molokai
  • peaksea

Use :color molokai to switch to a color scheme.

Snippets

It also contains a very complete set of snippets for use with snipmate or NeoComplCache.

Tutorials

  • Type vimtutor into a shell to go through a brief interactive tutorial inside VIM.
  • Read the slides at VIM: Walking Without Crutches.

Modes

  • VIM has two (common) modes:
    • insert mode- stuff you type is added to the buffer
    • normal mode- keys you hit are interpreted as commands
  • To enter insert mode, hit i
  • To exit insert mode, hit <ESC>

Useful commands

  • Use :q to exit vim
  • Certain commands are prefixed with a <Leader> key, which by default maps to .
  • Spf13-vim uses let mapleader = ',' to change this to , which is in a consistent and convenient location.
  • Keyboard cheat sheet.

Mailing List
Be notified of major updates

Discussion Group
Discuss issues, ideas, plugins

Contributing
GitHub makes for easy contribution

All development is done via GitHub. Fork and issue a pull request or file an issue.

Hot tips to bring the awesomeness of Visual Studio Code to Vim.

Front-Matter

I want to start by saying, this is not an editor-shame article. You can use whatever text editor you want. It really doesn’t matter. I’m only writing this because I found a level of productivity in Vim that I haven’t had in any of the editors I used before (Sublime Text, Atom or VSCode).

If you’ve heard about Vim, and want to try it out, I hope this article can provide a bit of familiarity you’d find from VSCode.

Why Vim?

Best Vim Books

There are lots of reasons to use Vim, so here’s a few of mine.

Keep your hands at 10 and 2

When you are solely using the keyboard, there is going to be an inherent speed boost just from not having to physically move your hands. And hey, maybe you’re a black belt in mouse movement, and you can move back in forth with a speed invisible to the naked eye. For the rest of us simple humans, it takes time.

Let’s do some quick math.

It takes 600ms to move my hand from the “home keys” to the mouse. On average, for sake of argument, I do that once a minute while I’m writing code. Whether that be to scroll, navigate to a new file, or something similar.

600 (wasted time in ms) x 60 (times per hour) x 5 (hours I am actually coding) = 180,000ms wasted =

3. Minutes. Every. Day.

Yeah, okay, maybe that doesn’t sound so bad, but, those 3 minutes could be spent writing a function, or refactoring code, not flailing your hand about like you're Harry Potter!

Speed

My favorite quote that describes what it’s like to code in VIM:

“Code at the speed of thought”

Vim is built around the idea that you are directly communicating with your computer. You tell it what you want, and it does it for you. The biggest eye-opener for me was this little tidbit:

Best Vimeo

To delete everything in between two objects (parentheses, quotes, etc), it's as simple as:

di'

That’s just the surface of amazing shorthand things you can do with Vim.

I’m a real programmer!

Part of the journey of learning VIM is exposing yourself to how UNIX works. I’m under the impression that the more you expose yourself to things like bash, the better programmer you are going to be.

Chances are, you have a pretty sweet command line setup. Wouldn’t it be nice if your code editor and your command line worked in concert?

How do you exit Vim?

Probability is high that you’ve ever edited a file on a Linux server, and couldn’t figure out how to exit the file. Let’s say, for example, changing an SSH key on Digital Ocean. If you know VIM…you don’t have to worry about that!

The real reason I switched to Vim

Honesty time. The real catalyst for wanting to switch to Vim was watching Kyle Mathews (creator of Gatsby.js) using it during a demo.

VS Code Features and their equivalents

Convinced? Cool, here’s some tools!

Plugin System

Vim by itself is pretty barebones. In order to add plugins, we have to have a mechanism to manage them. Enter Plug:

Note: There are a few plugin managers out there. I landed on Plug for no particular reason. I like it, and I’ve had no issues with it. FYI, Vundle is deprecated.

File Search

There has been a bunch of solutions for file searching over the years, as indicated by the multitude of answers in forums. I tried a couple of different ones, but landed on this combination:

Fuzzy Finder(fzf) + Ripgrep

Fzf is a really well built/maintained fuzzy search that works in both the command line and vim.

Note: You may see Ag(Silver searcher) in a lot of articles, however the Ag related vim plugin is no longer maintained, so it's suggested to use RipGrep.

Intellisense

The auto-completion system (Intellisense) in VSCode is arguably its best feature. Lucky for us, it’s been ported over to Vim!

CoC has its own extension system, that mirrors that of VSCodes. It's easy to use and well-documented (the most important part).

Note: You may see some old articles talking about YouCompleteMe, but as far as I can tell, that isn’t maintained anymore.

File System Explorer

VSCode, like most modern text editors, comes with a file explorer. Vim’s native netrw is alright, and I’ve seen quite a few articles saying you don’t need anything else, like here. However, I find NERDTree is too useful to not use.

Git integration

I gotta be honest here, I do most of my git stuff straight in Iterm. However, VSCode has an incredibly nice Git Diff split screen. To get that level of git integration, check out this plugin:

Additional plugins that you may want

This is some of the stuff I used in Visual Studio Code, that I wanted to bring into Vim.

Autocomplete Brackets

This nice little package will auto close those pesky brackets.

File Icons

This will add icons to stuff like NERDTree.

Prettier

Wouldn’t you know it, but the official prettier team has a vim plugin. How nice! Also, incredibly simple to set up.

Get it to work on autosave, check out this article.

Snippets

Wouldn’t you know it, using the Conquer of Completion, you can import VSCode snippets!

Check this out to show you how to do that:

Here is the React snippets package I’m using.

Additional Stuff

THE home for Vim plugins is Vim Awesome.

Great place to watch people use Vim:

Dotfiles

I have a few remapped keys to make things easier. Check out my dotfiles for all those.

Final Thoughts

My Journey

I solely use Vim now, after spending about a year to learn it. Initially, I was using it just for my personal projects, because my productivity level was low. I had to keep stopping to look up how to do something. However, I dropped VSCode completely about 4 months ago, and I don’t plan on going back.

It takes discipline

Learning Vim can seem daunting, and frankly, it is. It requires self-imposed discipline. However, doesn’t everything in development? There is no tool/language/framework I’ve ever learned that didn’t require some level of deliberate practice.

Vim is a lifestyle choice. It will take a while to get used to it, and it WILL be frustrating at times. However, if you stick to it, I guarantee it’ll improve your workflow. If you have any additional tips or questions, please drop them below. As always, happy coding!

Additional Resources for learning

References