Skip to content

Instantly share code, notes, and snippets.

@romainl
Forked from dahu/gist:39282c57bba5b2d1e7b1
Last active August 4, 2023 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save romainl/61c422a7639e14bb9d72 to your computer and use it in GitHub Desktop.
Save romainl/61c422a7639e14bb9d72 to your computer and use it in GitHub Desktop.

Goal Driven Learning for Vim

Principles

Six principles of learning:
  1. Active Construction (crafted exercises in Vim, vimgym)

  2. Situated Learning (real world exercises, vimgym)

  3. Social Interactions (workplace, #vim)

  4. Cognitive Tools (see Tools section below)

  5. Expert Knowledge (vim docs (reference manual & user manual), #vim, wiki, selected blogs)

  6. Vim as a way of editing (Overarching concepts below, 7 habits)

Adult learners are practical with goal-oriented and relevancy-oriented focuses.

  • Provide meaningful learning experiences that are clearly linked to personal and work goals

  • Provide real case-studies / examples

  • Ask questions that motivate reflection, inquiry and further research

As an example of a relevancy based exercise, learners could be invited to choose a problem from their workplace (optionally scaled down for learning purposes) and attempt a solution on their own. If they encounter problems, consult Vim experts in their workplace or ask for help on #vim.

Design Process

  1. Specify learning goals

    1. Identify multiple varying "paths" as characterised by different needs from different learners

  2. Develop materials

    1. Contextualize lessons through driving questions and anchoring events

    2. Identify learning tasks

    3. Produce an instructional sequence

    4. Create quizzes to reinforce learning


The overarching concepts in Vim:

When starting to learn Vim, it seems like you have to memorise a million things. You don’t. You need to grok the core principles of modal editing, command composition and text transformation. The million things you thought you had to memorise are simply various combinations of these core principles.

  • Modal Editing

  • Command Composition (normal and visual mode commands; text-objects)

  • Text Transformation (:commands inherited from ed/sed)

Modes

There are four major modes in Vim. In Insert mode, what you type is what you see. Normal and Visual modes are largely orthogonal, sharing a language of composable commands which operate on text. Cmdline mode provides a line-oriented text transformation language.

Modal editing reduces the number of chorded key commands that other editors rely heavily on to perform actions. In insert mode, Vim behaves like a simple editor, inserting typed characters literally. Other editors might use ctrl-f to search, ctrl-s to save, ctrl-z to undo, ctrl-shift-Y to redo, etc. These are called chorded key commands because they require multiple keys to be pressed at the same time. This causes extra strain on hand muscles, possibly resulting in fatigue or even RSI. Vim prefers non-chorded key commands, using simple keys like / to search, :w to save, u to undo and . to redo.

All of these simple keys would be inserted in other text editors. In Vim, the user switches from Insert Mode to Normal Mode (possibly along with Visual Mode and/or Cmdline Mode) to issue such commands.

Commands

Normal mode commands seem at first to be arbitrary and complex. In fact they are regular compositions of simple commands that form a language for operating on text. These commands have the format:

[count] operator [motion]
Counts

A count is an optional number of times (defaulting to 1) to repeat/multiply/iterate a command.

Motions

A motion is a Normal or Visual mode command that moves the cursor. A motion can be coupled with an operator to perform a change or delete on the motioned-over text.

Operators

The operator commands in Vim are used to delete or change text. They take a motion which specifies the portion of text to operate on.

A particularly useful set of motions are called text-objects. This lets you do what you’re thinking without having to think about what you’re doing.

Visual mode commands share many of the Normal Mode operators and motions. For example, to delete a word in Vim, use diw (read as delete inner word). To yank (copy it to the clipboard), use yiw. To visually select a word, use viw. With the visual selection you can now delete it with d or yank it with y.

Transformations

Text transformations (a subset of the Ex commands) are manipulations made on line-based ranges. Example: :%s/foo/bar/g will replace all 'foo' with 'bar' throughout the whole buffer. Some are chainable by separating individual commands with the '|' character.

An example of a chained transformation:

:bufdo g/^function/ s/)\zs\s*$/ "{{{2/

This will append folding markers to every unmarked function in all loaded files.

Tools / Goals / Recipes

  • The Help System (help.txt and learnvim’s help intro)

  • Sane Configuration (learnvim’s vimrc, options.txt, usr_05.txt)

  • Opening Files (patient-vimmer’s files chapter, editing.txt, usr_07.txt)

    • :edit, :enew, ctrl-6, :find, gf

    • :ls, :buffer, :args, :argument, :write, :saveas, :quit

    • :cd, :lcd, &path

    • netrw (pi_netrw.txt, usr_22.txt)

  • Simple Editing

    • Navigation, text-objects, jumps, marks and big motions (motion.txt, scroll.txt, usr_03.txt)

    • Inserting, changing, deleting, repeating with normal mode commands (insert.txt, change.txt, repeat.txt, usr_04.txt, usr_24.txt)

  • Searching & Replacing (usr_10.txt)

    • :s/// and :g// (change.txt, repeat.txt)

      • Understanding Ranges (cmdline.txt, usr_10.txt)

    • /, ?, , , g, g, n, N, gn, gN, fFtT,;, gd (motion.txt, pattern.txt, usr_27.txt)

  • Format and Indent (change.txt, indent.txt, usr_25.txt)

  • Completion (insert.txt, usr_24.txt)

  • Registers (change.txt)

  • Visual Mode (visual.txt, usr_04.txt, usr_10.txt)

  • Maps, Abbreviations and Commands (map.txt, usr_05.txt, usr_24.txt, usr_40.txt)

  • Tags (tagsrch.txt, usr_29.txt)

  • Macros (repeat.txt, usr_10.txt, usr_26.txt)

  • Windows (windows.txt, usr_07.txt, usr_08.txt, usr_29.txt)

  • Tabpages done right (romainl’s SO post, tabpage.txt)

  • Quickfix, :grep, :make, etc (quickfix.txt, usr_30.txt)

  • Folding (fold.txt, usr_28.txt)

  • Diffing (diff.txt, usr_08.txt)

  • Spell checking (spell.txt)

Advanced
  • The Undo Tree (undo.txt, usr_32.txt)

  • Filetypes (filetype.txt, usr_43.txt)

  • Syntax Highlighting (syntax.txt, usr_44.txt)

  • Sessions & Views (starting.txt, usr_21.txt)

  • Client-Server (remote.txt)

  • Mastering the Command line (cmdline.txt, usr_20.txt)

  • The :normal command (various.txt)

  • Autocommands (autocmd.txt, usr_40.txt)

  • Scripting (Conway’s IBM DeveloperWorks article, LVSTHW, eval.txt, usr_41.txt)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment