A Journeyman's Tour of Vim

S5 Slide Show

This is an S5 slide show. Move your pointer to the lower right corner to see the controls. Click on the "0" to see the speaker notes (aka "print view"). Reload to get back to the slide view. Click anywhere to advance the slides.

  • S5 is a great way to do a slide show ... but the main point here is ... congratulations on being able to read the speaker notes.

A Journeyman's Tour of Vim

The Adventures of an Escape-Hammering Vim Monkey

Giles Orr

TPL

  • I use the term "journeyman" in the old traditional sense: you start learning as an apprentice, you become a journeyman, and eventually you become a master
  • to understand where I'm coming from, I'm a mediocre programmer in several languages
  • and I know something about many, many Linux topics
  • I'm a voluntary and happy Jack-of-all-trades
  • with the flip-side being "master of none"
  • I never get bored (that's not meant to imply mastery = boredom, it's a personal choice)

Real Programmers

Real Programmers

Common Unix Editors

Show of hands: what's your primary editor?

  • Emacs users: I will NOT mock you - at least you have a real programming language in your editor
  • go check out github's Atom - seriously: it's massive and graphical only, but it's good and really interesting
  • anyone who answered Pico/Nano: consider learning something with a bit more power, you're missing out

Talk Structure

This will be episodic: I'll be talking about various things related to the editor that people may or may not know about in the hope of expanding your knowledge

NeoVim

  • consider using neovim ESPECIALLY if you're just getting started with vim: I suspect it's the future of vim
  • the opinions in that first URL are echoed other places: this is a short summary

Installation

  • The vi installed on Debian-based systems is a subset of Vim, but doesn't offer all the commands available in Vim - so install the "vim" package
  • The CentOS (and possibly Fedora/RedHat) versions apparently have a similar problem: run "yum install vim-enhanced" (not sure it has a dash, not a CentOS user
  • default OSX Vim lacks features that are compiled in on almost all other versions: for me, I found the lack of "tab drop" problematic as I use it in plugins
  • "Cream" provides a single, easy-to-install package and smooths out some of the weirdness that happens (ie. with CTRL-C, CTRL-V), although it also tries to wipe away modal editing - so if you want modal editing you have to choose your troubles (I prefer Cream: it's worked well and you can turn modal editing back on)

What's Right about Vim

What's Wrong with Vim

Classical learning curves for some common editors

What's Wrong with Vim

  • Neovim won't be fixing the horrible programming language: in fact, they're re-implementing it just as it is ...

History

Let's look at the origins of the power and the pain of Vim:

  • teletypes: you know, on paper?
  • Salus quote per Wikipedia

History

  • vi: we're talking about a text editor that's older than several of the people in this room

History

H-J-K-L keys on Lear Siegler ADM-3A terminal with arrow keys

The movement keys J-H-K-L weren't chosen by proximity either: at the time, the terminal Bill Joy was using (Lear Siegler ADM-3A) had the arrow keys on top of those letters - and the Escape Key was where the Tab key currently is (easier to reach).

  • Lear Siegler ADM-3A per Wikipedia ...

Modal Editing

Syntax Highlighting

  • get a show of hands on who's installed non-standard syntax colour schemes

Syntax Highlighting

  • vim has literally hundreds of colour schemes
  • different colour schemes are better for different types of code

  • Vim syntax highlighting is garish

    Favourite Colour Schemes

    I've had weird behaviour from "moria:" in the end I edited the moria.vim file to force a dark background at all times.

    Color Scheme Test


    web page that shows multiple vim colour schemes side-by-side for the same piece of code (choice of several languages)

    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.

    The Eight Colour Problem

    • not a problem on Macs
    • don't think this is a problem on Windows

    The Eight Colour Problem - the Code

    /etc/profile:
        if [ -e /usr/share/terminfo/x/xterm?256color ]
        then
            export TERM='xterm-256color'
        else
            export TERM='xterm-color'
        fi
        
    ~/.vimrc:
        if &term=="xterm-256color"
            set t_Co=256 " "terminal has 256 colors"
        endif
        
    • the "?" is in the /etc/profile line to address Debian and Ubuntu, as they use different characters

    ~/.vimrc

    Mappings


    
    let mapleader="-"
    nnoremap <leader>ev :tab drop $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 (almost the same location as "-" for Dvorak users).

    Tear-down on "-ev": "n" of "nnoremap" means "do this mapping in normal mode." The core is "map," but we also say "noremap" to avoid nasty side effects, ie. "don't interpret other parts through other mappings." Huh? If you've independently mapped a letter but the letter is a part of the new mapping, without "noremap" vim will try to interpret the other letter mapping as well ... It gets very ugly. If that didn't make sense, just trust me and use "noremap" until it becomes clearer.

    So I type "-ev" in normal mode to get a response, which is to run the command ":tab drop $MYVIMRC". That means to type a colon (we're entering ex mode!) followed by "tab drop" (which means "open this file in a new tab, or go to an existing tab if the file is already open"). And finally, a global Vim variable "$MYVIMRC" which is a pointer to ~/.vimrc on a Linux system, or elsewhere if you're on Windows or some non-Unixy system. And close the command with a carriage return.

    Getting :help

    • Walk through accessing the help for nnoremap

    Buffers

    • Where <N> is a number

    Buffers


    Vim session with mini buffer explorer at the top showing multiple buffers, two tagged as open.

    Tabs

    • Note that you can open a file browser on any folder with ":tabnew <name-of-folder>

    Sessions

    • I suppose session files could be made into dot-files, to reduce clutter
    • works fine with some plugins (Taglist), not so good with others (Nerdtree - starts it, but doesn't reload the folder it was in)
    • doesn't remember colours at all
    • can't compensate changes in terminal size (it tries)

    Plugins

    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. Although you have to do a git clone for Vundle itself.

    "Best" Plugins

    • "Best" is in quotes because these are ones I've tried and liked (mostly on others' recommendations), but there are thousands more out there
    • airline - pretty (and useful!) status bar
    • gitgutter - shows changes to the current file with "+", "-" or "~" in a left-hand gutter
    • signify - same as gitgutter, but handles other VCSes as well
    • fugitive - do all things git inside Vim
    • taglist - requires ctags, shows tags for the current program

    "Best" Plugins Continued

    • NerdTree - replacement file browser
    • openrel - "gf" can be used to follow a link from one file to another ... but often doesn't work - particularly with HTML - because absolute links on the webserver are different from those on the local file system: this can help with that
    • Ctrl-P - fuzzy file/buffer/tag finder
    • There are LOTS of language-specific plugins. I mention Python specifically because I've been using it a lot lately.
    • jedi-vim - completion for Python

    "Best" Plugins Continued

    • Superman - read your man pages in Vim
    • vimwiki - a personal wiki entirely inside Vim
    • Conque Shell - because what you really need is a shell inside Vim
    • Terminus - terminal integration: does a number of things, but for me the win is mouse integration in Vim in terminal windows

    Airline

    airline status bar
    airline status bar showing git changes
    airline status bar in insert mode

    "Programmer Fonts"

    • When I did this talk, I asked who used the GUI version of Vim - no one. Despite nearly everyone present being a Vim user.
    • So it's worth talking about "Programmer Fonts"
    • There are a million recommendations online: the most popular fonts are Anonymous Pro, Droid Sans, Inconsolata, Liberation Mono, and a few others
    • The previously mentioned Airline plugin was based on another plugin called "Powerline," and they both use slightly modified fonts to look their prettiest
    • The Powerline font repository includes all of the "greatest hits" of programmer fonts, all modified for Powerline: so save time searching the web and just go to that repo ... and you get the free bonus of being ready for Airline.

    XTerm and Scalable Fonts

    • Most modern terminal emulators have full support for TTF and OTF fonts built in, with a GUI font selection system
    • XTerm has no such conveniences
    • But it has command line parameters to use any of these fonts - write scripts to start what you want, because otherwise it's a lot of typing

    VimScript, aka VimL

    • They're not paying me and I don't know the author
    • I was using it online so much I bought two copies and gave one to a friend

    Behaviour Dependent on User Settings

    Truly: if you do a document search, VimScript will respect the case sensitivity setting set by the user. To do it your way you're forced to grab the setting, reset it the way you want it, do your search, and restore the setting (and that's only if you remember ... it's a helluva gotcha)

    • This of course applies to all settings - whether you know they exist or not

    ~/.vim/ Directory Structure

    • There are quite a few more, but these are the ones I've used and think I might actually be able to correctly explain ...
    • autoload - functions used by plugins and for general use that will be loaded when the function is invoked.
    • bundle - where Vundle (and, I think, other package management arrangements) put their unpacked software
    • colors - holds user syntax highlighting files for use with the :colorscheme command
    • ftdetect - files here are used to detect filetypes that vim doesn't know about by some other method (":help ftdetect")

    ~/.vim/ Directory Structure

    • ftplugin - filetype plugins, which are used to define the behaviour of Vim for specific filetypes, autoloaded when that filetype is recognized (filenames are things like "html.vim" and "python.vim")
    • plugin - files in this folder are autoloaded when Vim starts
    • spell - files related to spelling: primarily (that I've noticed) user additions to the dictionary
    • syntax - syntax definition files: these don't define the syntax colours, but rather how to determine if a word in a file is a "noun" or a "verb" so that the colors files can be applied to each word type

    Miscellaneous

    • cit, ci", dit ... useful short motion formulas. "cit" is "change inner tag, "change inner quote," "delete inner tag", etc. I learned them for HTML, but they work anywhere
    • there are millions of Vim "cheatsheets:" I haven't found a lot of value in them, but they may suit other learning styles than mine and this one is definitely the best I've seen
    • six different fold methods: manual, indent, expr, syntax, diff, marker

    Bibliography - and Questions