by crazygringo · 14y ago · 0 comments
I just don't get it. Ever since newer editors got block editing or multiple insertion cursors, and RegEx find & replace across multiple files, and searching filenames to open... I feel like I've already got everything I need!
What am I missing out on? I don't feel like my text editor holds back my productivity. Using something like Sublime, I never think, man, if only Sublime did x, it would save me five minutes, twenty times a week!
I've never had anyone explain to me what specific kind of code editing is so much more productive in vim than in any other editor. Can someone give me a real-world, commonly occurring example?
Or is it not about productivity? Is it an interface thing? People like the way it feels to use? The article explains the "feeling" I always hear about, how vim is so much better, but for the millionth time, fails to tell me why, in a way a non-vim-user can understand.
In vim you don't just move around with arrows, then delete and then replace the text you want. What happens is you can use noun-verb associations to do things.
For example on a line like this:
var foo = "bar";
I could be at the beginning of the line and type the following keys to change the inside of the quotation marks: ci"baz<esc>
In sublime I would do the following: <cmd>→←←⌫⌫⌫baz
The difference between the two was an epiphany for me. In vim I could actually use verbs and nouns to determine how I will edit the text in front of me. I now have a language that I can use to edit text rather than editing the text using the most manual of tools and the verbs and nouns combination are only limited by my imagination and the plugins I install.Also, not having to move away from the home row makes me feel much faster. Having to use Alt/Control/Arrows makes me cry. (I know you can't avoid Control in Vim, but in this example it is not required.)
ci"baz<esc> is 7 keystrokes, only one of which is a jump.
<ctl-F>bar<esc>baz is 8 strokes and two jumps. It also requires typing the entire string in quotes. If the example were
var foo = "The quick brown fox jumps over the lazy dog";
The vim example would not change but yours would.
I'm not trying to be an a-hole, use what you like, I'm just saying, that for me the attraction to vim is the strive toward the minimization of keystrokes, especially ones that require me to move my hands.
However, if I was actually faced with this problem, I'd use End, Ctrl + Left, Ctrl + D, baz, which is a total of 7 keystrokes. (if you don't release Ctrl)
The vim example was 8 keystrokes. (" is shift + ') I have no doubt that you could manufacture an example that shows a benefit for vim, but I think that the advantages are overestimated by heavy vim users.
Edit: Your longer string example is a good example of a task that's more efficient in vim.
Gives back a list of interesting people.
Not that I think it matters if you use Vim or anything particular for that matter.
i think it's easier to grab the mouse, dlb click bar, foo
with vim, it's still easier than grabbing the mouse. that's the litmus test of text editor interface effectiveness. the mouse is awesome, hard to beat. so if your editor beats it, game on!
<cmd>-<right>, <option-left>, <option-shift-right>, baz
And considering you didn't have to press <mode>: beforehand, it can be just as fast.
I'm a vim user, but using it for something like Objective-C in place of the wonderful autocomplete in Xcode would be a totally dumb thing to do. It's simply not smart enough to improve my productivity, even with the slight speed increases with text-manipulation.
edit: link - https://github.com/JugglerShu/XVim
The same holds true for Sublime Text. Instead of using the arrow keys, you could do any of the following:
Ctrl+H : Replace
bar : Find what
baz : Replace with
Ctrl+Shift+H : Replace first match
<esc> : Exit replace mode
or Ctrl + I : Incremental Find (finds and selects finding)
bar : Find & select text
baz : Overwrite selection
or Ctrl+<Right>+<Right>+<Right>+<Right> : Reach the word bar
Ctrl+d : Select word under cursor
baz : Overwrite selection
or Ctrl+P : GoTo Anything
# : Goto word
bar : Goto word 'bar' & select it
baz : Overwrite selection
I agree that vim's vocabulary is very expressive and very powerfull. I switched to Sublime Text because tweaking vim to meet my needs was just too much effort, even for simple things. Couple this with even more effort to make it play nice with Greek (my native language), and the switch came naturally. f"ci"bazYou don't use your mouse to move the cursor around a document.
After a while you just look at the document and your fingers move and the cursor moves, you can get anywhere in the file in just a few jumps. It's not the same as using a mouse or a touchpad where you need visual feedback to place the cursor in a specific place and the movement is continuous. It feels like it takes less mental processing to do that and it is less distracting while you are concentrating on actual work.
It's hard to explain, and I'm one of those people who using vim, vimperator and vim keybindings in his shell. The only other times I've reached the same levels of muscle memory taking over complex behaviour (besides sports) is when playing video games or driving a car. You concentrate on what you want done and some lower level part of your brain and your hands just takes care of it.
A pointer based system just can't compete in terms of immersion.
I have a feeling I just typed a lot and didn't do any better of a job explaining it.
Explaining nifty Vim backflips is the wrong way to sell Vim. A 15 minute session of `vimtutor` was enough to enlighten me. If I had needed a proficiency in Vim to appreciate Vim, I would've never started.
I never felt it either, back in my TextMate days. But one Thanksgiving holiday week, I told myself, you know there's got to be something to this if all these people I respect swear by it. I decided to use vim-only for two weeks, no matter what, and I'd switch back if I wasn't hooked. I was.
The biggest advantage I find in using something like vim or emacs is that you never have to switch between the mouse and the keyboard — in fact its awkward to use the mouse and that makes it difficult to get accustomed to. It allows you to seamlessly transition between code navigation and code writing, and you develop a kind of rythme that I never felt like I achieved with a graphical text editor.
Other nice features are the ability to write custom scripts and repeat actions, but these can generally also be done in other editors. One huge reason I made the switch is I end up writing code on remote machines on occasion, and I can almost always do so in my everyday editor: vim. All my personalization can be transferred over to the remote machine in a single scp command and the experience remains the same no matter where the files live that I'm working on.
Intuitive: most commands resemble natural language, without awkward or arbitrary mappings. For instance:
- w: (forward) word;
- cw: change (forward) word;
- c2w: change 2 (forward) words;
- 2cw: twice change word;
- ciw: change inner word;
There is no intervening translation. For instance, to change a word in mainstream editors, you delete it first, then start entering the new text. In Vim, it's one command: you think "change forward word", you issue the "change forward word" command.
Consistent. For instance, double letters work on lines:
- cc: change line;
- dd: delete line;
- yy: yank line;
and capital letters work till the end of the line:
- C: change till the end of the line;
- D: delete till the end of the line;
- Y: yank till the end of the line (not so in vanilla Vim, but I've remapped it because consistency matters to me).
Modular: you compose commands. For instance, / is the search command and then:
- d/testo: delete until the next occurrence of "testo";
- c/testo: change until the next occurrence of "testo";
- etc.
Comfortable: limited usage of modifier keys. Vim saved me from RSI.
Portable: letters and Shift keys are in the same position on any keyboard, be it on a desktop, a laptop, etc. whilst each laptop manufactures has its own idea about where Control, Alt, Arrows, PageUp and PageDown should be.
Hope this helps.
A lot of people here have made the point that vim has a steep learning curve that eventually pays off, which, to me implies that intuitiveness is either lacking or besides the point. Still, I agree with your other points. I'm thinking of going back to it to minimize hand strain.
If I learn the new verb c, which deletes and puts me in insert mode, I already know that I can type c3w to change 3 words, or ci" to change the phrase inside quotation marks.
Because all verbs work on the same set of nouns and adjectives I can intuitively know what many commands do - even though I've never tried them - as long as I understand the parts that make up the command.
I think the steep learning curve comes from the need to learn a richer and more precise way of editing, while you may be used to get by with a sloppy one. I had a similar experience when I switched to the Dvorak keyboard: I learned for the first time how to touch-type, while the Qwerty grew on me from hunt-and-peck.
Since you are considering about going back, here are some useful custom mappings of mine: - swap p and P; - map Space as PageDown; - map Shift + Space as PageUp; The last two mirror the way most document-displaying applications work. Generally, don't think twice about remapping some commands either to correct historical quirks of Vim or make it behave consistently with other applications you may be using, hence lowering your memory load.
Have fun
Change forward word is in a mainstream editor: [Shift]+[Ctrl]+[Right]
Change line: Home, [Shift]+[End]
...and so on...
Moreover you forgot to mention that you always need to switch modes...
Mainstream editors are pretty efficient, unfortunately in the UNIX World there are hardly any good ones. The best ones I can think of are Eclipse and gedit.
Unfortunately there is no Notepad++-like thing on UNIX. (And Kate just became messy and buggy when KDE4 came out.)
BTW: Has any vim fan ever used the refactoring feature in Eclipse? Or edited Code during runtime using the Graphical Debugger? I doubt it... ;-)
I stand corrected.
> Change line: Home, [Shift]+[End]
Here there is a translation at work: the editor lacks an atomic "change line" command, so users resort to "move cursor to the beginning of line, then select text up to the end of the line", which is something you could do in Vim, too, if you wanted.
> Moreover you forgot to mention that you always need to switch modes...
I don't understand. Do you mean you have to switch between Insert and Normal mode? If so, this is where newbies - including me some years ago - make their bigger mistake: you don't linger in Insert mode, you hit Esc as soon as you end entering text. Either you are typing text, or you are in Normal mode. This is the reason you need the Esc key as easily accessible as possible. On my keyboard, it is on the Caps Lock key. And : is unshifted.
> BTW: Has any vim fan ever used the refactoring feature in Eclipse? Or edited Code during runtime using the Graphical Debugger? I doubt it... ;-)
I'm with you on this. Still, people confuse Vi-style editing with either Vim or other Vi clones. Vi-style editing is neither Vi nor Vim nor Elvis nor [name an editor]. I used Eclipse and Visual Studio, yes, and guess what: I had Vi-style-editing plugins on both. What people call "the best of both worlds".
EDIT: Vi-style editing rocks at editing text, which is a subset - or not the same - of editing code. A user editing code with a mainstream editor offering powerful code-completion and refactoring facilities may have at her disposal a more powerful tool than a user editing code with a Vi-style editor lacking such facilities.
And yes, vi(m) is inferior to much less sophisticated editors when it comes to juggling large chunks of code. Or maybe not...
Anyways, now that I have a Macbook, I need to learn vim because it lacks all the cool keys you have on a PC keyboard :D At least I'm now using at nearly as productively as gedit or the like. (On average)
BTW: This caps-look trick is awesome, I'll set it up now!
I don't have to think about how to perform most tasks in vim. My fingers just execute what my brain wants to see happen. That doesn't mean that vim is the greatest thing ever, just that I'm used to it and it's fast enough to get the job done.
One concrete benefit to vim is that it works very well over crappy network connections, and it's installed on most every Linux system you're going to touch.
You often don't notice how useful something is until you're used to it.
This can't happen in emacs because editing isn't modal (though commands are very contextual). vi* is certainly easier on the hands than all the cording but getting rid of modal editing means no more wasting time when your brain is out of sync with the editor.
Having said all that, I'd still pick a nice IDE over either of them, since the IDE understands the language I'm editing and can e.g. change from simple minded "mass edits" to actual refactoring.
That's not to say it's the best overall. If you like to customize your environment, emacs is better. If you like tight OS integration and advanced GUI features, many editors are better. If you want the most productive environment for a specific programming language then some IDE is probably better.
But when it comes to raw keyboard editing, why is vim so powerful?
Well, it starts with normal vs insert mode. Because insertion is a specific mode, it means every single key on the keyboard is available for direct editing commands. Of course you can have modifier commands as well, but that's nowhere near the convenience and efficiency of plain typing.
So right off the bat you start with an order of magnitude more command possibilities in an easier to access position (chordless). The commands of the basic keys are designed to be a solid fundamental set of building blocks for all common editing tasks, and they are assigned mnemonically.
The power of the fundamental commands is then multiplied by the vim grammar, whereby commands are applied to objects, which again are a terse and mnemonic description of some chunk of the file.
In practice this means that very short unmodified alphanumeric strings you type can produce powerful changes. It's not just keystroke-counting, it's the fact that these keystrokes are also a meaningful language that makes sense mnemonically, not just through muscle memory. The more you practice, the more different ways you start to see to effect a given change. As you become more proficient, you can do more and more with a single command.
This is important because commands are atomic, and you can repeat the previous command by hitting '.'. The power of this isn't really apparent until you grok the breadth of things a single vim command can do, but have you ever wanted to do a regexp search and replace and spent a long time crafting it and still had to step through it because you were afraid it might screw something up? With vim commands you can often times use simple command repetition to avoid complex regexps ('n.n.n.n.n.n.n.n.' to find next/repeat command).
Sometimes I'm surprised by the mileage I get out of that, but it's really the tip of the iceberg. Because you also have macros, which are just recorded sequences of commands. But the cool part is that commands are made up mostly of regular characters, so the macros look like plaintext, and vim treats them that way as well. Vim has 26 clipboards called registers, and these registers function both as text storage and executable macro space. Meaning you can record a macro, and then paste it into a buffer, and tweak it via normal text editing, and then pull it back in and run it. Because the commands are so simple and mnemonic, it's actually astonishingly easy to do this. Once you are comfortable with it, you find yourself recording, running and dropping macros in less than the time it takes to write a single regexp. I have spacebar bound to a specific quick-macro slot so I can record and then hold down space to mass-apply a macro (my key repeat-rate is maxed as well :), this lets me do the types of things in seconds that previously would have me busting out the sed/awk book. It's very hard to communicate the impact this has on your editing workflows to someone who doesn't get it. It's sort of like a git user telling a svn user why easy branching is so awesome, the svn user just doesn't get it because they've already convinced themselves they don't need branches precisely because they are so hard to use.
In short, the vim advantage is about powerful editing primitives and easy ways to compose them. There are certainly many great editing ideas that are not in vim, but in terms of the fundamentals for keyboard editing, it's hard to imagine anything better.
:!make
Then run with:
:!./myprog
In both cases, the output will be viewable in a temporary window. You can also pipe the output of a shell command into a vim buffer (aka file) by prefixing you command with "r":
:r !./myprog
This takes all the output from ./myprog and lets you view/edit it in vim.
If your language has a more involved build process, chances are someone has written a plugin to help you and posted it on the vim scripts page: http://www.vim.org/scripts/script_search_results.php.
Enjoy :)
Alternatively, my own work flow consists of using tmux to have a split screen terminal, Vim left, REPL right.
I use CUA and can be productive everywhere immediately, even if it may be a bit less efficient.
Then you reap productivity benefits for the next couple decades.
I mean, I've never really felt the need to program an add-on to text editor. I download syntax highlighting packages, and there are common macros like "remove trailing whitespace" already installed. Keyboard shortcuts can be changed in lots of editors and OS's. In the past, I've definitely been upset that a particular editor didn't support a particular feature, but by now they've progressed enough that I don't really feel that anymore.
- A little hook to use an external Python program (cheating, I know) to look up the definition of the word under the cursor in the OS X dictionary.
- Several customizations for org-mode, which I use for anything where I want to make an outline, including and especially to-do lists.
- I actually still have some code to do "smart tabs" (http://www.emacswiki.org/SmartTabs) for some modes, though that's now probably obsolete if I would only configure up the code mentioned in that list for C modes. (I'm already using it for e.g. Python code.)
- Some configuration for LaTeX editing, like packages AUCTeX doesn't know about, converting words/phrases into \gls (glossary) references.
I actually have less custom stuff in .emacs than I thought. Having a programmable editor does mean that it's relatively easy for other people to write some really useful stuff which I then get to use. I have some local modifications to other people's packages which I don't have time to enumerate right now.
"Common" macros are the least interesting. The most interesting macros are the ones with no name, the one-time ones that you build on the fly. You have a file with ten thousand lines of:
foo.rb
bar.rb
baz.rb
…
… [9997 more lines like these]
and you need to turn the file into something like this: // Run the foo command
def foo()
end
// Run the bar command
def bar()
end
// Run the baz command
def baz()
end
… [9997 more blocks like these ]
That's 56 keystrokes in emacs: You record a macro that transforms one line appropriately, then execute it 9999 more times, all on the fly in about twenty seconds.1. `command + A` to select all
2. `command + shift + L` to split the multi-line selection into multiple single line selections (one curser at the end of each line)
3. `delete delete delete` to get rid of ".rb" on each line
4. `command + shift + ←` to select the identifier
5. `command + C` to copy each identifying word on each line (!!!!)
6. `←` to get to the beginning of the line
7. Type "// Run the "
8. `command + V` to paste each identifier on each line correctly (!!!!)
9. Type " command\ndef "
10. `command + →` to go past the identifier already there
11. Type "()\nend\n"
Also took about twenty seconds. This multi curser thing has been completely redefining how I mass edit code - it's quite fantastic, and as far as I know ST2 is the only editor that does it this wonderfully.
qrIdef<space><esc>f.Di()<return>end<esc>jq
qr ' record a macro into register r
I ' insert mode at start of line
def<space><esc> ' type def then exit insert mode
f. ' find the dot
D 'delete the rest of the line
i()<return>end<esc> ' type () return end
j ' next line down
q ' exit macro recording
call it with 9999@r
This looks unwieldy but it's all done interactively. (also if you mess up and you want to rework the macro you can paste it out with "rp to paste the r register rework it and then put it back into another register. 0"ry$ (start at column 0 then into r register r yank to end of line)
cat file | perl -p -e 's-\s(.)\.rb-// Run the $1 command\ndef $1()\nend\n-'
start recording a macro:
qa
Then enter this sequence of keystrokes[1]: 0veyO// Run the ^R" command<esc>j0f.C()<cr>end<cr><esc>
Then exit macro recording with: q
Then enter the command: :g/.rb$/ norm @a
to run the macro on every line ending with .rb (allowing comments in the input, just because (of course it would be nice to make that regex in :g look for "lines that start with comments" and ignore them explicitly)).
If I counted right, thats 57 keystrokes, and I might have been slightly inefficient in my usage, of course, if that one keystroke is part of a command my fingers just do, there is no effective difference :)
[1] I know it was exactly that sequence because I just pasted the macro buffer, which of course can then be edited, saved back to the buffer and run in edited form.
Also, you don't have to actually program the editor yourself to reap the benefits of a programmable editor. Let's be honest, most modern editors have mostly overlapping functionality. However, one of the benefits of emacs being programmable is that it's self documenting. I can find out how to capitalize a word problematically without having to go to google by using `M-x apropos RET capitalize RET`.
It's not always about programming. It's about configuring and extending to suit it to your problem.
Pylinting and running python code. ,c(mapped to :make, not shown here) to pylint(not need as I run syntastic but still), ,x to run
augroup python
au!
autocmd FileType python nnoremap<buffer> ,x :w<CR>:!/usr/bin/env python % <CR>
autocmd FileType python setlocal nosmartindent
autocmd FileType python setlocal makeprg=pylint\ --reports=n\ --output-format=parseable\ %:p
autocmd FileType python setlocal errorformat=%f:%l:\ %m
autocmd BufRead python setlocal efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
autocmd FileType python setlocal path+=$PYTHONDIRS
augroup end
ERB and Jinja2 shortcuts. \1 for <% {cursor_here} %>, \2 for <%= {cursor_here} %> etc inoremap \1 <%<Space><Space>%><Esc>2hi
inoremap \2 <%=<Space><Space>%><Esc>2hi
inoremap \3 {%<Space><Space>%}<Esc>2hi
inoremap \4 {{<Space><Space>}}<Esc>2hi
A mini calculator function, lots of snippets, some saved macros etc.It's not about changing keyboard shortcuts. It implies you can only remap what already exists. It's about giving you infinite canvas to paint on. This isn't unique to Vim. I am just saying having the capability to do so is important.
I have a function for my work log which gets the date, figures out the previous Monday's date and dumps a formatted weekly log for me to fill out.
I wrote an entire budget tracking application which generates a forecast and dumps it to a csv file
Wrote a utility to mark and optionally delete duplicate files in a dired buffer
Convert a windows path name to a cygwin one
Functions to add local sales tax and remove local sales tax, same for tips.
Perforce source control, helpers to do blame functionality and other stuff that benefits from pulling Perforce output into a buffer
The most used feature would be keyboard macros which are endlessly useful for any repetitive editing task, which can show up unexpectedly at any point of the day
Occasionally have to write throw away custom code to create some boiler plate code, such as turn the API documentation for some errors into a C++ array of structures that can be manipulated in code
Full client for Redis
Yes, but you can't change the editing model as easily, e.g. converting a modeless editor in a modal one just by changing a few shortcuts.
My take is that there are two camps: people who adapt themselves to the tools they use and people who try to adapt their tools to their ways and their ever-changing view of the world. The former want the tool to help them to get things done, the latter want the tool to help them to get things done their own way. The former look at tools as tools, the latter look at tools as extensions of themselves.
Highlights: a Python IDE with refactoring, inference, search, etc.
Some hacks for TRAMP which lets me remotely edit content on arbitrary servers transparently.
A Python repl.
A generic compliance checker for Python code.
An undo module that presents undo/redo history as a visible tree that you can traverse arbitrarily.
A git client that has some EXCELLENT features.
A function to dynamically reload my environment.
A macro for my python debugger injector.
Code to unhtml HTML content and a whitespace cleaner-upper.
An interactive environment to experiment with and test regex.
A mode for CSS that highlights hex-values with the colors they represent, making their properties visual.
An interactive HTTP REST client interface for testing HTTP APIs.
A clone of hacker-typer in elisp.
Modes for clojure, erlang, haskell, rust, etc.
And a nyan-cat for my progress bar.
either you share this or not. If you saw anything else, you are probably misreading or reading too much there.