Split windows in VIM

In this post I’ll provide an overview of how to split windows in VIM.

Split a window

Splitting an existing VIM window can be performed either horizontally or vertically.

Horizontal window splitting

:sp /path/to/file or :split /path/to/file will split the current window horizontally.

Alternatively you can also use the key stroke combination CTRL+W s to split the current window horizontally. Note: If no path to a file is provided, the current window’s content will be show in the new split window as well.

Vertical window splitting

:vs /path/to/file  or  :vsplit /path/to/file  will split the current window vertically.

Alternatively you can also use the key stroke combination  CTRL+W v  to split the current window vertically.

Closing an existing split window

To close the current split window type the quit command :q.

Moving the cursor from one split window to another

  • CTRL+w [h or left direction key]  move the cursor to the window to the left. E.g. CTRL+w h will move the cursor to the left window.
  • CTRL+w [j or down direction key]  move the cursor to the window below.
  • CTRL+w [k or up direction key]  move the cursor to the window above.
  • CTRL+w [l or right direction key]  move the cursor to the window to the right.
  • CTRL+w w will move to the next bottom/right window, and then top/left when it moves from the bottom/right window. As a result holding down CTRL and repeatedly typing w is an easy way to cycle through all current windows.

Resizing a split window

  • CTRL+w [N+]  Increase the current height by the value of N. If no number is provided for the value of N the height is increased by 1. E.g. CTRL+w 10+  would increase the height by 10.
  • CTRL+w [N-]  Decrease the current height by the value of N. E.g. CTRL+w 10-  would decrease the height by 10.
  • CTRL+w [N>]  Increase the current width by the value of N. E.g. CTRL+w 10>  would increase the width by 10.
  • CTRL+w [N<]  Decrease the current width by the value of N. E.g. CTRL+w 10<  would decrease the width by 10.
  • CTRL+w =  Resize windows equally.
  • CTRL+w |  Maximize the current window’s width.

Reposition a split window

  • CTRL+w H  Move the current split window to the far left position.
  • CTRL+w J  Move the current split window to the far bottom position.
  • CTRL+w K  Move the current split window to the far top position.
  • CTRL+w L  Move the current split window to the far right position.

Extra Help

Want to learn more about splitting windows in VIM? Then check out the help file by typing :h windows.txt.

Advertisements

Quick Tip: How to block a website URL in Linux

If you ever wanted to block access to a URL (for example, perhaps you want to prevent access to a website through a browser), you can accomplish this in an Linux environment by editing the /etc/hosts file. Simply add a new line to the file which includes the localhost address (127.0.0.1) and the URL you wish to block.

e.g.

127.0.0.1 offnadir.wordpress.com

Quick Tip: How to convert a pdf into an image file using ImageMagick

The other day I needed to convert a pdf document into an image file using ImageMagick and here are a few things I learned. Note: The following conversion examples were performed in the Linux terminal but ImageMagick is not limited to a Linux OS.

How to convert a single-page pdf into an image file:

convert file.pdf file.png

How to convert a multi-page pdf into multiple image files:
Note: The following command will output image files where the file names will following the pattern file_pg_#.png. e.g. file_pg_0.png, file_pg_1.png, etc.

convert file.pdf file_pg_%d.png

Additional options:

  • You can replace an alpha background with a white background using the parameters -background white and -alpha remove. See example below.
    convert -background white -alpha remove file.pdf file.png
  • You can change the density of an image (i.e. specify the dots per inch value) using the -density parameter. See example below.
    convert -density 300 file.pdf file.png

Want to learn more about ImageMagick? Check out their site here.

Quick Tip: How to unfreeze your terminal after typing CTRL + s

Every once in a while (usually when my morning coffee hasn’t kicked in yet), I’ll type Ctrl+s to save a document while using vi. Obviously this isn’t how documents are saved in vi, and the result causes your terminal to freeze, becoming completely unresponsive to keyboard commands.

Solution: To unfreeze you terminal after accidentally typing CTRL + s, you simply need to type CTRL + q, and you should now have control of you terminal again.

 

Nunaliit Tutorial: Creating a Module

Modules provide a means to organize the atlas into related content. They can contain a variety of data, and be presented in numerous formats including the use of dynamic maps, canvases, or if you prefer a simple html page containing traditional content like text and media.

The easiest method to create a new module, is to simply copy an existing module and update the id file. The following tutorial will provide instructions on how to accomplish this task.

Basic Structure of a Module:
module.demo/
├── _id.txt
├── nunaliit_module
│ ├── display.json
│ ├── edit.json
│ ├── help.json
│ ├── introduction
│ │ ├── content
│ │ │ ├── en.html
│ │ │ ├── fr.html
│ │ │ └── nunaliit_type.txt
│ │ └── type.txt
│ ├── map.json
│ └── title.json
└── nunaliit_schema.txt

Copying an existing module:

Within the docs directory of your atlas, first locate an existing module which you can copy.  Note: If you’ve just created an atlas, a template for a module called module.demo should be available for copying.

To copy an existing module via the terminal, type the following command (Note: the Unix copy command ‘cp’ requires you to add the ‘-r’ recursive option in order to copy the directory and its contents):

cp -r <the name of the original module directory>
 <the name of the new module directory>

e.g. cp -r module.demo module.testatlas_map

Note: If you’re working in a GUI, you can alternatively copy the directory and paste it with a new name in the docs directory, as you would copy any directory on your OS.

Updating the ID of the new module:

Following the copying of the module, you should now have two modules with different directory names. However you still need to update the id of the new module, so that its different from the original module it was copied from.

Using a text editor, update the _id.txt file (located within the new module directory) with the new module id. The file will consist of a single line of text containing the id of the module. Using the example above the _id.txt file will contain the text ‘module.demo’ and will need to be updated to something else, such as ‘module.testatlas_map’.

Quick Tip: Subversion Change Logs For Files

Yesterday I needed to determine who last edited portions of a file with subversion, and came across a couple great suggestions on stack overflow which I’d like to share here.

Subversion offer a few ways to perform this task, including the following two methods I learned yesterday;

1. The first method returns the log of previous revisions on the file and is ideal when you need to review a more detailed change log.

 svn log --diff filename 

2. The second method is more concise, and only provides the revision number and author name for the last change to a specific file’s line. This approach is performed with the aptly named subcommand blame.

 svn blame filename 

Nunaliit Tutorial: Adding a Schema

What is a schema?:

A schema provides guidelines for Nunaliit in the creation, editing and viewing of documents. They allow atlas builders a means to define what data to collect and how it should be viewed by the user. However, it’s important to note that how a schema is defined shouldn’t be viewed as hard set rules, but rather suggestions of the type of content expected in a document.

By default each atlas provides a demo document schema, a demo comment schema and a demo media schema. These schemas provide a new atlas builders a place to start testing out the functionality of the atlas right away. However, if you continue to use Nunaliit, you will likely need to build your own schema for a specific project. This tutorial provides the steps for creating your own schemas.

Designing a schema definition:

Typically when designing a schema, an atlas builder should first consider what data will be collected, and how to segment it into it’s core components. For example, an atlas which focuses on financial institutions, may contain data on banks, bank staff, bank clients, and transactions. This data can be simplified into three schemas: bank, person, and transaction. Notice that both bank staff and bank clients are merged into a single person schema, since their data will likely contain similar information. See below for an example of the fields needed for these three schemas.

schemadesign

Schema designs for Bank, Person and Transaction schemas.

Add a schema to the atlas:

To add a new schema to the atlas, you will need to run the command ‘nunaliit add-schema –id schemaid’ from the root directory of the atlas (similar to how you would run the update or run commands).

 e.g. ../nunaliit2-couch-sdk-2.2.6/bin/nunaliit add-schema --id bank

This command will create a new schema, which is added to the atlas’ docs folder with the name ‘schema.groupname_schemaid’. Within the new schema’s directory, you will see the required files which define the structure of a schema. Initially these files contain the basic structure of the schema, and will need to be updated to represent the schema design mentioned above.

schemadircontents

List of files within a schema directory

schema.testatlas_bank/
├── brief.txt
├── create.json
├── csvExport.json
├── definition.json
├── display.txt
├── export.json
├── form.txt
├── _id.txt
├── isRootSchema.json
├── label.txt
├── name.txt
├── nunaliit_schema.txt
├── nunaliit_type.txt
└── relatedSchemas.json

Updating the schema’s design can be performed by defining the structure of the schema in the definition.json file. Instructions on how to create defintion.json files, including a complete list of field options, can be found on the atlas builder wiki pages.

Using the schema designs shown above, I’ve included three examples of the definition files for the bank, person and transaction schemas.

Bank Schema Definition:

{
    "group": "testatlas"
    ,"id": "bank"
    ,"label": "Bank"
    ,"relatedSchemas": [ ]
    ,"initialLayers": [ "public" ]
    ,"attributes":[
    {
        "type":"string"
        ,"id":"name"
        ,"label":"Name"
        ,"includedInBrief":true
    }
    ,{
        "type":"string"
        ,"id":"branch_number"
        ,"label":"Branch #"
    }
    ,{
        "type":"string"
        ,"id":"address"
        ,"label":"Address"
        ,"textarea": true
    }
    ,{
        "type":"string"
        ,"id":"phone_number"
        ,"label":"Phone #"
    }
    ,{
        "type": "array"
        ,"elementType":"reference"
        ,"id":"employees"
        ,"label":"Employees"
    }
    ,{
        "type":"checkbox"
        ,"id":"atm"
        ,"label":"ATM location?"
    }
    ]
}

Person Schema Definition:

{
    "group": "testatlas"
    ,"id": "person"
    ,"label": "Person"
    ,"relatedSchemas": [ ]
    ,"initialLayers": [ ]
    ,"attributes":[
    {
        "type":"string"
        ,"id":"name"
        ,"label":"Name"
        ,"includedInBrief":true
    }
    ,{
        "type":"string"
        ,"id":"address"
        ,"label":"Address"
        ,"textarea": true
    }
    ,{
        "type":"string"
        ,"id":"phone_number"
        ,"label":"Phone #"
    }
    ]
}

Transaction Schema Definition:

{
    "group": "testatlas"
    ,"id": "transaction"
    ,"label": "Transaction"
    ,"relatedSchemas": [ ]
    ,"initialLayers": [ ]
    ,"attributes":[
    {
        "type": "reference"
        ,"id":"payer"
        ,"label":"Payer"
    }
    ,{
        "type": "reference"
        ,"id":"payee"
        ,"label":"Payee"
    }
    ,{
        "type":"string"
        ,"id":"amount"
        ,"label":"Amount"
    }
    ,{
        "type":"date"
        ,"id":"date"
        ,"label":"Date"
    }
    ,{
        "type":"string"
        ,"id":"details"
        ,"label":"Details"
        ,"textarea": true
    }
    ]
}

Updating Schemas:
Once the definition.json files are updated with the new schema design structures, you can update the schemas in a number of ways. You can either update each schema individually or you can update all of the schemas at once.

Update a specific schema:

 e.g. ../nunaliit2-couch-sdk-2.2.6/bin/nunaliit update-schema --name testatlas_bank

Note: The name of the schema is typically the groupname_schemaid. If you are unsure of the name of the schema, you should consult the name.txt file within the schema’s directory

Update all schemas:

 e.g. ../nunaliit2-couch-sdk-2.2.6/bin/nunaliit update-schema --all

Updating the Atlas:

The update-schema tool updates each of the files in the schema directory with the newly defined schema’s structure. However these changes won’t be seen in the atlas until the atlas it’s self is updated.

 e.g. ../nunaliit2-couch-sdk-2.2.6/bin/nunaliit update

Following the update of the atlas, you should now be able to use these schemas in your atlas. See a screenshot of the schema form view below.

screenshotofschemadisplay

Nunaliit form view of the Bank schema

Customizing your schema:

Using the add-schema and update-schema tools allows for quick creation and updating of schema documents in Nunaliit. However, you are not limited to the use of these tools. You can edit the files in the schema directory, allowing an atlas builder to customize your schema’s design. Note: If you decided to customize a schema, you will likely want to delete your definition.json file from the schema directory to prevent your custom changes being overwritten accidentally with the nunaliit update-schema –all.