This post is part IV for the Vim adventures series, it starts here.

This last section contains mostly samples of my .vimrc.


For my plugin manager, I have this shell script. It ensures my tmp directories exist and downloads the plugins I use:

Image alt


I have stopped using fuzzy finders because I prefer the deterministic aspect of tab-completed bash-like searches.

In general I am faster with :find along with set path=.,** (but it can be slow for big projects).

FYI, I’m making a plugin called forage that will behave like :find but using the super fast ripgrep

Bits of confs

Custom status line

Image alt

If you like what you see, paste that in your .vimrc (be sure to check out :h statusline).

set statusline=%<%f%#Visual#\ %y%m%w%=%l\/%-6L\ %0*%3c\  
set laststatus=2 " always display status line

CamelCase movement

I made this tiny function to move to the next/previous non lower-case letter. With that, I can delete the next subword by pressing d leader w

function! SubWord(isVisual,flags)
    let num=v:count - 1
    if a:isVisual
        normal gv
    "\C case sensitive
    "\L non lowercase character
    call search('\C\L',a:flags)
    while num > 0
        call search('\C\L',a:flags)
        let num -= 1
nnoremap <leader>w :<C-u>call SubWord(0,'W')<CR>
nnoremap <leader>b :<C-u>call SubWord(0,'Wb')<CR>
onoremap <leader>w :<C-u>call SubWord(0,'W')<CR>
onoremap <leader>b :<C-u>call SubWord(0,'Wb')<CR>
vnoremap <leader>w :<C-u>call SubWord(1,'W')<CR>
vnoremap <leader>b :<C-u>call SubWord(1,'Wb')<CR>

Backup, swap and undo

I don’t want vim to add extra swap/backup files in my directory, so I send them to ~/.tmp.

set history=50          " keep 50 lines of command history
set viminfo='20,\"500   " remember copy registers after quitting in the .viminfo file -- 20 jump links, regs up to 500 lines'
set backup              " Save backup files
let &backupdir=$HOME."/.tmp/backup"

" Write undo tree to a file to resume from next time the file is opened
if has('persistent_undo')
    set undolevels=2000              " The number of undo items to remember
    set undofile                     " Save undo history to files locally
    let &undodir=$HOME."/.tmp/undo"  " Set the directory of the undofile

let &directory=$HOME."/.tmp/swap"    "Sets the swap directory

Movement in insert mode

Most of the time, it’s best to stay in normal mode. I like however to do short movements in insert mode when appropriate. The following shortcuts are very common in the unix world.

"Readline movements (will work in bash)
"C-u delete to 0, C-w delete word, C-h backspace work already
inoremap <C-a> <C-o>^
inoremap <C-e> <C-o>$
cnoremap <C-a> <Home>

inoremap <C-f> <RIGHT>
inoremap <C-b> <LEFT>

inoremap <C-y> <C-r>"
cnoremap <C-y> <C-r>"
inoremap <C-d> <DEL>
inoremap <C-k> <C-o>d$

"Alt-based stuff, only works with neovim/macvim
inoremap <A-d> <C-o>de
inoremap <A-f> <C-o>w
inoremap <A-b> <C-o>b

Vim vs NeoVim

I thought it would be worth mentioning here, Neovim intends to extend and modernize vim. Most of the current reasons to choose one over the other are political in nature.

The main reason I’d use NeoVim would be to map Alt keys. But the fact that the osx clipboard is not (yet) fully supported stops me.

That’s it folks

If you want help from fellow vimmers, reddit vim is great, some of its regulars can be a tad harsh so try take it as a cultural quirk ;)

Image alt

This concludes my vim adventures post. Feel free to shout me a good oul Tweet @PierreAclement