tadhg.com
tadhg.com
 

Some Tidbits from my .vimrc

21:44 Thu 07 Oct 2010. Updated: 03:54 30 Dec 2010
[, , , , ]

These aren’t anything particularly major, just some things I’ve found to improve my editing experience.

:nnoremap Y y$

This is hardly a departure from Vim orthodoxy, as it’s even suggested in the help. Y is configured by default to yank the line (just like yy), but it’s clear that it should yank the rest of the line, just as D means delete the rest of the line and C means delete the rest of the line and enter insert mode. So this mapping makes it do what it should.

:nnoremap B ^

I need an easy way to get to the start of the line and remain in normal mode, the opposite of $. The default configuration has ^ do that, but while I find $ easy to reach, the same isn’t true of ^. B is normally “move cursor one WORD backwards”, but that just isn’t something I use enough (as distinct from b, “move cursor one word backwards”), and so I made it map to ^.

:nnoremap <Space> <C-F>
:nnoremap <S-Space> <C-B>

I’m very used to scrolling up and down using Space and Shift-Space, mainly due to browsing, and the default of having Space do the same thing as l seemed rather wasteful. I’ve been pretty happy with this change.

:nnoremap <CR> :
:nnoremap q<CR> q:
:vnoremap <CR> :
:vnoremap q<CR> q:
:nnoremap <S-CR> <CR>

The default of having Enter move [count] lines down just didn’t seem useful, even if it does go to the first nonblank character. If I suddenly decide this is really useful, then I can always use Ctrl-M. Getting into command-line mode, however, I do all the time, and the Enter key seems like a perfect binding for it. The other commands make sure that the command-line window mode is accessible if I hit q first, that the same applies in visual mode, and finally that in the command-line window I can hit Shift-Enter to execute the line.

:nnoremap <BS> "_d
:nnoremap <S-BS> "_D
:vnoremap <BS> "_d
:vnoremap <S-BS> "_D

It’s great that Vim automatically yanks anything you delete. It’s also great that Vim supports multiple registers. However, I find the requirement of hitting first " and then the key for the register and then the command you want to use that register for is just too awkward. At the same time, I very frequently get tripped up by the pattern of yanking something, being about to paste it, but first remembering that I have to delete something else, which I delete—and then when I paste, I pasted the deleted thing instead of the something I intended. I couldn’t see a good way to fix this by making register use easier—which I will likely revisit—but have found this approach very handy. If I want to delete something and not yank it, I use Backspace, which “yanks to the blackhole register”, i.e. doesn’t yank and doesn’t override the default register. Oh, and like Space, Backspace is configured to a not very useful role by default, doing the same thing as h. I’ve found this do be extremely useful so far.

:set clipboard=unnamed

Essentially makes Vim’s default register share the OS clipboard. I switched to this last week and couldn’t believe I hadn’t done it before. Incredibly useful.

:vnoremap y ygv<Esc>

This is a little more obscure. I find myself frequently wanting to visually select a bunch of lines, yank them, and paste them just below the original block. However, the default behavior when exiting visual mode is to move the cursor back to where it was when you entered visual mode, making my use case more awkward. This forces the behavior I expect in that use case.

set guioptions=egmrtc

(Actually from my .gvimrc.) Only the c is really of interest here, and it just makes MacVim use Vim dialogs instead of OS X dialogs. They’re definitely easier for me to use.

As a side note, I’ve been pretty happy since making the keyboard shortcut/meta key adjustments I mentioned last week.

2 Responses to “Some Tidbits from my .vimrc

  1. Steve C Says:

    Ahh, ^ does that! I’ve never bothered reading the man pages but it’s one of the few quick nava that I should really have looked up.

  2. Seth Milliken Says:

    0 gets you to the beginning of the line, too. And 0w is equivalent to ^.

Leave a Reply