tagbar-phpctags : Vim plugin for PHP developeres


If you are using Vim editor to write PHP code, you probably already know about the excellent tagbar plugin, which lists methods, variables and the like in an optional window split.  Recently, I’ve learned of an awesome phpctags-tagbar plugin, which extends and improves this functionality via a phpctags tool, which has a deeper knowledge of PHP than the classic ctags tool.

Once installed, you’ll have a more organized browser of your code, with support for namespaces, classes, interfaces, constants, and variables.

Vim 8.0 Released!

The team behind the greatest text editor of all times has release the new major version – Vim 8.0.  It’s the first major release in 10 years!  Brief overview of the changes:

  • Asynchronous I/O support, channels, JSON
  • Jobs
  • Timers
  • Partials, Lambdas and Closures
  • Packages
  • New style testing
  • Viminfo merged by timestamp
  • GTK+ 3 support
  • MS-Windows DirectX support

For a more complete list and details, have a look here.

The TL;DR summary: Vim provides a lot more power now to plugin developers, so we’ll be seeing a boost in both new functionality and old ways getting better.

Here is a mandatory Slashdot discussion with your usual Vim vs. Emacs flame.

P.S.: Emacs has recently released a major update too …

How would you write a C program to print 1 to 100 without loop, recursion and goto?

I came across this Quora question today – “How would you write a C program to print 1 to 100 without loop, recursion and goto?”  As always, there is a plethora of answers, of which I liked the following two.

Jonathan Day goes into how the specification can be misinterpreted in a variety of ways, and how garbage in (specification) means garbage out (implementation).  I like it so much, I’m going to quote the whole thing here, so that I can easily find it in the future:

  printf(“1 to 100\n”);

You actually want the numbers, not just that particular string? That’s the problem with poor specifications. Managers have no consideration for us poor programmers…

No loops of any kind, no recursion of any kind, no goto (or comefrom) of any kind… This is the opposite extreme, taking the question absolutely literally as it is given rather than as it might be intended. This would have to include loops, recursion and gotos in all libraries, external programs and even the kernel itself, if taken to this degree.

Which creates a problem. You have to treat all such things as black boxes. You do not know if the kernel parses system calls by looping through the operands. That would be a loop that any printing function must call. The question says nothing about YOU not using loops, it says no loops.

Again, this is why specifications must be exact in programming. Poor specifications will get you what you asked for, but not what you want, just as that code snippet above did. No, I don’t care what was in someone’s mind, nor does the computer. GIGO is the law to which all in IT must obey whether they like it or not. That is why you MUST say what you mean and mean what you say, in positives and negatives.

It’s also why a lot of highly autistic people are highly successful. Literalism is, very literally, in their genes.

Ok, let’s use a third possible interpretation, that you want the numbers 1 through to 100, without the code using loops, recursion or gotos, but where calls may.

Most of the other answers are very acceptable, although some were implicit loops rather than explicit loops. Again, are implicit loops allowed or not allowed, under the specification? The specification simply doesn’t provide enough information to say.

Nor does the specification say if I can use loops, recursion or gotos in generating the data, versus printing it. I could generate the string very easily, just malloc enough space, convert the number into text, then place the characters into the string, with a space or control-linefeed as separator. The print itself is then a single command. Nothing else is needed.

Nothing says if this is a permissible option or not, you have to interpret. And interpretation is not how you should ever program. GIGO.

By loops, I am interpreting this as meaning any sort of iterative process, regardless of formulation. That is the standard meaning. But it occurs to me that repeat/until (while) and until/repeat (do) loops aren’t always seen as loops as they’re conditional on an event. Well, in C, so is a for loop. In many languages, for is fixed-length and so is regarded as a different sort of beast.

Also, the “goto” should be regarded with suspicion. Some languages have deliberately replaced “goto” with “comefrom” to ensure that the language complies with the requirement of not having gotos. I don’t think many SE’s regard that as anything other than slightly snarky humour, but there is no indication in the question as to whether a comefrom command would be disallowed if someone could code it into a header file. This is why sane programmers would interpret the question as prohibiting any form of condition/jump operation, regardless of the nature of the condition or the jump.

This leaves grammars. If the sequence from 1 to 100 can be specified in a grammar, then an external library performs the loop and you can print the result. There’s still iteration, but it’s both implicit and indirect. (When abstraction and black-box design is used to hide things from a boss, it’s time to ask if the boss is suitable for you. These should only ever be used to clarify.)

Ok, nothing in the question specifies a sequence, only the presence of the numbers. Nor does anything specify that numbers can’t appear more than once. So if I use grammars to generate absolutely every permutation of the digits 0 to 9 and a space, then I am guaranteed every number from 0 to 100. There are other regexp functions that let us remove specific patterns, so if I remove all patterns in which one, two or three 0s have a space either side, I can eliminate 0. This just leaves 1 to 100, albeit with a great many single digit and double digit repeats. Repeats aren’t talked about and we’ve already screwed with the interpretation badly enough to make the question pointless, so we assume they’re allowed.

Questions of this kind are usually asked to analyze the methodology of thinking rather than the conclusion itself. They have to be, because the question means so many possible things that it is meaningless. The result you get is, thus, equally meaningless.

And then, this obvious Vim solution by Gilles Castel:

i#include <stdio.h><CR>int main(){<CR>
printf("%d ",1);<ESC>qq0yyp<C-A>q98@qoreturn 0;

Not only he provided the explanation of what’s going on, but also  an animated GIF of how it looks:


And, yes, I’m not really interested in the actual C solutions to this problem.

Vim.js – JavaScript port of Vim

Atwood’s Law – any application that can be written in JavaScript, will eventually be written in JavaScript – seems to be getting more and more traction.  Here is the newest example – Vim.js – a JavaScript port of the popular editor Vim.


This is not a production day-to-day ready software yet, but it’s a good start.  You can check out the project from GitHub and play with the source code.

Global .gitignore

gitignore is a very handy tool for ignoring unnecessary files in the project.   Most large projects have .gitignore file included.  Most small projects would benefit from one too.  However, working as a developer on a variety of projects, it’s often difficult to add your own rules to all .gitignore files around.  And that’s exactly what I wanted.

I’m using Vim editor for all my coding needs, and I wanted to add Vim swap file and backup file to all .gitignore files.  That sounded like annoying, so instead I looked around for a global gitignore solution.  As always, StackOverflow has an answer for everything.  There is a way to disable extra files in Vim, but there is an even better way to have your own global .gitignore.  Here is how to do it:

  1. Edit .gitconfig file in your home folder, and add excludesfile=~/.gitignore line to the core section.
  2. Create .gitignore file in your home folder with whatever rules you desire.

Once that is done, all your projects will ignore the files matching the rules.  If you are not sure which rules to start with, borrow one of the gitignore files from this GitHub project.