Vim, the Power of Antiquity
"The Shinkansen Tour"
But ... Using vi HURTS
- vi originated in 1976 on Unix systems that had unimaginably low horsepower by modern standards
- its origins are in "ed" and "ex," and if you knew them ... vi's arcane nature starts to make sense
- vi is a "modal" editor: "Insert" or "Normal" modes
- hjkl ia :w :q - your most basic commands
What is Vim and do I Care?
- vi is a POSIX standard: it's on ALL Unix systems, including every version of Linux and Mac OS
- vi and many variants are still with us: vim is the commonest and most developed
- vim adds a huge number of things to vi that are lacking
To run vim to see what vi looked like:
vim -u NONE filename.py
- mappings can be created at the command line, or put in your ~/.vimrc
- mapping is by default recursive, thus most people use "nnoremap" rather than "map"
nnoremap <leader>ev :tabnew $MYVIMRC<CR>
" _R_e_I_ndent whole file:
nnoremap <leader>ri msHmtgg=G'tzt`s
I chose "-" as my leader because it's unused in vim, and very handy if you use the Dvorak keyboard layout. For Qwerty users, ";" is probably the most accessible choice.
- vim has literally hundreds of colour schemes
- different colour schemes are better for different types of code
Syntax Highlighting Part II
- I prefer a black background (there are just as many themes for light backgrounds)
- my favourites (in no particular order): gardener, jammy, candy, candycode, ir_black, herald, moria, darkdevel, darkmate, nightsky, shobogenzo, slate, oceanblack
- writing your own isn't too bad if you know basic regex
I've had weird behaviour from "moria:" in the end I edited the
moria.vim file to force a dark background at all times.
Syntax Highlighting Part III
- pick your preferred type of code
- may SLAUGHTER your JS-engine
If you go to https://code.google.com/p/vimcolorschemetest/ ,
I recommend Chrome. Don't get me wrong, Firefox is my default
browser, but the language tests often choke it.
Syntax Highlighting Part IV
- if your xterm is only showing 8 colours (you'll know: it horribly mangles 256 colour colour schemes)
- install ncurses-term and update t_Co in your ~/.vimrc
Syntax Highlighting - Ugly Code
if [ -e /usr/share/terminfo/x/xterm?256color ]
set t_Co=256 " "terminal has 256 colors"
- vim has its own programming language
- Book (available entirely online, but buy a copy!): Learn Vimscript the Hard Way
- it's a hairy language: user settings affect the behaviour of the language
- a programming language ... that means plugins
- Plugins? But that would mean ... oh dear god no ...
- vim has its own package management system
- correction: several
- Vundle and Pathogen appear to get the most respect, I use Vundle
Pathogen requires more work on your part creating directories and
running "git clone ..." commands. Vundle only needs a pointer to a
github (or other) repo and it does the checkouts for you.
Plugins, Part II
There are LOTS of language-specific plugins.
- HTML: cit, ci", dit ... there are many others, most apply to Python
- there's a whole hierarchy of files in ~/.vim/ including one for file detection: when your ~/.vimrc gets messy enough, use them
- folding - by markers or file syntax
- your friends: Stack Overflow and similar, Vim Tips Wiki