Surviving Your First Week in Vim (and beyond) | Upcase

Ben & Chris give some tips and tricks on how to survive your first week in Vim. A great cheat sheet (Remember, you need this one and your own smaller one). Start with this minimal vimrc
This is a companion discussion topic for the original entry at https://thoughtbot.com/upcase/videos/surviving-your-first-week-in-vim

Iā€™ve made the switch to Vim about a month ago. I was in love with Sublime, but I spend so much time in the console and on remote CLIs that it really warranted the switch. So far no regrets, the only minor complaint that I have is the 256 colour limitation, havenā€™t found a work around for that one just yet and it wouldnā€™t make any sense for me to use gvim over Sublime for reasons stated above. This means slightly less colour scheme options, but definitely not anything progress stopping.

For anybody using Sublime looking to make the switch but canā€™t quite wean themselves off: just to get your feet wet with the idea of less mouse interactions try working in full screen mode. They have various keystrokes that will allow you to navigate tabs/files just as efficiently as if you were to use your mouse. They even have a vim mode for sublime, I havenā€™t tried it myself, but perhaps a good introduction.

I switched to Vim two months ago thanks to Ben Orensteinā€™s advice, and have become vastly more productive than I ever was using Sublime. Itā€™s painful for the first 2 days, but stick with it, and you will have no regrets. After youā€™ve been using it at least a week, check out tpopeā€™s vim-rails plugin and Chris Toomeyā€™s tmux trail on Upcase.

1 Like

One drawback, when starting to use Vim, is that you start using the Vim key shortcuts in other programā€™s too. Every now and then I catch myself wanting to use the direction keys (hjkl) in my email client, or some other sofware tool. Anyone else had that experience?

2 Likes

Hey all; we have some great additional Vim resources on our Youtube Channel from various meetups weā€™ve filmed. Enjoy!

Yep, vim has worked its way so far into my muscle memory that I try to use its key mappings everywhere such as when typing a url into the address bar or writing an email or GitHub comment, hammering esc wondering why I canā€™t delete 2 lines at once hah :smiley:

Yes. Same here. Great that Chrome has a ā€œVimiumā€ extension that uses Vim motion commands.
Besides, if you use Gmail via web they also have ā€œjā€ and ā€œkā€.

The cheat sheet is great! Iā€™m curious about one thing I saw: _ is labeled as ā€œsoftā€ bol down, but when I try it out, it seems to do the same as ^ - going to the first nonblank character on the current line and not the next line. Is something wrong with my configuration or is that expected behavior?

Hi @benorenstein and @christoomey Thanks for the encouragement!

Iā€™ve had a on off love affair with vim for about 10 years and have finally now just started using it as my only editor! So thanks to Ben who first awed me by showing off mad vim skills in his talk at the RubyBath Conference and then Chris for introducing tmux!

one thing that I found really useful have the http://vim-adventures.com/ game. It really kept challenging me! (although it was difficult to convince my managing director that it was training for work). Also one other thing I wanted to add was instead of pressing Esc I use Ctrl + c to exit INSERT mode. It makes such a big difference, specially if you map the CapLock key as a Ctrl as well! It keeps my on the home row a lot more i find :smile:.

@benorenstein while at the BathRuby conference you were showing off how to run tests with vim and how the pane should hide itself if all tests are passing. I manage to run the tests with vim-rspec, but was hoping you could reveal the secret of auto-hiding the pane if its all green and display the failure?

Many thanks, and keep it up!!!
ā€“ Hassan

Hey @hass_isnull, the plugin @benorenstein used in the video is vim-dispatch from tpope. It handles running commands from Vim and will detect and use tmux if present.

@christoomey what is a best way to configure vim so it can copy/paste from Tmux and iTerm? I still havenā€™t found a good solution to do soā€¦ I thought you wrote an article about it a while ago. Does it still apply?

Hey @antwonlee, the post I wrote about tmux copy and paste is still relevant and is in fact how I copy and paste in tmux.

Iā€™ve seen a number of people who connect Vim to the system clipboard, e.g. how @gabe does in his dotfiles by using the unnamed clipboard.

Personally I like the clipboard interaction to be more explicit, so I use the following to set up pasting:

nnoremap <leader>p :r!pbpaste<cr>

And a plugin I wrote to allow copying to the system clipboard via text-objects and motions, vim-system-copy.

2 Likes

@christoomey you are a true tmux jedi master. It is working and it just changed my life. :stuck_out_tongue_winking_eye:

Hey @christoomey, thanks for this, itā€™s a much better binding than the one I was using before.

I know I can use :! to call any shell command, but what does :r! do?

@antwonlee thanks for the kind words!

@aaronmcadam in general :r is short for :read which will read in the contents of a file. :r! or :read! will read in the output of a shell command, e.g. :r! ls will read into the buffer the output of ls.

1 Like

Ah, thatā€™s really cool, thanks!

@christoomey, slightly related question:

I have had zero luck finding this in the vim documentation or on Google, so apologies if thereā€™s some easy source Iā€™ve missed.

Is there a way to send a command with arguments to :read!? Iā€™m trying to build a vim alias to paste a timestamp using the shell date command in a file, but date takes an argument, and I canā€™t seem to get the quoting or backticks right. Iā€™d like to do something like this:

inoremap <C-t> <C-o>:read! date +%Y%m%d%H%M%S<CR>

but Iā€™m not having any luck.

Hey @geoffharcourt,

No easy source that I know of. For this I would use the expression register rather than trying to use :read!. The expression register is activated by typing <C-r>= in insert mode (<C-r> waits for a register to paste from, = goes into the expression register sub-mode). You can then use system() to call out to date. All together as a map (with a substitute to chop off the trailing newline):

inoremap <C-t> <C-r>=substitute(system("date +%Y%m%d%H%M%S"), '\n$', '', '')<cr>
3 Likes

@christoomey, works great, and now I know something new. Thanks again.

Hey all, does anyone have the link for the fuzzy search plugin mentioned?

Thanks for your help!