Archive for February, 2017

How to format JSON in VIM/GVIM

Thursday, February 23rd, 2017

The strength and beauty of VIM is the simple interaction with lots of external programs.

To format any JSON file in VIM/GVIM:

:% !jq .

% means the file you’re working on, and `!jq` is run the external command `jq`

That’s all.

You need to have `jq` installed:
sudo apt install jq
whatis jq
jq (1) - Command-line JSON processor

The ease and beauty of VIM

Friday, February 3rd, 2017

Never thought that I would write a post with the ease of VIM in the title. But honestly I tried a lot of editors still coming back to VIM. VIM is a lot more hackable then Atom.

Probably because I like bash, python and javascript, while Atom is javascript hackable only.

VIM is not easy at first sight, and certainly not easy at first touch. Counterintuitive to the noob, all the difference modes VIM can be in, you somehow love it after a while.

Try the VIM editor

If you’re interested just try it out.
apt install vim

Run vimtutor after you installed VIM. I surely recommend the great VIM casts, of Drew Neil. Excellent learning stuff. Best to watch after you installed VIM and tried the VIMTutor.

Back to the title, the ease of VIM for productivity. Sure you need to extend it and use plugins. UltiSnips is one of my favorite.

Use snippets with UltiSnips

A good setup of snippets are a real time saver. There are pre-installed snippets, but you need to setup your own snippets, because they reflect how you think, and they should suit into your workflow.

For testing sites on Apache, or protecting a WordPress login from, you often use access control,  to restrict access to portions of your site based on the host address of your visitors.

You create a Deny Allow directive  for that in .htaccess.

order deny,allow
deny from all
allow from [your-ip]

Create a deny allow snippet

To speed up inserting earlier code in any .htaccess file your editing in VIM/GVIM, create a apache.snippets file in your UltiSnips directory (~/.vim/UltiSnips by default), and add this to the file:

snippet deny "Deny allow snippet" b
order deny,allow
deny from all
allow from `curl ipinfo.io/ip`
endsnippet

Done, every time you type `deny` hit tab and the snippet is inserted with the ip-address of the computer you’re working on. Through  `bash interpolation`, the snippets insert the output of the command `curl ipinfo.io/ip` which is the linux way of getting your ip-adress. Compare that to Microsofts Windows way. Never say again that Linux is not easy.

So, easy after all, isn’t it? That’s why I call VIM easy. Of course it isn’t actually, but there is beauty in the way it works, and the way you can make it work, fast en easy.

Your are browsing
the Archives of My Beloved PHP for February 2017.
Categories
Archives
Links