Dev box
I'm a 32-year-old Ruby on Rails web developer. With the help of friends and co-workers, I've been teaching myself Rails. I worked as a Rails developer for Crowd911 in Colorado. I live in Berlin.
In my developer blog I publish a stochastic array of thoughts and ideas, lessons, mistakes, questions and attempts as answers about Rails and Ruby. I am also posting Anki cards that I used to help myself study. In my view most knowledge is about practice. If you have thoughts, questions, ideas, corrections, arguments, feel free to email me at henryvw@gmail.com.

Henry's Important VIM commands

v - Enter select mode within a line

V - Enter select mode for whole lines

ggVG - Select ALL text in a file

:NERDTree - Bring up Nerd Tree for navigation through a folder

ctrl-n - Bring up Nerdtree

Y - Copy.

yy - Copy a whole line of text.

:y14 - Copy 14 lines of text.

P - Paste.

"_d - Delete WITHOUT cutting the content

:Gdiff - See three tab windows with Git Differences. This is part of the "Fugitive" Git plugin.

:%s/text to search for/text to replace/ - Search for and replace text

ctrl-w h - Move within VIM window left

ctrl-w l - Move within VIM window right

ctrl-w j - Move within VIM window down

ctrl-w k - Move within VIM window up

vim ftp://// - Edit a file with vim remotely.

$ - Move to end of line

0 - Move to the beginning of the line

M - Jump to the middle of the screen

L - Jump to the bottom of the screen

G - Jump to the bottom of the File

1G (or gg) - Jump to the top of the File

H - Jump to the top of the screen

% - Jump to its corresponding item - e.g. from an open bracket to its (corresponding) closing bracket

/ - Search

n - Select down to next item result from your Search

N - Select Up to next item result from your Search

ctrl V - Go into Visual Line mode

ctrl O - Step BACK to previous file

To Write Within Folders, e.g. delete file within a folder:

:set modifiable - Make a folder / directory modifiable (e.g. to delete a file)
:w - To write
:set buftype: " "

To comment out text:
  • hit ctrl+v (visual block mode)
  • use the down arrow keys to select the lines you want (it won't highlight everything)
  • Shift+i (capital I)
  • insert the text you want, i.e. '% '
  • ESC

 :set nu - Show line numbers
 :set nonu - Remove line numbers 

u - Undo
ctrl R - Redo

Nerdtree (plugin)

R - Refresh all files in Nerdtree
m - Open Nerdtree file options
a - add a new file (then, input the name, and enter to create)

i - Open Nerdtree file in new horizontal window

s - Open Nerdtree file in new vertical window

VIM NERD Tree Moving and Renaming Files

m - Opens the Nerdtree filesystem 

m - A 2nd "m" will give you the opportunity to rename the file's path

c - Copy the file, and then enter the prompt to change it's path. This will leave a copy of the file in its original path.

a - Add new file

Searching in VIM

:Ack

Example basic search for the phrase "recent_entries":

:Ack recent_entries

Example basic search for the phrase "recent_entries" in ONLY Ruby (.rb) files:

:Ack --ruby recent_entries

Ack automatically excludes searching lots of folders that you don't need, like .git.

To open search results: hit enter

To open search results in a new tab: hit " t " 

edit ~/.ackrc to ignore folders and add other ack settings

https://gist.github.com/kevinold/4749656

GREP

:grep -R 'Content::PressRelease' .

More about GREP search in this thoughtful article here: http://seesparkbox.com/foundry/demystifying_multi_file_searches_in_vim_and_the_command_line

VIMGREP - Search Within Files

:vimgrep /pattern/gj ./**/*.rb

:cw - Open vimgrep search results

http://lostechies.com/derickbailey/2010/05/11/vim-grep-find-all-occurrences-of-text-in-your-project/

Ctrl-P (plugin) - Search for Files
Ctrl-p - Search through all files - filenames only
:CtrlPMixed - Search a mix of method names and filenames (note that this cmnd is typed out)
Ctrl-j / Ctrl-k - Toggle through ctrl-p results
Ctrl-t - Open result in a new tab
Ctrl-v - Open result in a new vertical window
Ctrl-x - Open result in a new horizontal window
Ctrl-z - Save a result to open later (Ctrl-o)

Ctrl-t - Open result in a new tab. Yes I know I wrote this twice. For emphasis.

Ctrl-o - Open saved results

Ctrl-p Ctrl-p (Ctrl-p x 2) - Open past Ctrl-p search result

VIM Tabs

gt - Go to next tab

gT - Go to previous tab

{i} gt - Go to tab selected by the i

:tabclose - Close VIM tab
:tabn - Go to next tab
:tabp - Go to previous tab

 VIM Windows

Ctrl-w r - Swap windows in place (Ctrl-w, release, then hit r)
Ctrl-w - General Window options
:30winc + - Add 30 horizontal lines to the window
:30winc - - Subtract 30 horizontal lines to the window
:30winc > - Add 30 vertical lines to the window
:30winc < - Remove 30 vertical lines from the window
:vertical resize 30 - Set the window to exactly 30 lines vertical
:horizontal resize 30 - Set the window to exactly 30 lines horizontal
:vsp - Split window vertically
:sp - Split window horizontally

VIM Directories
:pwd - Show current working directory
:cd directories/directory - Change VIM's working directory

VIM Copy and Paste
:set paste - When copying from an internet website, this turns off crazy auto-indentation

ctrl-v 2> - Indent two spaces 

ctrl-v 2< - Un-indent two spaces

Read More
VIM

3 Types of Array within Array Manipulations - *[array], [array].zip, Hash[array]

Three different methods to MANIPULATE an ARRAY which were shown to me yesterday:

  1. array = [*[1,2],*[3,4]]    =>      [1,2,3,4]    Use the splat operator (*) to explode an array into a literal list of items.
  2. [1,2].zip(['a','b'],['I','II'])  =>   [[1,'a','I'], [2, 'b', 'II']]  Use the .zip method to combine collections in an ordered way.
  3. Hash[[[1,2], [3,4]]]         =>    {1 => 2, 3 => 4}   Convert arrays into a hash using the Hash method. You can customize what the array looks like using whichever combinations of splat operators and zip methods that you'd like.

 

 

Read More

ps aux | grep PROCESS

The Unix

ps aux | grep process

command is a powerful command to see all the instances of a running process. For example,

ps aux | grep rails

Will show you all instances of the rails process:

$ ps aux | grep rails

henryvanwagenberg 17799  52.2  3.1  2740008 262736   ??  R    11:15AM   4:19.28

henryvanwagenberg 18068   0.0  0.0  2424580    416 s001  R+   11:51AM   0:00.00 grep rails

You can then KILL a process with:

$ kill -9 process_id

To continue using this example,

$ kill -9 17799

And now if you again do ps aux | grep rails you have:

$ ps aux | grep rails

henryvanwagenberg 18068   0.0  0.0  2424580    416 s001  R+   11:51AM   0:00.00 grep rails

Read More
Unix, grep, ps

%w[boston baltimore philadelphia]

Using the %w method generates a "word array". 

%w[boston baltimore philadelphia]

would create an array:

 => ["boston", "baltimore", "philadelphia"]

In other words, the "word array" generation adds commas and quotation marks around the entries that you list.

Read More
word array

Adding a new value to a hash, without a key, while simultaneously creating a key

If you take a Hash:

fun_hash = { }

And call the hash fun_hash, it returns:

=>{ }

Great! Now you created a hash.

But now, you'd like to populate it with a key/value pair at the same time.

What do you do?

fun_hash["fun_key_one"] = "fun_value_one"
fun_hash["fun_key_two"] = "fun_value_two"

And now when you call the hash it returns:

=> {"fun_key_one"=>"fun_value_one", "fun_key_two"=>"fun_value_two"}

Great! You've now added two values WITH keys to the new blank hash.

Read More
Hash






Footerfull