107 points · by mparramon · 12y ago · 132 comments
https://gist.github.com/btipling/0d6faa80b24ccee5caea
Note this requires +python, :he nvim-python for how to get that (involves pip install neovim)
You can't do something like this clock in vim without the feed keys cursorhold hack that breaks using leader keys. Otherwise I'm still using vundle and have made 0 changes in my .vimrc other than move it all to .nvim and .nvimrc. All my plugins and vundle worked out of the box.
The original binding of ; is super useful, and I would argue it should not be rebound.
; repeats the last f, t, F or T command.
There's also , which is the same as ; but in the opposite direction.
But I've found it to be most useful as page-down (with BACKSPACE as page-up).
map <space> <leader>
rather than simply setting mapleader to space directly. If someone else knows why, I'd be interested to know!Googling some, it seems to mean a backslash in the vimrc... but I don't really understand what you mean.
The only thing I never understood was why ; doesn't go beyond the current line (n does). Is there a way to make it?
For example, if you were at the beginning of the following text:
foo(bar, baz);
Typing f,dt) would change it to:
foo(bar);
The only advantage I can see in Vim over a modern solution is that it runs in the terminal (which I guess is useful if you like to remotely modify files in your production environment?). Is it that after they have spent so many years learning the arcane controls, users feel obligated to stick with it in order to justify all the time they've already invested?
I must say I've only spent ~2 months of my life using vim before giving up, which I think is already pretty long for an evaluation. I have never experienced or even witnessed the productivity gains you're supposed to get from mastering vim. All I've seen is very unintuitive shortcuts for Ctrl+Backspace advertised as unique features in the world of text editing.
I would be very happy if someone could point out to me the elephant that I am not seeing here.
Vim, in pure code editing sense, has two unique advantages that no other editors have or dare to have: modal editing and ubiquity.
Modal editing makes code editing absolutely DRY, as users can avoid any repetitive typing/clicking that they wish to avoid. It doesn't necessarily increase your code throughput much as a lot of the time you'll be thinking instead of typing, but it reduces the frustration of editing to almost zero when you do have to type, hence reducing distractions and cognitive load. Once you are familiar with Vim, its commands have close to one-to-one mapping to ANY ways you want to edit code.
For example, you want to change the html text two lines above? kkcit. Then come back to the place where you left? g;g;. Re-indent the lines? =ip. They look foreign and unintuitive to non-vim users, but are actually muscle memories for vim users. This is probably why vim users swear by it, but non-users find it hard to love.
Ubiquity is something you can only appreciate when you have to. If your work environment is Windows, this probably won't occur to you. But if you have to code in different OSes, or in SSH sessions, or in git commit, or in less/man commands, you'll find vim invaluable.
After all, Vim is just a tool, a very good one. But if your work doesn't have the need for it, you won't find it useful.
It may be true that some magical Vim invocation is the fewest key strokes in any text editor to edit text. In practice real world Vim users probably lose just as much time as they save trying to find the magical incantation. Beyond saving a few keystrokes, consider how wasteful it is to devote months of effort learning a new text editor when editing text is such a small fraction of the time we spend programming. Are programmers ever limited by how quickly we can type? No, we are limited by how quickly we can think!
Having said that, NeoVim is a fairly decent choice for a text editor. It is open source, runs in a terminal, is actively developed, and (vim) is installed on nearly every *nix by default.
Vim will not make you more productive. At [gratuitous company plug!], the
dude with Sublime is the best touch-typist, and the guy with an IDE is
good at refactoring.
These are false comparisons, and have absolutely nothing to do with Vim.Does your Sublime guy code fast because he's an amazing touch-typist, or because he has better command over Sublime's shortcuts and special features than your Vim guys do? If it's the former, then it's irrelevant. If it's the latter, then it clashes with the point you tried to make in the next paragraph.
Of course your IDE guy is better at refactoring code. (S)he's using an IDE. That's what they do, better than any text editor. Comparing editors to full-blown IDE's is fairly "meta" to the topic at hand. However, it should be noted that almost every major IDE has built-on or plugin support for popular editor keybindings. I use Vim keybindings with IntelliJ... and even with my fairly baseline Vim familiarity, I'm able work several times more fluidly than on vanilla IntelliJ.
It may be true Vim requires the fewest key strokes to edit text. In practice,
you'll lose more time finding those ideal keystrokes. It's wasted effort to
learn a text editor, because programmers are not constrained by typing speed.
This is just outright nonsense, and tells me that you personally have never learned to use any text editor well. Sure, I would agree that it's unproductive to scour StackOverflow for a magical one-step incantation for EVERY thing you ever do. However, that is not what being proficient with Vim (or any other text editor) means. It means you organically pick up on things over time, such that you aren't having to think about it when using them.If you pick up Drew Neil's book "Practical Vim", it's structured around 121 "tips". Each one is short, clear, and something that you can pick up and internalize in an hour. After the first 24 or so, you will absolutely be more productive that you would be with "Windows Notepad" bindings in the same situation.
It's not about crazy incantations that refactor your entire codebase in one keypress. It's about simple little things, that add up:
* I want to add an extra parameter to this method I just wrote. So rather than taking my hand off the keyboard and clicking there with my mouse (or hitting the arrow keys over and over), I just press "f)" to jump to the closing parentheses and start adding text.
* I want to replace everything on the current line, starting from my cursor position somewhere in the middle of that line. Rather than moving my hand to the mouse and dragging a selection, or holding <Shift> while hitting the arrow keys over and over, I instead just press "c$" and start adding text.
Sure, commands can be a bit arcane, but I learned them organically over a period of time... and these are real-world things that I do many times almost every single day as a coder. I probably only use 10% of Vim's available functionality, and that's enough to make my coding a much more fluid experience than it was before. Until you've experienced it first-hand, it's hard to grasp just HOW DISRUPTIVE it is to your flow and thought process to move your hand from the keyboard to mouse and back!
I don't care which editor (or IDE keybindings) you use. Vim, Emacs, Sublime, whatever. But you will absolutely be a more productive programmer if you pick one and dig into it over time. You ARE limited by your typing flow, and just don't realize it. If anyone really believes that isn't the case, then why bother to learn touch-typing? Take your two index fingers and try coding with the "hunt-and-peck" method, and see how it doesn't limit your thought process.
I've tried almost every editor out there: Vim, Emacs, Sublime Text, Textmate, Visual Studio, IntelliJ, and Atom. I've customized them all with plugins. I've even written plugins for most of them. My first editor was pico, quickly followed by Vim.
My toolsmithing goes beyond editors. I've tried different keyboard layouts to improve typing speed, settling on dvorak with qwerty shortcuts. I even gave chording keyboards a shot. I built Ag[1] to search code faster.[2]
I don't own a mouse. If I want to point at something, I use a trackpad. Switching to/from it is much faster than grabbing a mouse.
People don't want to hear this, but I could not be as fast in Vim. Even if Vim had every feature in my current setup, it would still be slower because Vimscript executes synchronously. Executing plugin code blocks Vim's UI. If a plugin spawns a subprocess, the UI will be blocked until it exits.
With Vim, you can't start a search and examine another file while it's running. This problem can be worked-around by using multiple Vims or searching from the command line, but then you lose quick opening/replacing of results. You can also abuse certain AutoCmds and updatetime to get a sort-of working async execution, but it requires each plugin have its own event loop.
I agree with kansface: Vim users may type less, but they don't move faster. I have yet to see a Vim user who has impressed me with their speed. I typically see wasted motion, waiting for commands to finish, and fixing mistakes in regexes. Even your example invocations are as good or better in Sublime Text.
I want to add an extra parameter to this method I just wrote. ... I just press "f)" to jump to the closing parentheses and start adding text.
That does not jump to the end of the function definition. That does a search for ) on the current line. If your cursor isn't on the right line, you're SOL. Also, ) shows up in many places. It may not be part of a function definition in the language used. In my setup, "cmd + r, up" goes to the previous function definition no matter the language. If I want to go to the end, that's ctrl + m.
I want to replace everything on the current line, starting from my cursor position somewhere in the middle of that line. ... I instead just press "c$" and start adding text.
For me, that's ctrl + shift + e, (start typing). Unless you have a $ key, both are three keystrokes.
If you use Vim and you're happy with it, great. But I would heavily discourage anyone from switching to Vim. Editors and UIs have come a long way in the past 25 years. Even with nerdtree, YCM, and other plugins, Vim can't catch up. NeoVim looks promising, since it fixes Vim's architectural problems.
1. https://github.com/ggreer/the_silver_searcher/
2. http://geoff.greer.fm/2011/12/27/the-silver-searcher-better-...
Since you mentioned you're using vim keybinding yourself, I thought I'd mention that any time you type x$ (where x stands for delete, change, yank, etc), it's better expressed as X[1]. You mentioned c$, but C is the same thing.
[1] - Vim actually breaks this pattern on y—Y is the same as yy out of the box. But almost every vimrc I've seen remaps Y to y$ for consistency.
vi and emacs seem like magic if you're coming from something like SublimeText. Compared to modern IDEs like VisualStudio or IntelliJ products, however - not so much.
vi users tout the rapid text editing features, but you can generate and navigate code just as fast with an IDE - out of the box - no configuration incantations or third party packages required.
Until very recently (early to mid-2000s), IDEs for open source web frameworks were non-existent, unaffordable, or slow. Once you have a working vi or emacs setup, there's a lot of inertia in place that discourages switching.
That explains the continued popularity of vi, imo.
You can navigate code and you benefit from powerful autocompletion (well, depending on your language, because it may quickly degrade to "laughable" with something a bit dynamic). However, the pure text editing experience with vanilla Eclipse/VS is rubbish compared to Vim. In addition, there are languages for which IDE-based code generation/autocompletion is not that interesting due to the language being a lot more compact. And with something like syntastic + the right language plugin, a strongly-typed language gets syntax checking, a description of the type of a variable, and possibly autocompletion. I use both Eclipse (with a Vim plugin) and the real Vim, and it feels much nicer not have to deal with the resource and mental overhead of a full-blown IDE. I think the only feature I really miss when working OCaml/Merlin in Vim is being able to get a list of call sites of a given function in the current project.
So the IDEs make it feasible to manage all the poor horizontal "abstractions" (complections, really) with all the different files and paths and whatnot. But they're much inferior to vi(m) for editing text.
Granted, if you don't do much text editing (writing, modifying, moving lines around) - the work you actually do do ("programming") - won't benefit much from a great text editor.
I used vim for small java projects before inner classes (massive spill of code/classes across files and folders) -- and it was pretty painful. When I changed to use Literate Programming - and could easily work on one file, letting the system generate the arbitrary structure java needed -- things went much more smoothly.
So, yes, YMMV - but if what you do is write/edit stuff that fits in a sane text format, a great editor is a great help. If what you're doing is composing objects from a large standard library of objects, you probably want an object editor like a visual, image-storage (as in vm image) based system like Smalltalk.
See all my guides for more demos: http://tuhdo.github.io/
Those IDEs only work on some languages, and force you into their workflow. Emacs and vi are both more all-encompassing and less restrictive.
However all the major languages and frameworks are covered by IDEs, and the workflows they enforce are good enough for 99% of developers.
Programmers who are working in a fringe language or who need a specific workflow - vi and emacs are great options - but these days it's a disservice to recommend those out of the gate to a new developer.
I hope Neovim is a pathway out of that, and makes configuration a breeze.
Vim is a Linux/Unix text editor used via the terminal. Notepad++ is for the Windows GUI environment. Apples and Oranges.
Why is a good terminal text editor important? When you are SSH'ed into your server and you need to adjust a configuration file, you require a good terminal text editor. It also is very good for C programming, and a lot of C programmers use it extensively. There are many other reasons. From a Windows GUI environment, you won't really be able to compare or relate, or understand why vim is so good.
You can use it on Linux, MacOS, and Windows (among many other operating systems).
vi is even more ubiquitous. Even if one doesn't use vim as one's primary editor, it would behoove one to learn the basics of vi, as it's available on virtually every operating system.
Vim in specific actually has a rather nice GUI called gVim. It's what I used when I used vi-style editors, which overlaps with the last time I used Windows seriously. So, yeah, gVim works on Windows and has for well over a decade now.
Almost all of the editing I do is in a consistent environment on my development machine and I don't see the point of using a lowest-common-denominator tool when I don't have to. I'm sure with some work you can bend Vim into something approaching the power of an IDE but why would you bother? Text editing is a pretty small part of the work of development, after all.
This is pretty much exactly what you're not supposed to do in any form of modern system administration. How would you rebuild that server, or move it to a different provider?
Edit a local definition of your server for Ansible or Salt or Puppet or whatever else, and let those systems deal with making the server match your definition.
The one thing where vim beats hands down any vanilla text editor, such as you have listed, is the speed of text editing facilitated by its mode-based usage paradigm. It's not the number of features, but the pure effortlessness of the frequently used editing actions vim offers.
The technical details are detailed in many vim tutorials. The speed comes from the fact that for a large set of common non trivial operations there is a one or two key sequence that establishes the precise edit you wanted.
The way to discover these actions needs a bit of self conscious learning: You notice you do something repeatedly (sometimes painfully obviously) and figure out if there is a quick set of operations in vim to do the thing you wanted to do.
To get the full power of vim you need to spend enough time with it so the frequent editing actions you want to achieve are automatically decomposed in your backbone to vim operations, at which point you can edit text at the speed of tought.
Also, the split window dual or triple document editing combined with fast commands for switching to different places in the documents is really nice.
Notepad++ is my second editor of choice as well.
And that's for a marginal use case programmers don't fall much into (if you're frequently re-arranging lines or performing the same actions of blocks of text, then you aren't exactly programming).
Even a small improvement in iteration time has a dramatic effect in the way you approach problems. Vim lightens the mental overhead on making text manipulations so that you simply think about what you want to do and your fingers do it.
Whenever I find myself repeating something painful, it is almost always solved by searching the resources in the Vim community for solutions.
But it is frustrating to reach for mouse and click several times for a task that can be easily done quickly with keyboard. In another words, it interrupts the flow.
ssh -X host
Then remotely run whatever tool you want, including Sublime or Geany or Kate or even Wireshark if you wish.
> I must say I've only spent ~2 months of my life using vim before giving up, which I think is already pretty long for an evaluation.
Hmm yeah that is pretty long, you should see the advantage of it by then. Have you used it a lot in those two months? Because I've alternated between Geany and vim for like 6 months before being fluent enough in vim that I could get work done at the speed I could in Geany (or Notepad++ for that matter). But if I had seriously used vim for everything that I used Geany for, I think I would have easily gotten there in 2 months.
> I would be very happy if someone could point out to me the elephant that I am not seeing here.
Beyond that it's simply faster in text editing (code, plain text, or something like Markdown for that matter), I guess it's also a way of using a computer. I've never liked the mouse for anything besides games or GIMP and even navigate many websites by keyboard in Firefox. Ideally I'd spend all my time in a terminal, typing away with my hands almost never leaving the home row. But that's just me, I know noone else who is so fond of their keyboard vs. a mouse or touchpad.
http://www.viemu.com/a-why-vi-vim.html
http://stackoverflow.com/questions/1218390/what-is-your-most...
The elephant you are missing is UNIX itself. The best IDE ever made.
I am by no means a master of vim's varied features but the best productivity gain for me is vim running in the terminal. I use a lot of command line tools (grep still beats most things for search and the git command line tool is still better than any editor plugins), it's just much more convenient for me when it's all in the terminal and I can switch between them seamlessly with keyboard commands especially when using something like tmux.
I used vi, vim and was an Emacs user between 1996 and 2005 when coding on UNIX platforms.
But I have came to UNIX from the home computers, so I was already spoiled with Borland IDEs and Amiga editors before my first UNIX experience.
Got to experience Smalltalk and Oberon environments as well.
Always looked for IDE experiences in UNIX land, and since I moved 100% into JVM/CLR land, I only use Emacs or VIM for editing configuration files or when on systems where my beloved IDEs aren't available.
Even for C++, thanks to LLVM work, IDEs can offer much more that vi or emacs do, even with CEDET.
- Powerful automatic indentation: https://raw.githubusercontent.com/Bruce-Connor/aggressive-in.... It does not only indent the current line, but the whole Semantic context around your cursor.
- Live grep: http://tuhdo.github.io/static/live_grep.gif
- Access to a list of project with a few key strokes: http://tuhdo.github.io/static/helm-projectile/helm-projectil...
- Quickly access any file in your project, as large as Linux kernel, instantly, regardless of where you are in the project, and within a few keystrokes: http://tuhdo.github.io/static/helm-projectile/helm-projectil....
- Jump to any file depends on context, even if the file path is in a plain ASCII text file: http://tuhdo.github.io/static/helm-projectile/helm-projectil...
- Copy files from anywhere to anywhere: http://tuhdo.github.io/static/helm-projectile/helm-projectil....
- Delete files anywhere; files are always at your finger tip to do whatever with them: http://tuhdo.github.io/static/helm-projectile/helm-projectil....
- Switch between other files with same names but different extensions: http://tuhdo.github.io/static/helm-projectile/helm-projectil.... Work not only for C/C++ but other languages, and is customizable. You don't have to configure anything, like adding include paths for the command to search. Everything is automatic. Just use it as it is.
- Jump to tag definition, from Emacs's own parser or external parser like GNU Global: http://tuhdo.github.io/static/c-ide/helm-gtags-jump-dwim.gif
- Jump to any definition from a list of definitions in source tree, even for Linux kernel: http://tuhdo.github.io/static/c-ide/helm-gtags-select.gif
- Jump up to parent: http://tuhdo.github.io/static/c-ide/senator-go-to-up-referen....
- Do you like outline tree?: http://tuhdo.github.io/static/c-ide/sr-speedbar.gif
- Interactive outline tree: http://tuhdo.github.io/static/c-ide/helm-semantic-or-imenu-w...
- Easily move back and forth using the interactive outline tree: http://tuhdo.github.io/static/part3/helm-semantic-or-imenu-2...
- References retrieved from its Emacs internal parser: http://tuhdo.github.io/static/c-ide/semantic-symref.gif.
- Beautiful compile output: http://tuhdo.github.io/static/c-ide/compilation-compile.gif
- Frontend support for GDB: http://tuhdo.github.io/static/c-ide/gdb-many-windows.gif
- Code completion: http://tuhdo.github.io/static/c-ide/semantic-boost-demo.gif.
- Open man page for symbol at cursor: http://tuhdo.github.io/static/part3/helm-man-woman.gif.
- Emacs open 39MB C file: http://tuhdo.github.io/static/performance.gif
- Emac opens multi-gigabtye file: http://www.emacswiki.org/VLF
- Emacs is a bit torrent client: https://bitbucket.org/ukaszg/aria2-mode/
You can see more demos in:
+ Emacs Mini Manual: http://tuhdo.github.io/emacs-tutor.html + C/C++ Development Environment for Emacs: http://tuhdo.github.io/c-ide.html + A Package in a league of its own: Helm: http://tuhdo.github.io/helm-intro.html + Exploring large projects with Projectile and Helm Projectile: http://tuhdo.github.io/helm-projectile.html
Note that in the demos you may see me type in the commands. You can think of it like the start menu in Windows, but actually those commands can be executed quickly with a shortcut. I type in the commands for demonstration purpose to Emacs users.
Those demos are just tip of the iceberg.
We in the real world have to use compiler toolchains specified by our customers.
Do you also have demos for:
- Navigate in binary files
- Semantic refactory
- Background compilation
- Debug unit tests
- Cross reference to source control checks and software tracking issues
- Parallel code debugging
- Visualization of C++ data structures
- Semantic code navigation
- Database integration
- UML diagrams with two way code editing
- UI design
- Integration with application servers
- Graphical visualization of profiling data
- ...
Emacs is a fine software, but it is stuck in the past.
That's just scratching the surface. I've been using VIM for around 3 years. Most of the day almost every day. And I feel like I'm barely acquainted with what it can do. Still, it is one of the most important and vital work tools and its hard to imagine life without it. I'm pretty sure I would leave any job I wasn't allowed to use it.
Admittedly I went through a rough month or two getting started, but I could see right away that the potential gains in productivity were worth the cost and I'm glad I did. Sort of like learning to type which some people refuse to do because hunting and pecking is faster and easier short term. I'm sure you have seen people like this. And some actually type at amazing speeds for two fingers, but it doesn't compare with what they could do if they took the time to retrain themselves.
The problem now is that Vim is so ingrained in muscle memory I type splotch all over any other editor and web browser I touch. Hold on a second, I need to arrow back and clean up this comment... bbbbhhh
The second one is modal mode (editing and navigating/command).
I am trying to warm up to ST and the vim plugin is okay but some things are really missing (capital R)
All the things mentioned in the article are just there to not miss the nice features of other editors.
I don't use buffers explicitly at all, only tabs instead, like in any IDE. Sometimes vsplit. I even have custom mappings for ctags to open stuff in new tabs instead of buffers. I treat hidden buffers as legacy needed mostly for technical reasons. Yet I keep seeing other people using multiple buffers, switching between them. So, should I reconsider, maybe? And why?
I used "lusty juggler" before but 'gt' is a very natural way for me to "go tab" now and I like it better. Macvim makes it trivial for me to arrange tabs in a consistent order, for example html file to the left of its js file. The tabs also give me a kind of quick view of what my current "project space" is.
Two tab-y things that I find useful are:
* alias "vi -p" (to open files in tabs)
* "vi --remote-tab" (to add a file to an existing session in a new tab from the command line)
Part of why I like tabs may be because I don't do split windows often in vim. When I want to have two files side-by-side I use my os window manager (CMD+right to move current window to right side of screen, etc).
Actually it is. That thing is called "leader" and is used exactly for the same purpose as author uses backslash. So better way to write
:nmap \o :set paste!<CR>
would be :nmap <leader>o :set paste!<CR>
Reasons to use "leader" are discussed more than once, so I'll leave reading the docs/blogposts to you.I prefer unite[1] to ctrl-p[2], it's much more flexible.
1: https://github.com/Shougo/unite.vim 2: https://github.com/kien/ctrlp.vim
My config is here: https://github.com/wridgers/vimto/blob/master/rc/25-unite.vi...
[1] https://github.com/szw/vim-ctrlspace [2] https://github.com/zhaocai/GoldenView.Vim
With i3[1] you get split windows out of the box, but the splits are fixed by 1/2s (kind of a Russian Doll box model) that you can then incrementally resize via hotkey by some percentage of your choosing.
That's different than GoldenView which automatically gives the focused window the lion's share of screen real estate, thus providing a kind of distraction free mode with the added ergonomic benefit of not having to crane one's neck to left and right when working with split windows on a 27" monitor.
Maybe Xmonad, Awesome, and other highly programmable TWMs provide such functionality (or are trivial to pull off), although haven't heard mention of it (spent a couple of months with Awesome before switching to i3).
I can see the need for more windows on a 27" (or 30") though. Maybe xmonad with "Spiral" or "Spiral Golden Ratio" does something similar (although probably not quite the same)?
https://www.haskell.org/haskellwiki/Xmonad/Screenshots
Generally I just use a standard tiled layout, with 2/3 of the screen for the "main" window (vertical split, works best on a 16:9/16:10 display), and bring witch ever window I want there with alt+enter.
But then, I find that things that change "automatically" end up being distracting (eg: relative line numbers in vim) -- so odds are we just have different preferences.
There's plugin for it in vim. Even several of them, as always. I don't remember which one I used and if it was completely ok, but I can find https://github.com/skammer/vim-css-color right away.
Why? Well, there could be multiple answers, but essentially there's one main reason: it's just dead simple, while vundle and other ruby-inspired ones are not. Pretty much for the same reason I like pathogen+git thousand times more than emacs' package manager.
So even if it could be arguable that pathogen is better than vundle, there's completely no reason not to advise it.
The major feature is that it can install plugins in parallel. I've switched from vundle to it and have been quite happy.
pathogen loads the plugins which is all I need. Does Neobundle do something else?
Pathogen loads plugins, but it doesn't manage them. Neobundle lets me list some plugins in my vimrc and it'll take care of installing them, updating them, and even only loading them on filetypes where they're useful.
Pathogen does none of that and I find every one of those features useful. One of the big ones, honestly, is just the simplicity of listing a new bundle in my vimrc, syncing it to all computers, and having it deal with getting it. Much better than syncing large git repos across computers.
Also, I find MacVim to be a better experience than Vim in the terminal.
iTerm lets you do this, but Terminal.app doesn't.
http://apple.stackexchange.com/questions/48796/iterm-as-a-sl...
Unlike others in this thread, though, I do find the original behavior of ";" useful occasionally. I bind that behavior to ";;", which is still quite fast to type whenever I do need it.
But it is frustrating otherwise.
Remove two `a' characters of the current line:
fax;.
Note: no mode change necessary
Also, line editing in /bin/{,k,ba}sh -o vi without `ftFT;,' is a pain.