Convert PIL or Numpy Image to Bytes without Saving to Disk


Sometimes, we want an in-momery jpg or png image that is represented as binary data. But often, what we have got is image in numpy ndarray or PIL Image format. In this post, I describe how to convert numpy image or PIL Image object to binary data without saving the underlying image.

Fast Movement and Navigation Inside Vim or Neovim


One key spirit of Vim is to accomplish something in as fewer key strokes as possible. When you repeat a command a few times in order to perform an action, you need to ask yourself if there is a better way to do it. Only in this way, can you make progress in mastering Vim. For example, when your want to delete five lines of texts, if you press dd five times, you are certainly doing it the wrong way. After looking up the Vim manual, you know that you can use 5dd or d4j: you only need three keystrokes instead of ten!

The other day, I saw a post in a forum asking for help on how to quickly move the cursor inside a buffer. After using Neovim for nearly a year, I would like to share what I have learnt about fast movement and navigation inside Neovim/Vim.


6.18 快到了,加上在家里使用的 IKBC C87 青轴声音太大,敲击费力,所以动了换一把更加静音,触发力度更小的键盘的心思。在京东和淘宝上入手了多款键盘试用,不得不说,一把好的键盘真的是难选啊。自从去年双十一入手了一把 Leopold 红轴键盘以后,其他的键盘真的很难入我的眼睛了。试用过的几把键盘以及感受如下:

Exclusive and Inclusive Motion in Neovim


Suppose that we have the following text in normal mode (cursor is indicated by |):

|hello world

if we use dw, we delete hello<Space>1 and only world is left; if we use de, hello is deleted and <Space>world is left. Have you ever wondered about why dw do not delete w while de will delete the o in hello? It seems that the motion e and w are somewhat inconsistent. It turns out that this has something to do with the exclusivity of motions in Vim.

Vim-like Editing inside Browser

Neovim has powerful ability in editing texts. But if you are in a browser and want to input some text, can we somehow utilize the editing power of Vim? In this post, I would like to share several ways to use Vim or Vim-like editing when you are working inside a browser.

Create Mappings Which Take A Count in Neovim

Many normal mode commands accept a count, which means to repeat the motion count times. For example, 3j moves the cursor 3 lines below the current line and 4w will move the cursor four words forward. Usually, the user-defined mappings can not take a count. Even if they can, they will most probably not work the way you expect them to. In this post, I will describe what I have learned to make a fairly complex mapping repeatable with a count.

How to Use Python Inside Vim Script with Neovim


I have been using Vim-airline for a while to customize my statusline. We can change the theme used for statusline with the many themes available in vim-airline-themes. Not all these themes looks good since it depends on the background color you use for Neovim and certainly your aesthetics.

I only use a handful of themes myself and I change my themes when I feel bored with one theme. It occurs to me that I can write a simple script to randomly pick a theme from my favorite list1. It turns out writing such a script is not easy for Neovim newbies like me.

In this post, I would like to share how I end up achieving what I want by mixing Vim script and Python script.

Using Snippets in Neovim with Ultisnips

If you have used Sublime Text before, you may be familiar with the snippet function. Snippets let you input a trigger word and expand the trigger to some boilerplate code or string you do not want to repeat each time. You will increase your efficiency dramatically with the help of snippets.