In many scripts that I write, I often construct programs in a "functional style". That is to say, I basically define a lot of functions at the beginning, and then later apply these functions. This results in a sequence of nested function calls, wherein I type out:
- function name
- its arguments
- next function name
- its arguments
...and so on.
For cases in which functions are "piped" together, the output of one function is an argument (usually the first, but not always) to the next function, the output of which is an argument to the next function, and ad infinitum. In prefix-notation, the key movements can be very jumpy if you type out this sequence from left to right. For example, how would you type out the second line of the following [Python] example (~mul~ is multiply, ~truediv~ is divide)?
from operator import add, mul, truediv
print(truediv(mul(add(1,1),2),4))
If I had to write the same set of operations linearly (from left to write, without jumping around), I am more likely to use the notation of function composition. Building on my previous example in Python, I might write
from functional import foldr, compose, partial, flip
print(foldr(compose,add,(partial(mul,2),partial(flip(truediv),4)))(1,1))
I think this is because I associate each function with its own arguments and prefer to type them out in succession, rather than filling arguments to another function before the argument list for the first function is complete (as would be required to type out the first example from left to right).
I noticed this because I've been an emacs user for a long time and only recently tried out viper/vimpuse and vim. In emacs, I might do something like
- [type function name and arguments]
- C-a
- [type next function name]
- C-e
- [fill in rest of arguments]
- C-a
- [type next function name]
- C-e
- [fill in rest of arguments]
...and so on, with occasional use of M-b, M-f, M-DEL (backward-word, forward-word, backward-kill-word) if I mess up or forget something.
I recently found out about C-o in vim, which is a lifesaver - but I find that the equivalent keys would be
- [type function name and arguments]
- C-o 0
- [type next function name]
- C-o $
- [fill in rest of arguments]
- C-o 0
- [type next function name]
- C-o $
- [fill in rest of arguments]
...and the rest; backward-word, forward-word, and backward-kill-word equivalents would be C-o b and C-o w, and C-w.
So this got me thinking that to program in vim, I may have to grow a larger working memory, so that I can pause the construction of one function as I fill out another, and so on down the stack. Also, in construcing text documents, I find that I edit (kill, copy, yank) quite frequently even before I finish a complete thought, which is not so amenable for vim's operational style of "stay in normal mode, burst of text in insert-mode, and back to normal mode", which seems to presume that I am capable of producing something worth editing during my forays into insert-mode. To use vim, I find that I deliberate more as I type to reduce the frequency of switching between modes. Is this because I'm naturally spastic, or once I master or commit a suitable range of vim key commands to muscle memory, I'll stop thinking they're so different?
If you program in both emacs and vim, do you find yourself thinking about and construcing your programs and blocks of text differently in each editor?