Showing posts with label Installation. Show all posts
Showing posts with label Installation. Show all posts

Monday, April 6, 2015

Day 3: VIM Powerful Text Editor


The most import piece of software for a  programmer (the way I see it) is a proper text editor. Almost all I plan on doing will involve working with text (editing, formatting etc.). 


I love arcane and powerful tools, so my editor of choice is going to be: VIM.


VIM does not come with the Raspbian Linux distribution. When I issue the command 'vim' I am getting error: "-bash: vim command not found". It's not a big deal. 
Software installation in Linux is trivial.



Command that installs VIM is:

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install vim

A moment later (be patient as many dependencies must be installed with VIM), VIM is ready to go.

Since my journey with Raspberry PI will be primarily focused on learning how to code in Linux (Bash, C, Python etc.) I am going to set up VIM editor what others suggested: 

$ cd ~
$ vim .vimrc

(The command 'cd ~' (this twiggly thing is called tilde, pronounced TILL duh) represents your /home/username directory. It will move you to your home directory context).

Adding the following settings will make VIM work better for a developer (the double quote character acts as a comment in .vimrc setting file and as such will be ignored by vim text editor):

" Turn on line numbering

set number  

" Set tab display to 4 characters

set tabstop=4

" softtabstop controls how many columns to insert on tab

" If softtabstop = tabstop, vim uses spaces
set softtabstop=4

" When expandtab is set, hitting Tab produces appropriate

" number of spaces specified by softtabstop
set expandtab

" Shiftwidth controls how many columns text is indented

" with autoindent operation
set shiftwidth=4

" Set autoindentation helpful in programming lang like python

set autoindent

The below stuff is to be learned gradually not all at once. Alternatively, simpler text editor can be used such as nano (or in GUI gedit).


VIM Most Commonly Used Options:

Insert mode - inserting/appending text

i - insert before the cursor
I - insert at the beginning of the line
a - insert (append) after the cursor
A - insert (append) at the end of the line
o - append (open) a new line below the current line
O - append (open) a new line above the current line
ea - insert (append) at the end of the word
Esc - exit insert mode

Cursor movement

h - move cursor left
j - move cursor down
k - move cursor up
l - move cursor right
w - jump forwards to the start of a word
W - jump forwards to the start of a word (words can contain punctuation)
e - jump forwards to the end of a word
E - jump forwards to the end of a word (words can contain punctuation)
b - jump backwards to the start of a word
B - jump backwards to the start of a word (words can contain punctuation)
0 - jump to the start of the line
^ - jump to the first non-blank character of the line
$ - jump to the end of the line
G - go to the last line of the document
5G - go to line 5

Editing
r - replace a single character
J - join line below to the current one
cc - change (replace) entire line
cw - change (replace) to the end of the word
c$ - change (replace) to the end of the line
s - delete character and substitute text
S - delete line and substitute text (same as cc)
xp - transpose two letters (delete and paste)
u - undo
Ctrl + r - redo
. - repeat last command

Marking text (visual mode)

v - start visual mode, mark lines, then do a command (like y-yank)
V - start linewise visual mode
o - move to other end of marked area
Ctrl + v - start visual block mode
O - move to other corner of block
aw - mark a word
ab - a block with ()
aB - a block with {}
ib - inner block with ()
iB - inner block with {}
Esc - exit visual mode

Cut and paste

yy - yank (copy) a line
2yy - yank (copy) 2 lines
yw - yank (copy) word
y$ - yank (copy) to end of line
p - put (paste) the clipboard after cursor
P - put (paste) before cursor
dd - delete (cut) a line
2dd - delete (cut) 2 lines
dw - delete (cut) word
D - delete (cut) to the end of the line
d$ - delete (cut) to the end of the line
x - delete (cut) character

Exiting

:w - write (save) the file, but don't exit
:wq or :x or ZZ - write (save) and quit
:q - quit (fails if there are unsaved changes)
:q! or ZQ - quit and throw away unsaved changes
:xa - save and quit all split windows (buffers)

Marking text (visual mode)
v - start visual mode, mark lines, then do a command (like y-yank)
V - start linewise visual mode
o - move to other end of marked area
Ctrl + v - start visual block mode
O - move to other corner of block
aw - mark a word
ab - a block with ()
aB - a block with {}
ib - inner block with ()
iB - inner block with {}
Esc - exit visual mode

Visual commands

> - shift text right
< - shift text left
y - yank (copy) marked text
d - delete marked text
~ - switch case

Search and replace
/pattern - search for pattern
?pattern - search backward for pattern
n - repeat search in same direction
N - repeat search in opposite direction
:%s/old/new/g - replace all old with new throughout file
:%s/old/new/gc - replace all old with new throughout file with confirmations

Working with multiple files

:e filename - edit a file in a new buffer
:bnext or :bn - go to the next buffer
:bprev or :bp - go to the previous buffer
:bd - delete a buffer (close a file)
:sp filename - open a file in a new buffer and split window
:vsp filename - open a file in a new buffer and vertically split window
Ctrl + ws - split window
Ctrl + ww - switch windows
Ctrl + wq - quit a window
Ctrl + wv - split window vertically
Ctrl + wh - move cursor to next buffer (right)
Ctrl + wl - move cursor to previous buffer (left)

Tabs

:tabnew filename or :tabn filename - open a file in a new tab
Ctrl + wt - move the current split window into its own tab
gt or :tabnext or :tabn - move to the next tab
gT or :tabprev or :tabp - move to the previous tab
#gt - move to tab number #
:tabmove # - move current tab to the #th position (indexed from 0)
:tabclose or :tabc - close the current tab and all its windows
:tabonly or :tabo - close all tabs except for the current one

Now, with this cheat sheet at hand, I am ready to rock and roll! Next posts will be all about coding using different tools.


Saturday, April 4, 2015

Day 1: Installation



Download the Linux image for Raspberry Pi (I use Raspbian)


https://www.raspberrypi.org/downloads/

Raspbian-Download-Page
Raspbian Download Page

Then follow the installation instructions:

Windows users

Linux Users

Since I use Linux to image the SD card, so this is what it is going to look like:

1. Checksum check if the file is intact.

sha1sum 2015-05-05-raspbian-wheezy.zip
cb799af077930ff7cbcfaa251b4c6e25b11483de

Compared with the number on 'download' page and the digest value is the same.

2. Check how my system detects sd card. 

First 'df -h' without sd card installed

Output withot sd card
Output without SD Card

Then insert sd card and  repeat the same command:

Output with SD Card Inserted

My system mounts sd card as: /dev/mmcblk0p1.

3. Unzip the image downloaded:

unzip 2015-05-05-raspbian-wheezy.zip 

4. Unmount sd card

umount /media/jaro/D681-1D95

5. Using 'dd' copy the image onto the sd card (make sure you use the whole partition of the card - here: /dev/mmcblk0)

sudo dd bs=4M if=2015-05-05-raspbian-wheezy.img of=/dev/mmcblk0

It will take a while to copy image and nothing shows on the screen during that time. Just give it a time.

6. Insert sd card into Raspberry PI and connect to your TV set.

Once my Raspberry PI is hooked up to the TV set

A tool called 'raspi-config' is the first thing that is greeting me. It can be invoked at any point from CLI (command line interface) using the following command: 

$ sudo raspi-config


all information on raspi-config can be found at: http://elinux.org/RPi_raspi-config


Avoiding too much deliberation I arrive with the following settings:


Option 1: Expand Filesystem
This allows system to see and use the whole SD Card.

Option 2: Change User Password.
I have changed default password (defaults: user=pi, password=rasbberry)

Option 3: Enable Boot to Desktop/Scratch
-----> Console Text console, requiring login (default)
In case I wanted Graphical User Interface (GUI) I can always type:

$ startx



Graphical User Interface is pretty and makes simple task simple. But my goal is to discover the full power of this little computer and Linux. This is why I will be using SHELL most of the time.

Option 8: Advanced Options
-----> A3Memory Split
(How much memory should the GPU have)? 32
Since I don't use GUI, 32 MB should do.

-----> A4: SSH (in order to be able to log on to PI from other computers (putty etc.)

If I don't like them I can change them anytime I want by invoking the tool again. 

The last thing I want to do is to make sure that IP address of my Raspberry PI has a static IP address rather than using DHCP server. It will make my ssh access much easier later.

I edit the file in which system keeps the information about IP settings (I'm choosing IP address that is not part of DHCP in my network (A.B.C.D are values used in my home network):

$ sudo nano /etc/network/interfaces





iface eth0 inet static
        address A.B.C.D
        netmask 255.255.255.0
        network A.B.C.0
        broadcast A.B.C.255
        gateway A.B.C.254

Content saved with CTRL-x / save


(Note: learn VIM text editor. It's usage is more difficult but gives more power as well).

And...
IT'S ALIVE



Welcome home little buddy!