vim

Toby said something on twitter that I found interesting.

I've played about with other editors, the big three in my opinion are sublime, Textmate and atom. I've used them all on and off. Surprisingly I've never taken to any of them and after a few days/weeks I've reverted back to vim.

I started using vim back in 2000 when the sys admin of my first job refused to install pico. However it is really only the last few months that I've started to use vim 'properly' and I use the word 'properly' very loosely.

Lately I am developing in python or ruby. Luckily great progress has been made in getting the most of out of vim with the likes of vimcasts and the excellent work done by Tim Pope. If you use ruby there are lots of plugins in for vim. For python there isn't a real front runner like vim-ruby but if you look about there are lots of tutorials out there to aid you. A tutorial I highly recommend is Learn-Vim-Progressively.

Learning how to use tabs and split screens has helped me immensely, if I remember correctly the default commands for moving around tabs and screens is awkward. So I remapped them and now I get around the tabs but hitting 't' to move forward in a tab and 'gT'. I don't use the 'Xgt' shortcuts though.

" Getting used to tabs in vim
map  gt
map  gT
map  1gt
map  2gt
map  3gt
map  4gt

" Use ctrl-[hjkl] to select the active split!
nmap   :wincmd k   
nmap   :wincmd j  
nmap   :wincmd h 
nmap   :wincmd l


Easy file navigation is essential for a good workflow. Luckily there is ctrlP which gives you a fuzzy search interface. If you spend your time inside a framework like Django or Ruby on Rails you can easily add shortcuts to edit commonly opened files. I have done this for a certain project I am working on but I never actually use it as the navigation for ctrlP is so handy. However to stop indexing of build data, database files etc a few options are needed to thin out the files.

set runtimepath^=~/.vim/bundle/ctrlp.vim
set wildignore+=*/tmp/*,,*_site/*,*build/*,*venv*,*bin/*,*db/*,*.pyc,*node_module*,*dist/* 
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn|so|swp|zip|pyc)$'

Add this to the tabs and splits and the workflow is starting to get quite interesting. Keeping inside vim is deadly important though so I also use vim-fugitive to keep inside the editor while I am commting to git. I also want as much information as possible to me on the info line so I have installed powerline - this shows me the branch I am on, the encoding, file type, line number, character number and mode. The important thing is that I get this information at a glance.

  if !exists('g:airline_symbols')
      let g:airline_symbols = {}
  endif

  " unicode symbols
  let g:airline_left_sep = '»'
  let g:airline_left_sep = '▶'
  let g:airline_right_sep = '«'
  let g:airline_right_sep = '◀'
  let g:airline_symbols.linenr = '␊'
  let g:airline_symbols.linenr = '␤'
  let g:airline_symbols.linenr = '¶'
  let g:airline_symbols.branch = '⎇'
  let g:airline_symbols.paste = 'ρ'
  let g:airline_symbols.paste = 'Þ'
  let g:airline_symbols.paste = '∥'
  let g:airline_symbols.whitespace = 'Ξ' 
 

I don't think there are many other plugins that I use on a day to day basis. On my old laptop I used the snippets plugin a bit however four weeks into this new work laptop and I haven't used it. After this I use config commands to aid me.

This simply puts the spacing and tabs to be four if it is a python file and for everything else is two.

" everything else at 2 but python at 4
set smartindent
autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
autocmd FileType python set sw=4 sts=4 et

To aid in easy shifting of text I added this helper. I can't remember where I stole it from though, pretty sure I'm not smart enough to come up with this on my own.

" Shortcut for indentation while inside visual mode
vnoremap <  >gv 

I really need to keep inside vim for my productivity up. If I want to make notes on what I am working on I simply add them to a scratchpad file I keep in my home directory by hitting ',e'. I tried using an actual scratchpad but this seems to have gained more favour with me.

map ,e :tabnew ~/Dropbox/notes.txt

A few handy things I have is having are remaping the esc key to 'jk'. Actually that was a pain to type in so I might have to remap that. Also trailing spaces are hateful so if the python file I am in has any then get rid of them. Also I try and stick to 80 characters as a max line length. If I go over I want a red background on the cell on the line that is over. I prefer this than a default ruler.

autocmd BufWritePre *.py :%s/\s\+$//e

inoremap jk  

highlight ColourColumn ctermbg=red
call matchadd('ColourColumn', '\%81v', 100)

The nicest thing I do I think is remaping ',t'. Which I move to running whatever test I am currently in.

So, that is it. That's what I am doing with vim so far and I have no want to try anything else at the minute.

  • workflow, (1)
  • vim, (1)
  • development (3)