Posts Tagged by Vim
|12-Feb-2013||Posted by Sonia Hamilton under Golang, Perl, Python, Ruby, Vim|
I’ve just finished refactoring a large Go program, and the process was rather…. pleasant.
Static typing catches all those obscure errors I wouldn’t think about in a scripting language (Python, Perl, Ruby, etc). My process is:
- type :make in vim (I have a dummy Makefile in my Go project just for vim)
- vim jumps cursor to error (vim quickfix list)
- “oh, I shouldn’t do that” – fix (type type type)
- start again
Finish rather sooner than expected, run tests, smile in knowledge program is working properly.
To quickly setup the make command for Go, type this in a Vim window:
:setlocal makeprg=go\ build\ \.
Or even better configure vim via your ~/.vimrc, for example:
autocmd BufRead *_test.go setlocal makeprg=go\ test\ \. autocmd BufRead *.go setlocal makeprg=go\ test\ \./..
Thanks Martin for the comment!
|20-Nov-2012||Posted by Sonia Hamilton under Golang, Vim|
Bufexplorer – my new favourite add-on for vim.
Why do I like it? It allows you to emulate the buffer list feature of emacs, as well as switch between horizontal/vertical buffer splits and find recently edited files. All this can already be done with vim buffers, but bufexplorer makes it easy.
Why don’t I just use emacs? Because as sysadmin/devop I’m often working on other people’s servers, and I don’t want to go installing buckets of stuff everywhere – vim is usually installed.
I found the best way to use bufexplorer is to open up all possible source files (eg vim src/*.go other/*.go) at the start of an editing session, then just skip between them (shown here with the excellent xMonad window manager, GNU Screen, and Gnome Terminal):
|26-Apr-2012||Posted by Sonia Hamilton under Emacs, Vim|
A small Vim Buffers cheatsheet:
:bu <tab> - select a buffer :buN - select buffer N :ls - list buffers :sb tab - split screen on another buffer :sbN - split screen on buffer N :only - make this the only buffer (ie maximise) ^w^o - make this the only buffer (ie maximise) :ball - split screen on all buffers :hide - hide this buffer :bdel - remove buffer from list
Vim buffers don’t seem as flexible as the Emacs equivalent, but then nothing is as flexible as Emacs:
|02-Mar-2012||Posted by Sonia Hamilton under Vim|
I little command I always have to search for when using vimdiff – :diffupdate
After you’ve made changes in vimdiff :diffupdate will recalculate the diffs.
|30-Mar-2010||Posted by Sonia Hamilton under Vim|
A concise article on Linux.com (that I keep referring back to) about vim folding. I’ve been using vi/vim for years and vi keystrokes just “happen”, but it’s always nice to learn a few more tricks, especially when working with larger scripts.
A brief summary of folding:
- highlight some text using v visual mode, zf to fold, zo to unfold (ie open)
- put cursor on an opening curly bracket, and zfa} to fold until closing curly bracket (or zfa) or zfa] for parentheses, square brackets)
- add this to your .vimrc to remember folds:
au BufWinLeave * mkview au BufWinEnter * silent loadview
Lots more commands in the article.