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 [...]

Grokking the Zen of the Vim Wu-Wei

I love text editors.Which is a good thing, because I spend the overwhelming majority of my computing time (and, hence, sadly, most of my conscious life) in one text editor or another. For years I have been an Emacs user, only relatively recently moving to BBEdit with my adoption/inheritance of a Mac as a personal machine. Using and often administrating Linux-based systems has necessitated that I use Vi now and then, but I have long held the opinion that the only Vi command one needs to know is: Read more [...]