Helpful Vim Commands - Find/Replace and Formatting JSON Files
Recently, I've been trying to learn Vim simply via full immersion. I have mixed opinions and feelings about it. Namely, after more than a month I'm about ~80% as productive in Vim as I was in sublime. A big part of that productivity loss is in my workflow within a pry shell and needing to copy-paste commands. But, I'll leave those thoughts for another blog post. Anyway, I recently switched jobs and was put on a relatively quiet project so I thought it would be a good time to take a hit to productivity and learn some Vim.
One of the latest additions to my dotfiles is vim-multiple-cursors which has been great for same-file find/replace (similar to sublime). Today, however, was the first time I needed to find/replace in vim across an entire project (changed a method name). So, I started googling and ran across a stack overflow post that was perfect for what I was trying to do.
def my_method end
describe '#my_method' do it 'does something crazy' do expect(my_method).to eq(awesome_sauce) end end
So If I needed to change #my_method I would simply perform the following while still in vim and voila.
This one is super slick (you'd have to install a package for sublime). Props to coderwall for this one.
Assuming you're in 'spec/fixtures/data.json'
:%!python -m json.tool
You can turn this into a Vim command by putting the below into your .vimrc
:command! FormatJSON :%!python -m json.tool
Anyway, thought these were super helpful. Happy coding!