# Vim, Thoughts After Two Weeks

Purposefully, I began using Vim during a non-strenuous work week which helped manage frustration. I have been using solely Vim as a text editor for two weeks and have experienced improved efficienies over my previous text editor, Sublime.

##### Improvments

The ability to change between files quickly using the Ctrl-P plugin is the biggest quality of life increase. Commands such as / and ? make finding word matches in a file easy. Using RSpec with Vim is also great; I can change my code and re-run a single test without switching screens! There are many small wins with using Vim and they add up.

##### Pain Points

Adding new files does not work if the directory does not exist. The mkdir plugin solves this issue. Furthermore, commenting out code is a pain without vim-commentary. Checking my vimrc file into version controller has been helpful in debgging where breaking changes originate.

Vim Awesome

# Level Up With Vim

How much time do you spend in your text editor? We spend most of our time reading through text and jumping between files. My goal is to find a tool in order to help me do this more efficiently. I have found that learning Vim is not overwhelming or difficult if you break the units of work down into manageable pieces. The ultimate goal is to use Vim fulltime. Below are my curated steps:

##### Vimtutor
• Comprehensive introduction to Vim
• Type vimtutor in a Terminal session
• Complete a few sections per day

# Filtering Ack Results

While setting up my VIM environment, I read a blogpost which states ack can ignore directories. For cleaner ack output you can setup the file below:

# Rails before_action Method

I did not know you could give a before_action a block argument. This is a benefit because you do not have to create a ruby method and pass the method into the before_action.

This got me thinking, what does before_action look like in Rails? The following is the source code from Rails 4.2.7, from AbstractController::Callbacks::ClassMethods.

And I can do cool things like:

I would like to point out the set_callback method.

# Extend and Include in Ruby

I have been trying to clean up some old code with Ruby modules. This post is to help me remember the differences between include and extend in Ruby.

# Find and Replace Text

If you find yourself in the situation of needing to find and replace text in multiple files, use the Command Line Interface. I wanted to rename a Phoenix application and ran the below command.

ack pivotal_commentor -l | xargs sed -i '' 's/pivotal_commentor/commentor/g'

Let’s break this command down with a simple example.

And lets add the text ‘hello’ to both text files.

ack is like grep and found the files containing the string hello. The -l flag “Only print filenames containing matches”

xargs is a Unix utility that constructs argument lists and is smashing the filenames into one line.

Finally, we pipe the arguments from xargs to sed.

The -i flag allows for in place editing on the file. In the regex, the s replaces hello with bye and the g indicates globally, in case hello is found more than once in the file. The ‘’ is sending the change into the correct output file.

# JQuery beforeSend Function

I have a form which submits a comment via AJAX. The app was throwing validation errors if there was no value in the comment field. My initial solution was to disable the submit button if the comment is blank. However, using the beforeSend function provides a cleaner solution.

With the above code, the comment form is never posted if the comment is blank.

# ActiveRecord None

The .none class method was introduced in Rails 4.0.2 and is helpful when returning a blank array will break.

none

# Submitting a Get Request in Rails

For the error “WARNING: Can’t verify CSRF token authenticity”, add a CSRF token.

The top-level block contains method: :get which doesn’t auto-add the needed authenticity_token.

Understanding the Rails Authenticity Token