(Neo)Vim as php editor

As a PHP developer and efficiency addict, I constantly aim towards a better workflow.

About half a year ago I got very enthusiastic about VIM..

The workflow

I like the idea to not use a cursor at all. It helps you to focus more on what you are doing. I never recorded it, but you might be amazed by the time you spend on a daily base with your hand on your mouse. Not including the travel from your keyboard towards it.

In my current workflow I still depend on my mouse, a lot.. It is a tool that helps me access things I am not capable of accessing by keyboard, not because it is impossible by design, but because I do not have the skill yet.. It takes time. And every day I get a little bit better.

As os I use Manjaro, but in the i3 flavor. Please read about them, and especially i3wm as it could also improve your workflow. There are more alternatives to I3 available for linux, awesomewm just to give an example, is also one of the bigger tiling window managers out there.

Also for other operating systems (with the exception of windows), there are tiling window managers available.

One last tip for a keyboard only workflow: use Vimium on Google chrome to avoid using your mouse.

The tools

Now back to development.. We all have our favorite tool, and we should respect that. There is no point in trying to force someone into using a text editor, vim or a php IDE like Phpstorm.. The developer should always be able to choose what he wants, simply because that makes him happy, confident and self aware of what he can, and all that results into an efficient developer.

My current main editor remains Phpstorm with ideaVim, here is the reason why:

  • It still has the best code completion (intellisense) available in the world of PHP.

Short list, I know, but that is the only reason I am still using Phpstorm.

A few things I like about vim:

  • Requires no mouse
  • Runs in your terminal
  • Runs EXACTLY the same on each OS
  • Very low on resources ...

A short word about vim and neovim: They are quite the same in use, but Neovim is asynchronous which makes it faster on most levels. vim 8.0 should be asynchronous as well but I never tried.

Now to make vim really comparable to an IDE like Phpstorm we have to configure it properly. There are some great plugins available that can help you with that.

The vim config

I will list not all of the plugins that I am using, you can use my vimrc file as a reference.

The most important ones:

Nerdtree:

It is always easy to get a view on your working directory. When using vim it's easy to start working on a directory instead of a file. Just run vim . in the workign directory instead of directly opening files.

Nerdtree tabs will help you to manage your window a bit better.

ctrlp:

We all know the concept, in phpstorm it is Shift+Shift, in atom and Sublime it is CTRL+p. ctrlp Is a fuzzy finder, it allows you to quickly open a file from your working directory.

php.vim:

To take care of your php syntax highlighting.

vim-sleuth:

The brain behind your project.. It detects indentation settings, and automatically applies them. You need this especially when working on multiple projects with different indentation settings.

vdebug:

It is 2017, it's pretty hard to develop a php application without the ability to debug. vdebug works with Xdebug!

vim-test:

Another important feature for me is the ability to execute tests while I am working on the file. vim-test is the plugin to rule them all. You can run where your cursor is, you can run what you ran last etc..

tagbar:

The tagbar plugins shows you a short tree of what is in your current file, to give an example: It shows you all the method names in a class, all variable assignments... You can just hjkl onto the right function to directly navigate towards it. The screenshot will show this better.

LanguageClient-neovim:

Kept last as it is not yet good enough.. This plugin is the bridge between language protocol and Vim. It's under very rapid development and will surely at some day be able to fix the only missing part in vim (for me at least).

The plugins above more or less give your full php-ide capabilities withing your terminal text editor. While it is not the ideal setup yet, it is refined enough for a proper daily workflow (given that the autocomplete is working).

Apart from a full keyboard workflow, working with an editor as simple as vim gives you a better code overview. You will know more because you rely less on your editor.

Here is a screenshot of my current vim setup.