Vim: Insert Mode is Like the Passing Lane

Insert mode is not the mode for editing text. It is a mode for editing text, because both normal and insert modes are modes for editing text. Insert mode, however, is the mode for inserting new/raw text directly from the keyboard (as opposed to, e.g., from a register or a file). Thus, you will only be in insert mode when you are actually typing in inserting (raw) text directly. For almost every other editing operation, normal mode is where you will be. Once you grok this you will realize that, Read more [...]

From Acolyte to Adept: The Next Step After NOP-ing Arrow Keys in Vim

We all know about no-op'ing arrow keys in Vim to get us to break the habit of relying on them for inefficient movement. But, as this post points out, it is not the location of the arrow keys that makes them inefficient, but the modality of the movement: single steps in insert mode is a horrible way to move around when normal mode provides so much better functionality. But here is the thing: while normal mode provides for much better and more efficient ways to move around than insert mode, Read more [...]

Taking it to a 11: Dramatically Speeding Up Keyboard/Typing Responsiveness in OSX

If you use a Mac/OSX, then enter the following commands in your shell and reboot: $ defaults write -g KeyRepeat -int 0 $ defaults write -g InitialKeyRepeat -int 15 If you live in a text editor or the shell, or otherwise spend most of your typing hammering away at the keyboard like I do, then this makes an absolutely wonderful difference in the responsiveness of any typing activity. It will make your previous typing feel like you were pecking away in slow motion at the Read more [...]

Dynamic On-Demand LaTeX Compilation

Most of the existing approaches to integrating LaTeX compilation into a LaTeX writing workflow centered around a text editor (as opposed to a fancy-schmancy IDE) are horrendously bloated creatures, aggressively and voraciously hijacking so many key-mappings and normal functionality that it makes your Vim feel like it is diseased and is experiencing a pathological personality disorder of some kind. Yes, LaTeX-Suite, I am looking at mainly at you. I did not want a platoon of obnoxiously cheery elves Read more [...]

Setting up the Text Editor in My Computing Ecosystem

Image from WikiMedia Commons Basic Setup of Shell to Support My Text Editor Preferences By "text editor", I mean Vim, of course. There are pseudo-operating systems that include rudimentary text-editing capabilities (e.g. Emacs), and integrated development environments that allow for editing of text, but there really is only one text editor that deserves the title of "text editor": Vim, that magical mind-reading mustang that carries out textual mogrifications with surgical precision Read more [...]

Smart (`infercase`) Dictionary Completions in Vim While Preserving Your Preferred `ignorecase` Settings

Dictionary completions in Vim can use a 'infer case' mode, where, e.g., "Probab" will correctly autocomplete to, e.g., "Probability", even though the entry in the dictionary might be in a different case. The problem is that this mode only works if `ignorecase` is on. And sometimes, we want one (`infercase`) but not the other (`ignorecase`). The following function, if added to your "`~/.vimrc`", sets it up so that `ignorecase` is forced on when dictionary completions are invoked via Read more [...]

Some Vim Movement Tips

Within-line character-based movement: `h` and `l` move you left and right one character, respectively. `fc` or `Fc` will take you forward to the next or back to the previous, respectively, occurrence of character "c` on the current line (e.g., `fp` will jump you forward to the next occurrence of "p" on the line, while `Fp` will jump you back to the previous occurrence of "p" on the line). `tc` or `Tc` will take you forward to just before the next or back to just Read more [...]

Vim Regular Expression Special Characters: To Escape or Not To Escape

Vim's regular expression dialect is distinct from many of the other more popular ones out there today (and actually predates them). One of the dialect differences that always leaves me fumbling has to do with which special characters need to be escaped. Vim does have a special "very magic" mode (that is activated by "\v" in the regular expression) that makes thing very clean and simple in this regard: only letters, numbers and underscores are treated as literals without escaping. But I have never Read more [...]

The Power and Precision of Vim’s Text Objects: Efficent, Elegant, Awesome.

Vim's text objects are not only a powerful, flexible and precise way to specify a region of text, but also intuitive and efficient. They can be used with any command that can be combined with a motion (e.g., "d", "y", "v", "r"), but in this post I will be using the "c" command ("change") to illustrate them. Imagine you were on a line looked like this, with the cursor on the letter "r" of the word "dry": print "Enter run mode ('test', 'dry', or 'full')" Then, after typing "c" to start Read more [...]

Neat Bash Trick: Open Last Command for Editing in the Default Editor and then Execute on Saving/Exiting

This is pretty slick: enter "fc" in the shell and your last command opens up for editing in your default editor (as given by "$EDITOR"). Works perfectly with vi. The"$EDITOR" variable approach does not seem to work with BBEdit though, and you have to:
$ fc -e '/usr/bin/bbedit --wait'
With vi, ":cq" aborts execution of the command.

Managing and Munging Line Endings in Vim

If you have opened a file, and see a bunch "^M" or "^J" characters in it, chances are that for some reason Vim is confused as to the line-ending type. You can force it to interpret the file with a specific line-ending by using the "++ff" argument and asking Vim to re-read the file using the ":e" command: :e ++ff=unix :e ++ff=mac :e ++ff=dos This will not actually change any characters in the file, just the way the file is interpreted. If you want to resave the file with the new line-ending Read more [...]

Filesystem Management with the Full Power of Vim

Just discovered "vidir" , a way to manipulate filenames inside your favorite text editor (better known as Vim). Previously, I would use complex and cumbersome BASH constructs using "for;do;done", "sed", "awk" etc., coupled with the operation itself: $ for f in *.txt; do mv $f $(echo $f | sed -e 's/foo\(\d\+\)_\(.*\)\.txt/bar_\1_blah_\2.txt/'); done Which almost always involved a "pre-flight" dummy run to make sure the reg-ex's were correct: $ for f in *.txt; do echo mv $f $(echo Read more [...]

Execute Selected Lines of (Optionally) Marked-Up Python Code in a Vim Buffer

There are a number of solutions for executing Python code in your active buffer in Vim. All of these expect the buffer lines to be well-formatted Python code, with correct indentation. Many times, however, I am working on program or other documentation (in, for example reStructuredTex or Markdown format), and the code fragments that I want to execute have extra indentation or line leaders. For example, a reStructuredText buffer might look like: How to Wuzzle the Wookie ------------------------- Read more [...]

Editing Remote Files With Your Local Vim Using the SCP Protocol

I love Vim! It is so easy enough to edit a remote file with my local Vim through the Secure Copy protocol: $ vi scp://user@remote.host.com/projects/foo/bar.py However, I often find myself wishing that bash completion was available to expand/complete paths on the remote system. Furthermore, when editing files outside of my home directory hierarchy, I have to remember to add an extra slash after the host name, e.g.: $ vi scp://user@remote.host.com//var/www/html/index.htm A solution Read more [...]

Buffersaurus – A Vim Plugin for Searching and Indexing Across Buffers

Description Buffersaurus is a Vim plugin for searching and indexing the contents of buffers for regular expression patterns or collections of regular expression patterns. Results are displayed in separate buffer, and can be (optionally) viewed with user-specifiable lines of context (i.e., a number of lines before and/or after the line matching the search pattern) or filtered for specific patterns. Global commands provided include (among others): :Bsgrep[!] {pattern} Search all buffers Read more [...]

Character/Word/Line Count of Selection in Vim (a non-Vimique Vim Command) Compared to Underlining Text (a Vimique Operation)

Every day I discover at least one new thing about Vim. Sometimes useful, sometimes not. Sometimes rather prosaic, sometimes sublime. This one falls in the useful but prosaic category: to get a count of the number of characters, lines, words etc. in the current selection, type "g CTRL-G". This is a useful command, and good to know, but its invocation is a rather obscure key-mapping. In other words, just like most of the commands of your garden-variety "dumb" modeless editor, it can only Read more [...]

A Tale of Two Vim Commands: ‘s’ and ‘c’

Vim continues to surprise me with its wonders. Sometimes (many times, in fact) things do not make sense, and I am perplexed as to the reasoning behind them. Then, one day, I grokked it. And from that day on, I can never imagine any other way of doing it. An example of this was my confusion over the apparent redundancy of two fundamental commands. In normal mode Vim, "s" (mnemonic: "substitute") and "c" (mnemonic: "change") are both ways to remove some existing text and then go into insert mode. This Read more [...]

Vim: Making Those Arrow Keys Work for You (Or Why the Anti-Arrow-Key Propoganda is Wrong)

The Great Controversy A standard dictum amongst experienced Vim users is not to use the arrow keys to move around your document. This dictum is often repeated again and again, in tones that range from the taken-for-granted to hysterical-zeal. The most common reason given for this is that using the arrow keys takes your hands away from the home row of your keyboard, and thus is wasteful both in terms of time and energy, whereas the standard Vim movement keys ---| h, j, k, and l ---| keep your hands Read more [...]