Numbered Marks in Vim

Numbered marks are '0 to '9. Unlike normal marks, these cannot be set directly. Instead, '0 refers to the cursor position before Vim was exited. '1 returns the cursor position during the Vim session before that, and so on.

Read more about marks.

Tags: vim

Difference of ^ and _ in Vim

In vim, both ^ and _ can be used to move to the first non-blank character of the line.

However, ^ doesn’t work with motion. This mean that 3^ doesn’t move to the non-blank character of the third line. It ignore the motion and only move to the non-blank character of the first line.

Consider that your cursor is at this position:

* This is the first line
            -
* This is the second line
* This is the third line

with 3^, the cursor will move to the first non-blank character of the first line:

* This is the first line
-
* This is the second line
* This is the third line

However, with 3_, since it works with motion, the cursor will move to the first non-blank character of the third line:

* This is the first line
* This is the second line
* This is the third line
-

For more details, refer to :help _ and :help ^ when using vim.

Tags: vim

Effective Cursor Moving in Vim

Aside from the usual w, we can use W to navigate between words.

For instance, it would take a lot repetitive w keys to reach &&:

dispatch(GeosActions.getSegmentationRequest(request)) && ...
-
dispatch(GeosActions.getSegmentationRequest(request)) && ...
        -
dispatch(GeosActions.getSegmentationRequest(request)) && ...
         -
dispatch(GeosActions.getSegmentationRequest(request)) && ...
                    -

However, it only takes one W key to reach it:

dispatch(GeosActions.getSegmentationRequest(request)) && ...
_
dispatch(GeosActions.getSegmentationRequest(request)) && ...
                                                      _

The uppercase versions of e and b are also useful.

See all the right moves.

Tags: vim

Indexing `NULL` in Oracle Database

Oracle database does not index of a row if all the indexed columns are NULL

For instance, let say we have a users table where we index role column to improve the query performance.

SELECT * from users WHERE role IS NULL

The index does not work for such query in Oracle database. This is because when Oracle database inserting the new record of user where the role is NULL, it does not add the created row to the index. Hence, the index is not useful when querying with NULL

Solutions

Use a constant expression that can never be NULL.

CREATE INDEX users_role ON users (role, 'user')

or we can use a concatenated index (multi-column index) and ensure that the the other column of the index must haveNOT NULL constraint.

CREATE INDEX users_role ON users (role, id)

For more detailed explanation and source, refer to NULL in Oracle Database

Using `form_for` in Phoenix without `Ecto.Changeset`

form_for expect the first argument to be any data structure that implements the Phoenix.HTML.FormData protocol. Phoenix implements this protocol for Plug.Conn. Hence to create form not backing by any data layer:

<%= form_for @conn, to: Routes.search_path(@conn, :new) do |f| %>
  ...
<% end %>