Hacker News new | past | comments | ask | show | jobs | submit login
A Good Vimrc (dougblack.io)
355 points by sanjeetsuhag on Oct 10, 2015 | hide | past | favorite | 170 comments



Rebinding jk to escape because escape is too far away seemed like a fairly ugly hack to me, especially because you can't type it anymore without waiting.

Why not simply rebind caps lock to escape? Caps lock is used awfully little, considering how prominent its position on the keyboard is. On Linux, you can rebind it by adding

  setxkbmap -option caps:escape
to your .profile. If instead of an additional escape you prefer it to be swapped around, use

  setxkbmap -option caps:swapescape
This is perhaps the most impactful change on my vim workflow.


Hi! Author here.

Fair points. I'm gonna start out on the defensive: I didn't post the article, which kinda stinks because if I knew it was going to get such attention I would have updated it to my current setup. Anyways as the 1.5 year old article states:

  This article will almost certainly fall out of date with my vimrc in the very near future
I don't do jk escape anymore. I have since abandoned custom escapes because I work often enough on remote servers with vanilla vimrcs that don't have custom escape bindings set that the penalty I pay having to stop and consider which environment I'm in before every escape wasn't worth the small quality of life enhancement from having it set locally.

Good tip on caps lock, though I currently have it set to control which I find is a much better use of the key. Especially once you know about ctrl-o.


I once told my wife an amusing story I'd read in Australian Personal Computer where a computer technician was told by a secretary that she was great with computers, said technician was very happy and joked that he was glad as the last person he had to help thought that the way to input capital letters was to press the caps lock key, the capital letter and then press the caps lock key again... To which the secretary asked "what's so funny about that?"

Anyway, I chortled after telling this to my wife, to which she looked at me with a puzzled look and asked me what the punchline was...


To be fair, some of the fastest typists use caps lock instead of shift, since it makes the shift action modal, instead of requiring coordination of multiple fingers at once.

http://forum.colemak.com/viewtopic.php?id=1309


Oh! My wife will be pleased :-)


You may wish to look into xcape. Currently i have capslock = escape when pressed alone, or control when pressed with another key. [0] https://github.com/alols/xcape


> Currently i have capslock = escape when pressed alone, or control when pressed with another key.

This is brilliant idea. And it works on OSX too - using http://apple.stackexchange.com/a/132569


Thank you for this! I've been using capslock as Ctrl for a long time time, and fell into the bad habit to use C-c to exit insert mode.


ctrl+] will act as escape in any vim out there. At least that I've encountered.

Having caps as ctrl makes it really easy to hit.


Ctrl-C seems to work in any vim (though, I think, not actual vi), and at some point my muscle memory rewired itself to that. It's usually directly under my left hand, and it's a keyboard shortcut I use elsewhere, like in the shell.


ctrl+[ works in any vim because it sends the exact same character as Escape. Unless your terminal emulator is very oddly configured, then it will work the same.


ctr+[ you mean.


This depends on what you're hosting your article on, but you could either generate the vimrc programatically from the code in the article or generate the article from comments placed in your vimrc. Similar to a .litcoffee file.


Do you think that updating your article would make more sense now. It would benefit users who read it now.


I came across [xcape](https://github.com/alols/xcape) this week. It is a great little utility which can map escape to another key like control or shift but only when pressed once. For example you can configure the control key to be escape if pressed once, but will still act as control if held down. Combined with mapping caps lock to control, I now have the best of all worlds. Highly recommended.


Ack, no. Bind caps lock to Ctrl, and escape is now the trivial chord C-[.

As an added benefit, getting used to this layout will help you out with migrating out of vim to emacs.


yup. i find binding ctrl <-> caps way more useful than binding ctrl to esc (and my keyboard even has a ctrl key made for the caps place and a caps key made for the ctrl position).

BUT there's also a way to do something like: if you press and hold caps, it acts like control. but if you press and release quickly it acts like esc. stevelosh describes how to do that on osx here http://stevelosh.com/blog/2012/10/a-modern-space-cadet/#cont... but i still haven't found a way of doing that on linux.


See link to xcape in this thread.


C-[ is trivial in an English keyboard, but in the Spanish layout it's an awkward three-key chord. I use the latter, and I've been happily inoremapping jj to <esc> for a decade.


So your suggestion is that, rather than pressing Caps Lock to escape, one should press Caps Lock and [? How is that better (assuming you’re using VIM)? Regular Ctrl isn’t hard to reach.


I'm a fan of 'C-c' for escaping.

That keybinding works to go from insert to normal in most filetypes (looking at you sql) without the binding so unconfigured vims are still usable with it, and it's really easy to reach.

I will admit it's a little more awkward than caps-lock, but I use my caps-lock for ctrl and thus can caps-lock-c instead.

Escape isn't really useful anywhere else in the system, so capslock as ctrl or super makes more sense to me.


I agree. If you're on Mac, the tool Seil will allow you to map Caps to Esc. And I use SharpKeys when on Windows.

The downside however is when you're stuck using someone else's computer or don't have root on Mac and Windows. I don't find myself on someone else's machine often though, so for me it's worth it to not have that half second delay.


To add to this, Seil [1] is free and has been available for many years. If anyone here uses it, a donation is probably a good idea.

[1] https://pqrs.org/osx/karabiner/seil.html.en


I use jk, and agree that binding escape to something easy is the most impactful change on my vim workflow.

I encourage everyone to try it. The amount of times in the last year where i've had to actually type the string "jk" is exactly...one? I think, though perhaps I was imagining even that one. I suppose it really doesn't matter what you bind it to as long as you can execute the escape whilst keeping ALL of your fingers on that good ol' home row.

I guess I should also note that I never use vim except in my own environment where i know i have my own vimrc. I totally get why people who are always using remote computers without their vimrc would want to keep default key bindings and thus be forced to use ctrl-[.


I'm another jk devotee, I use caps lock a lot more. I don't get the complaint about using other servers. Either you control them in which case :tabnew ~/.vimrc and adding imap jk <Esc> takes a few seconds, or you don't control them and so you just run the map command locally for your current file. My vimrc is around 200 lines but the jk bind is the only thing I must have these days. Enough forced Eclipse has beat it out of me, but I once had the habit of typing jk outside vim while thinking.


> [...] especially because you can't type it anymore without waiting

This was my thought when I saw this mapping for the first time, and when I started customizing my vimrc I opted for using caps lock as well. It didn´t take long for me to change that and start using kj instead -- in the end it was more common for me to type constants in all-caps than typing "Reykjavik."


I use 'jf' instead of 'jk', so I can type "Dijkstra" occasionally, not to mention they're both on the home row, under your index fingers, typically have physical nubs on the keys, and no words in any language I can find contain the letters 'jf'.


What about IKEA names?


That's when I switch over to emacs and ikea-mode.


Did you know that IKEA names tend to be names of towns and places in Sweden/Norway? So if IKEA names have jf then Swedish/Norwegian must have that letter combo as well..


IKEA also frequently use first names (for people), e.g. Billy or Erik, and even abstract words, e.g. Poäng (point, as in "that's a good point".).

As for jf: I searched through the pdf of a 1300 page Norwegian dictionary, and the single word in there containing jf is the abbreviation "jfr." which is the same as the abbreviation "cf." (confer) in English. So jf appears to be a very good choice.


Note that in Norwegian (and, I think, Swedish and Danish) words are joined without a hypen. So anythime a word ending with "j" like "marsj" ("march/marching") is joined with a word beginning with "f" like "fart" ("speed") you'll see "jf": "marsjfart" ("marching speed"/"cruis(e|ing) speed").

Also jfr isn't a particularly rare abbreviations - so ymmv. At any rate, with how words can be combined in Norwegian, there's generally no good safe choice...

Another example, in line with the IKEA theme: "dusjforheng" ("shower curtain").


Ah, hadn't thought of that. I had a feeling there had to be more words, but couldn't come up with any off the top of my head. Apparently I write very little Norwegian in vim (I use jk for Esc).


FWIW (again, not sure about rules for joining words in Swedish):

    for abb in jk jf;
    do
      echo "Occurances of ${abb}:"
      grep ${abb} -c \
      /usr/share/dict/{bokmål,nynorsk,british*,svenska}
    done

    Occurances of jk:
    /usr/share/dict/bokmål:90
    /usr/share/dict/nynorsk:39
    /usr/share/dict/british-english-insane:20
    /usr/share/dict/svenska:70
    Occurances of jf:
    /usr/share/dict/bokmål:31
    /usr/share/dict/nynorsk:32
    /usr/share/dict/british-english-insane:0
    /usr/share/dict/svenska:0
So jf seems pretty safe for English, at least. Apart from when adding "jk" to your vimrc …


Words are joined the same way in Swedish as described above for Norwegian, so not safe there either.


As someone else pointed out, caps lock is an excellent compose key, that opens up a world of new characters that can be used throughout the environment.


I set jk to Esc, and not CapsLock, because I use CapsLock to capitalize.

I'm currently working on a vimrc that caters to people like me, those who only use CapsLock to capitalize, and avoid all chording. When I'm done, maybe I can map Shift to Esc.


Ironically, since installing the 'youcompleteme' add on, I've started using the 'jk' escape method more, since ctrl-[ and escape only close the autocomplete window, not out of insert mode.


Here's what works for me:

capslock remapped to ctrl jw for escape in vim

jw is convenient if capslock is used as a control key. I had to pay attention to what I was doing in a vim file in order to remember what I had escape mapped to :)


I've tried remapping Caps Lock, but I find that the stretch to hit that key eventually irritates my ulnar nerve. I'll stick with "jk" (or "ii" on Colemak).


Instead of remapping keys, I've always used Ctrl-[ for escape.


Same here, and I don't even understand why people want to remap Ctrl to Caps (but I never used Mac, so I don't know: maybe it is inconvenient on their keyboards). And recommendation to remap "jk" to Esc always almost made me ignore the whole post, because being able to enter any letter sequence I want is the very least I would expect from a goddamn text editor.


I find pushing ctrl to be at an extremely inconveninet position. Do you look at the keyboard when you type? If so it might explain it. Being a touch typist my left pinky is 1 character away from Capslock so it's way easier to press.


No, I generally don't. But thinking of it, I don't know where my pinky usually is. I mean, I don't always keep it on "a": after all, I have to press Shift pretty often anyway. And Ctrl is pretty close: I don't even need to move my finger to put fingertip on Ctrl, I just use side of the finger to push it.

I tried to use Caps Lock instead of Ctrl, and it wasn't uncomfortable or anything, I just didn't get used to it. I don't remember how it happened that I started to use Ctrl again: maybe it's because I don't always use 1 computer and Ctrl is too important of a key to be looking for every time I need it on somebody else's keyboard. Anyways, currently Caps is Caps and I don't really use it often. Or maybe even ever.


I never need to type "jk" unless I'm pasting a certificate or a hash/UUID/key. It's worth the remap for me. As always, to each his own.


Capslock is already in use as my Compose key.


I don't use vim as my go to editor so I may be asking a silly question; does it just use idiotic defaults or something? I've only met a couple 'vim users' who could just hop onto someone else's vim setup and be productive, and I've never met a single vim user who could use someone else's setup without making comments about everything being different.

I guess the question is do people modify vim cause they can or cause they have to?


For me, it's because I can. When I find a job I do often, I add it to the config, when I find a tool that makes a job easier I pick it up. Bare, freshly installed vim is quite useable, but is missing the affordances of my personally customized environment.

It's kind of like the difference between being able to cook and walking into a strange kitchen and immediately knowing where everything is. In my home I'm comfortable, I know that the vegetable peeler is in a different drawer than the steak knives. In a friend's home, I'm just going to have to ask where something is every few minutes if I want to get work done.


The default vim config is pretty barebones.

Actually, one of the main goals of Neovim[1] is to provide better defaults[2], such has syntax highlighting.

[1] https://neovim.io/

[2] https://github.com/neovim/neovim/issues/276


Holy ish! Neovim has progressed so much. Exciting.


I'm actually using it currently and I really enjoy the built-in terminal. It makes my workflow much better.

Be aware that some plugins might have some bugs. I also got segfaults when using multiple terminals (although that's quite rare).


Interesting. I tried out the built-in terminal and found that I couldn't navigate around panes as quickly as if I just used tmux instead. Are you using the default mappings, or have you made them easier to use somehow?


The current defaults discussion is at https://github.com/neovim/neovim/issues/2676.


On my home machine I have a vimrc of about 30 lines, but I could do without most of it, I could probably reduce it to about 5 lines if I had to. So whenever I use vim on a computer at university or on a new machine in the workplace, as long as it has syntax highlighting and auto indent on, which it usually does, that's fine for me.


Correct, the defaults are indeed idiotic, probably because they are from the last century. I even have a freaking plugin installed to properly close buffers (https://github.com/cespare/vim-sbd/).

It's indeed harder to use vim without my customizations. I guess it's more like a "build-your-own-editor from parts" kind of thing.


The defaults are just fine. (As a sysadmin) I tend to work on systems that mostly aren't my own workstation and have never found it to be an issue (can't be arsed to push out my own config everywhere, not to mention other admins may not like what I like). I imagine it might be different for a coder...line numbers and pretty colors are nice I guess?


If there is only one thing I can complain about vim/vi, it's the esc key. The key is too far away to reach easily. It is most accessible with the little finger, which is our weakness finger. Coupled with the fact that it's likely the most important key in vim. I hate it.

So when I use a non-configured vim, it's the thing that I miss the most. The rest is trivial.

However, using someone else vim is completely different!

You must keep in mind that vim is much similar to a programming language. You can remap keys all over the place. You can create exotic combinations that do wonderful and/or terrible things with few key strokes. You can install plugins that argument and alter vim behaviours.

Jumping into a well tuned vim setup is not unsimilar to starting to use a new programming framework. It's hard to be productive right away.

In that case usually, I just rename .vimrc, remap <esc>, do my things and get out of the way.


Yes, the vim defaults suck.

If you're building a new vimrc or want a common ground for pairing, I would recommend checking out [vim-sensible](https://github.com/tpope/vim-sensible) by tpope. It's a vim plugin that provides a set of sensible default options.


Vim Bootstrap (www.vim-bootstrap.com) is one I recently discovered and really like.


Vim's default are indeed dumb, but what you described is not a vim-specific problem. Walk into any room full of coders and try to use their computers; you'll discover tons of weirdness that can't be explained by anything except by a desire to be treated like a princess.* Things like rebinding basic shortcuts, reversing the scroll direction (Mac users will get this), swapping Cmd/Ctrl, using some obscure shell or even infecting other people's machines with some haphazardly scp'd dotfiles.

This kind of overcustomization is fine if you live in a basement and work on a project alone. As soon as you become a part of a team, please stop. You're making cooperation unnecessarily hard and spending company time on an optimization that isn't.

*I sometimes joke that coders who refuse to conform to the industry standards should wear a tiara as an indication they are, indeed, unique snowflakes free from the usual social expectations. It seems to work.


> that can't be explained by anything except by a desire to be treated like a princess

Do you mean a desire to be more efficient?

Am I some kind of princess because I decided to use a different keyboard layout than the default? That I decided to learn a different language than the one I was told to learn in school? That I wanted to install a different operating system than the one that came with my computer?

Your comment is not just hostile, it is unbelievably pretentious. You quite clearly don't understand why people customize things. If you want to live in your undecorated, perfectly square single-room house you're welcome to do so without telling others they're not "part of the team" for having different preferences than you do.

Damn...


Realistically, what justification is there any more for working on somebody else's machine, being force to use their config? Ok, if your machine explodes and you need their's for a bit fine. But in the long run, the amount of times where you need to actually edit some code by typing on another person's machine should be vanishingly small.

I'm all for standards when it comes to collaborating on code. But when it comes to text editors, vim configs, even using emacs (get out your crosses, holy water and sliver bullets), it shouldn't really matter from my perspective.


This, I don't want anyone else's disgusting unwashed hands on my keyboard or mouse. I work with a guy who regularly walks out of a bathroom stall and back to his desk, bypassing the sink entirely. He tried taking over my machine, I was like hell no. So I get a rep for ocd germaphobe, big deal.


How do people who like to customize their environment do pair programming? I belong to that group, and I like the idea of pair programming, but I've never had the chance to try it in practice...


tmux/screen sharing work just fine.


Far more common these days, I think, than actually typing on another person's keyboard is sharing an account on a server (physical or virtual). Not that that's a great practice.


This reminded me that more often than I'd like, people want me to debug their dev setup on local Vagant VM (I'm an Op and among other I partially support the development environment). I hate that, to use the different layout and not having my tools ans aliases.

Tried to tell them to use dev env on some local shared machine, where it's easier to setup and manage, but they refuse and want to do these things in a local VM.

I just try to say that there might be semi-legit cases when you must go and use other person's laptop.


You may personally be more efficient but as a team or class our overall efficiency drops by being different. Now I'd argue that the class is more important than you personally.

We can agree that it matters a lot less what your own personal setup is as long as it saving stuff in the same format but I wouldn't say it doesn't matter at all.

As soon as someone asks you for a bit of help you're going to be slowed down by understanding each other system. If we conformed, teaching a junior how to profile code will be easier than showing him how to do it with your vim setup, for example.

Finally I'm never going to buy the efficiency of keyboard shortcuts when coding is generally worth the time sink in learning them over clicking a mouse in an IDE. Sure, they will make you faster, but I'd rather most people took longer and delivered solutions that weren't actually worse than the problem. All too often the quick people land me with stuff that pisses me off.


> Finally I'm never going to buy the efficiency of keyboard shortcuts when coding is generally worth the time sink in learning them over clicking a mouse in an IDE.

So here's your problem, right. I'm not selling this to you. If I were stating it, I'd be stating it as a fact. Most of HN would agree with it because they themselves experienced it. Indeed the only ones who would disagree with it are the ones "not buying it".

Try it if you want, I don't really care if you don't, but you're making assumptions and reacting to this with fear instead of curiosity. And that, above anything else, is something that will make you less efficient not just in your work but in your entire life - so you're in a pretty bad spot to lecture others on efficiency...


Nope, that's where you assume my problem lies. I actually used vim myself for about 8 years as a developer and still generally default to it as my editor doing ops. I just honestly don't think it's generally worth the bother.

That said, I typically wouldn't mandate uniformity either as, as you said, I'd rather work with the curios. I think this ones a crapshoot, but the same folks are much more likely to know a bunch of useful stuff too.


>> but as a team or class our overall efficiency drops by being different.

Wait, what? How does this follow? In my whole professional career I don't think I've ever sat down at another persons machine, so I don't see how Bob using vim/querty and me using emacs/dvorak could possibly impact our aggregate performance as a team.

Do teams really spend a chunk of time fiddling around on each other's computers?


Maybe you have a career that's different from mine. I've spent time upskilling, pairing and mentoring. It's helpful to sit next to these people and show them something and as I said I can teach a junior how to profile on my tricked out vim setup, but helping them do it if we're both using intellij will be less effort in my opinion.

Honestly though, I often work with developers (I'm a contractor so I work with tons of people ) who use GUIs for git or vagrant and the like. If you sit down next to me with your windows system using a gui for some development tool asking me questions about why it doesn't work, I'm going to struggle to help you.


Hey I'm sorry to change focus here, but your peers are going to have a much more effective learning session if they're "doing" rather than "watching". I know it takes longer to fix their problem that way, but theyll appreciate the motions when they have to go through them themselves.

I can understand what you mean though. I've certainly had to take over a couple of times with fresh juniors and interns, but their setup was usually very under-customized, and those times were pretty rare. People who had complex setups were usually smart enough to figure out directions on their own, and really just wanted some documentation or an example to guide their way.


It isn't just writing code faster, but also navigating (thus comprehending) faster, and in some cases writing code with less errors.


Has this "faster" thing been measured and profiled scientifically in some kind of A/B testing?

Or it's just based on subjective feelings and cargo cult?


This whole discussion is ridiculous. When you customize your vim key bindings, you do so either on your machine, or your profile on some remote server. One does not mess with other's computers or settings. But ...

> Or it's based on subjective feelings and cargo cult?

What if it is? What if I am _factually_ not "more efficient", what if I am just "happier" with _my_ setup on _my computer_? how does that in reality could have a negative effect on a team? I am of course assuming that the "we mess around with other's machines or profiles" is an obvious-enough bad practice that it doesn't happen. Right? Right!?


In my tests it's always made quite a difference if your fingers are already on the keyboard, and you want to invoke some specific, non-interactive function; you can usually hit the shortcut, whatever it is, in less than the time it takes to move to the mouse alone.

Few would argue that moving from keyboard to mouse and back between every keypress would be more efficient than just typing one key after the other, as is more usual. The same applies, when activating a shortcut: for example, starting with my hands on the home row, I can do 10 activations of copy (Cmd+C), returning my hands to the home row between each activation, in about 8 seconds. Using the mouse in a similar manner to select the corresponding menu item takes about 22 seconds. Just moving my hand from the home row to the mouse and back again ten times takes around 9 seconds.

(These times are all slightly approximate, because I'm going by eye, because with 2 hands on the home row I don't have a hand left to operate the stopwatch.)

The longer the shortcut, the more time it takes to activate, of course; here, I picked a nice easy one, in the form of Cmd+C. Maybe that's cheating. Some of the fiddlier emacs shortcuts can be quite time-consuming to enter - the rect ones are particularly bad - C-x r C-w, that sort of thing. I wonder how much quicker those are? But I'd imagine they'll still win out over moving from keyboard to mouse to menu bar and back, since for shortcuts you invoke often, muscle memory takes over and you can rattle them off without even thinking.

Maybe all those piano lessons helped after all.

The reader is invited to use their preconceived opinions about microoptimization to decide which conclusion to draw.

(I have no particular opinion about what to do if your hand is on the mouse to start with. Generally I move it back to the keyboard if I don't know how to do something with the mouse, or leave it there if I do. For things such as moving the cursor, or scrolling, the mouse is very effective anyway; usually effective enough that in many cases it's worth using in preference to the keyboard, if you don't have some non-interactive higher-level motion that you could conceivable invoke, such as M-x forward-sexp, or whatever.)


Interestingly I've also played an unfathmoly amount of FPS games to the point where my mouse skills are pretty fricking nifty, so I may be bias, but I'd question why I have both hands on the keyboard when trying to read and understand code anyways?

The thing is, I'm not arguing that you're not quicker anyways. Just that the speed difference between someone good with a mouse and someone good with keyboard shortcuts generally don't matter in a world where IDEs exist and where understanding code properly takes longer than just navigating through it.

Anyways, I'm not actually bothered what you use as long as you can take care of yourself, which a user with a weird vim configuration generally can. However, as I said in a post above, if you're struggling to use git, I'm only gonna be able to help if you use the cli. That won't be the vim guy, but it will be the windows guy who asked me for ftp access.

Point is though, I think the counter argument that using the same tools is super valid. I don't think it's the most important thing in the world, but I do think it has merit.


https://ux.stackexchange.com/questions/30682/are-there-any-r...

With that said, this is in the realm of common sense for anyone who's ever used vim bindings at least semi-seriously. We're not just talking millisecond improvements, we're talking about doing some tasks that can take several minutes in mere seconds.


Faster than what? Faster than clicking on the function name and seeing where it's reference in an IDE? Like I said, I dont buy that your vim plugins and shortcuts are going to help you understand that code better. I'm in no way arguing we should all be using notepad though.


This isn't an argument about "vim" vs "IDEs". You really should read the entire thread.. or re-read it.


Linked post is about vim.

The first post of this thread is about vim setups all being different causing problems.

The next post is about vim, configs and developers not conforming being a pain in the ass.

The next post is about you taking offense to his colourful comment ( he was poking fun btw, you shouldn't be offended )

The next post is me backing his point as having merit without the negative connotations. Specifically mentioning IDEs.

The next post is saying it's not just about writing code quicker but navigating and understanding quicker.

Then there's me again saying is how is a tricked out vim really any faster than an IDE to the point it matters.

Then there's you saying I don't understand the thread.

Are you trolling or just totally missing the point because I don't agree with you? Either way, my comment was totally on point for this thread but I'd rather be arguing the point than responding to silly off-topic comments.


Have you seriously missed that this is a discussion about general customization of things such as keybinds/mappings, shells, dotfiles etc? Somehow you turned that into "IDEs vs vim" and you were the only one mentioning IDEs. Customization can happen in IDEs too, you know...


Listen, I get that you're outraged that I've had the audacity to question the worth of customisations but nitpicking an example doesn't encompass the entire argument doesn't detract from the point that this is a thinking mans game.

As it stands I'm not trying to take your toys from you. If you can take care of yourself, do what you like. If you are likely to need some assistance you'll likely annoy anyone who needs to touch your computer.


Glad someone had the same reaction I did. What's the value of conforming to a company standard when it makes you less efficient? Yeah, okay, chastise me and call me a princess - I'm going to go work somewhere else for someone who doesn't hold such a misguided set of principals and let's me work in my own best environment.


>Am I some kind of princess because I decided to use a different keyboard layout than the default?

Maybe you just bought into some myth:

https://www.utdallas.edu/~liebowit/keys1.html


I made my own layout because Azerty is unusable for programming; hitting three keys to produce an @ sign or a {} is inexcusable. And, since I play a lot of games, I wanted the default qwerty wasd keys.

But sure, I bought into some typing speed myth, whatever floats your boat. XKCD774.

https://github.com/jleclanche/dotfiles/blob/master/X11/xkb/s...


Probably missed the whole "Maybe" thing I wrote.

In your case those are valid reasons and apply to several "national" layouts -- but there are many people who go for the cargo cult version too.


> This kind of overcustomization is fine if you live in a basement and work on a project alone.

Hahahahaha! You trolling?

I wonder, you work like 5 people on the same computer or something? And if 'yes', the OS doesn't support multiple users?! I don't wanna ruin a happy relationship or anything, but it's 2015... ;-)


Wait, am I missing something obvious here, or are you seriously complaining about people reversing the scroll direction on their own computers?


Apple reverses scrolling by default. I don't know about other coders' computers, but there are people who don't know how to change it, and whenever I boot into recovery mode it gets reversed.


It's only "reversed" if you consider the other direction "normal". Either one makes sense: Mac acts like your finger is moving the page itself; X11 and Windows act like your finger is moving the location indicator on the scrollbar. Either one makes sense a priori, but once you're used to one the other becomes intolerable.


Nah, I change back and forth between Mac and Linux. It's bearable.


Try using it Down Under...


I'm actually glad this complaint was made. But only because I was unaware that you could change the scroll direction on a Mac.

I will definitely be making that "overcustomization" on my Mac. :-D


"Vim's default are indeed dumb, but what you described is not a vim-specific problem. Walk into any room full of coders and try to use their computers; you'll discover tons of weirdness that can't be explained by anything except by a desire to be treated like a princess."

Yes, shame on those evil coders for wanting to use their own computers in a manner which they find most enjoyable and productive! They must be assimilated! Give me a break.

"Things like rebinding basic shortcuts,"

Again, give me a break. Developers should be allowed to configure their individual machines in any way they wish. Different people work differently.

"reversing the scroll direction (Mac users will get this),"

When you've worked on platforms for decades where the scroll direction works one way, then end up on a platform where it is reversed, what is wrong with changing the new system to work the way you are used to? Yeah, I might decide to get used to the differences, or I might change it because I prefer it the old way, but who cares?

"swapping Cmd/Ctrl,"

again, who cares -- it's their machine.

"using some obscure shell"

I also see no problem with this -- if they prefer it, just let them.

"or even infecting other people's machines with some haphazardly scp'd dotfiles."

This is a legitimate complaint, if the person is leaving stuff behind that screws up the other person's computer. But if the person is expected to work on other peoples machines, then I think a reasonable solution could be worked out. You should try to defer as much as reasonably possible to the person who the machine belongs to. On the other hand, if you are asking someone else to do work on your machine, it seems reasonable to let them copy some dotfiles in order to help them do the work -- as long as they don't affect your stuff.

"This kind of overcustomization is fine if you live in a basement and work on a project alone."

I don't buy the "overcustomization" label. Yes, it is possible to spend too much time customizing things (if, for example, it prevents you from getting your actual work done). However, programmers can make themselves much more efficient by many of these customizations. Different people have different ways of working, and they have different jobs. Vanilla configurations of things like editors are fine, but the ability to customize exists for a reason -- you can make your job easier and yourself more efficient by customizing your tools.

"As soon as you become a part of a team, please stop. You're making cooperation unnecessarily hard and spending company time on an optimization that isn't."

I've worked on many different development teams over the years. At all of those jobs, it was an extremely rare thing to even do development on someone elses computer. Everyone uses their own.

"I sometimes joke that coders who refuse to conform to the industry standards should wear a tiara as an indication they are, indeed, unique snowflakes free from the usual social expectations. It seems to work."

What "industry standards" are you referring to? Is there an ISO standard for vim keybindings? Please. Also, I don't think the whole "Princess" analogy is fair. Just because someone has their own way of working doesn't make them self-absorbed and shallow.

(edited for better formatting)


Do you not have your own computer at work? Because that's what these ridiculous complaints sound like.



Is that article serious? I appreciate that GP's post is atrociously misguided but that article can't be serious can it? Are there really people out there who believe this?

I had a look at this guy's other articles and it looks like the trashiest of linkbaits. "Reddit's Terrorists Have Won". "How MRAs Killed the World". "The Big Business of Internet Bigotry".

Author might be overcompensating for something...

Edit: Took a closer look at his articles. I generally appreciate opinion pieces, but this guy is either writing about women/feminists (neither of which he is), or about gamers (which he quite clearly isn't either), in a way that lets him just talk without the "threat" of opinions opposite to his own, which he heavily bashes. Wow. I need a shower after this.


Arthur Chu is a rather... special case. Stay far away from his Twitter if you value your sanity and faith in humanity.


I've never heard of him before today, FWIW, but you did get me to google his profile - what with your reverse psychology ;-) - and... well, it's not that bad. It's a pretty standard twitter profile for someone who thinks having 25k followers makes him the voice of god... but I've seen a lot worse on twitter than merely misguided people.

Regardless, I genuinely don't understand the appeal of outrage-writing over subjects that simply do not concern you. For example, I'm straight but I'm also a proponent of gay rights - does that give me any right to speak "on behalf" of gays? Isn't the entire "I'm not [gay/black/a woman] but..." ideology of people stealing other people's voices exactly the reason some countries or communities have societal problems with various minorities?


I guess that's part of the reason I hold him in such contempt- a lot of his comments have made their way into my Twitter feed, and I've yet to see something that wasn't either directly advocating irrationality (c.f. https://archive.is/xfjyi), blatantly speaking on behalf of the supposedly marginalized, or making uninformed statements on something or other.

No intelligent being should ever have the right to speak "on behalf of" any other intelligent being without their direct approval, any other standard is massively insulting.


The journey to learning vim is so long that people at different stages will have things set up differently. I'm still adding and removing things as I learn and understand them, or conversely, as I no longer need them. I'm not kidding when I say it's a 10-year learning curve.


Most code editors are half-useless by default though. I don't think anyone is using the default Atom or Sublime. It takes time to both tweak them and learn how to use them. So I don't think Vim is THAT different.


I think of vim almost as two separate editors. (1) my setup which is customised exactly like I like it and borders onto a IDE and (2) default setup which I can happily use to edit a few config files.


The default settings on Windows and Red Hat based systems are pretty good. On the other hand, I was very disappointed ~8 years ago when I touched an Ubuntu system. It was too plain for me.


For those just getting started or using vim only occasionally, Tim Pope's vim-sensible is a good, conservative starting point. It just sets some reasonable base configs instead of Vim's crazy default settings. No custom keybindings or fancy plugins included.

Vim is by default intended to be compatible with some historical implementation of vi. In my opinion, it doesn't make any sense any more, but I guess there is some reasoning behind the decision.

https://github.com/tpope/vim-sensible


neovim has some saner defaults, by the way.


Mostly based on vim-sensible's (with some input from the community): https://github.com/neovim/neovim/issues/2676


Agreed, the current defaults are a major turn-off. Especially for first time users. Vim is incredibly frustrating without auto-indent.

The problem with vim is that you can't use it effectively unless you know almost everything that there is to know about it.

When it comes to vim, you're either a novice or an expert, there is no middle-ground.


That's just really not true. Vim has a massive middle ground. It has a plethora of features that you don't need to know about, but that make your life marginally easier when you do learn them. Getting up to parity with another editor takes a little bit more time than with a yet-another-WYSIWYG, but you can certainly use vim effectively after a day or two. Everything after that point is just bonus productivity.


This is a very nice write up, but the tabs/spaces part of it makes no sense at all.

"I like it, since it means my source code looks the same on every machine."

That reason just makes no sense at all.

There's only one reason for configuring tabs to be anything but tabs, and that's because someone else set the standard. So if you're editing python or bash, and you don't feel like being a rebel with a cause, you set expand tab.

But obviously you shouldn't be doing that manually every time you open a file, so you should configure Vim to detect what's going on.

You can do that by adding the `ciaranm/detectindent` plugin and then setting the following line:

    autocmd BufReadPost * :DetectIndent
To detect the indentation any time you open a file. That at least for me makes the headache go away most of the time.


Author here.

I literally meant that I enjoy that it will be forced to look the same on every machine. I like that it's not configurable by others.

Personal preference.

Good tip on autodecection!


There's also https://github.com/tpope/vim-sleuth, by Tim Pope.


Why would either tabs or spaces be better than the other? Isn't that one of those pedantic style debates that often come down to a matter of personal preference? I'd get rather annoyed if someone on my team was constantly changing the indentation from tabs to spaces or vice versa every time they opened a file.

To elaborate on the author's reasoning for using spaces, people sometimes mix spaces with tabs in the indentation unknowingly. If you're not using the author's tab size on your machine, the code doesn't format well at all and if you want to convert to spaces you'd have to manually edit a lot of things. There's also the issue with aligning things as well, which spaces are more consistent for as well. At least with spaces you can see the author's original intention and then reformat it as you wish.


You're mixing up arguments. No one on your team should be changing indentations. You should decide as a team what your settings are going to be, that's why I suggest using DetectIndent to make sure your settings match whatever the project guidelines are.

It's not a matter of personal preference though. Tabs are simply superior for encoding indentation. If you use tabs for indentation you can configure their width in your editor to match your personal preference, spaces doesn't allow for that. That's the only significant difference, and the only good reason for using tabs instead of spaces.

None of the arguments you made about spaces make sense. What's the fact that sometimes people mix up tabs and spaces got to do with anything? The whole idea of using tabs is that the code does format well regardless of what tab-width setting you have on your machine. Converting tabs to spaces does not require manual intervention at all. Alignment should be done with spaces, no one is argueing to use tabs for alignment. You can't use tabs for alignment because their width is undefined! The whole idea of using tabs is semantically encoding the authors original intention to allow you to reformat as you wish! At this point.. are you just trolling me?


Oh sorry! I completely misunderstood what DetectIndent was doing, that's a good tip.

I did want to point out that there's some sense to forcing the code to look the same on every machine though. Of course converting tabs/spaces is automatic, but my point was that the mix of the two requires either manual editing or conforming to the width of whoever made the error. It does happen, and I've been on at least one project with a professor who would occasionally mix things up while in the throes of editing (and they used a tab width of 8 which made it especially irritating for others!). With spaces you at least force whitespace to mean only one thing and if you absolutely can't stand someone's indentation width you can still change it like you can with tabs.

This really is personal preference though. Spaces explicitly represent the author's original intention including their indentation width, while tabs make it more convenient to others while conflating whitespace to mean two different things. Both are entirely reasonable though.


> What's the fact that sometimes people mix up tabs and spaces got to do with anything?

Its a concession to the fact that humans are imperfect. When I am working with a group of people I find it easier to just use spaces instead of relaying on everyone configuring to use tabs correctly.


As an example of where it's not just personal preference: makefiles require actual tabs, not spaces, in the indentation in recipes for targets. And in Python, mixing tabs and spaces will cause flow control to do something different than what you intend it to. In vim you can handle tabs on a per-filetype basis, eg. I have red syntax highlighting of spaces for indentation in makefiles.


Great writeup and thank you making it clear that you want people to understand what's happening. I love the clean style of your site.

Let me also recommend some of my favorites:

  set matchpairs+=<:>     " match < and > as well
  set ignorecase          " case-insensitive search
  set smartcase           " upper-case sensitive search
If you already use ctrlp, you might also cpsm [0], a better matcher for it and ctrlp-funky [1] which allows you to go to methods and other symbols in a ctrlp style.

  [0] https://github.com/nixprime/cpsm
  [1] https://github.com/tacahiroy/ctrlp-funky


Disabling the search highlight seems like a rather lowly use for leader+space. Great guide though, didn't know about quite a few options in here, wildmenu is great.

I switched to vim from subl about a month ago - it took a bit of getting used to but I'm loving it now. I still use subl for some multi cursor wizardry but that's less and less common now.

I found the disabling the arrow keys in normal mode was the point of no return!


> I found the disabling the arrow keys in normal mode was the point of no return!

Is there any reason to do this when you have a keyboard that has easily reachable arrow keys? (Kinesis Advantage, in my case.)


Yea, it forces you to use the vim bindings. This is advantageous, since your hands don't leave the home row. It seems minor, but when you actually "get" vim, you'll actually see speed improvements. It sounds silly, the half second saved here and there, but once you've done it long enough, you get into a flow that you just can't get moving your hands to the arrows or mouse.


^ this. I could likely reuse them for something now but when your muscle memory has you going there all the time at the start it's better if they just do nothing. I think it is at least.


Author here.

Agreed it sounds like a poor use at first blush. I lean on search for navigation frequently enough that having a super convenient :noh binding really works for me.

Use whatever you want though!


I managed to use Escape to disable search highlight: https://github.com/alxndr/dotfiles/blob/ce0e18cb40f52f0c60d1...


there are at least one plugin for multiple cursors stuff - https://github.com/terryma/vim-multiple-cursors


Yeah - I need to have another look into it. Visual block is working ok for the time being.


The `ToggleNumber()` function may be shortened to

    :set invnumber
There two kind of prefixes for `:set` variables: `no-` and `inv-`, the first one turns the variable off or empties it, the second just toggles between states.


Cool trick.

FYI, you can do the same with :set number!.

Adding ! at the end of a variable will invert it. Adding ? at the end will echo its value.


Nice tutorial. While I understand the pleasure of configuring stuff — being a Gentoo-lover I'm throwing stones in a glass house here — I always stuck to a very simple Vimrc file. I find it better to learn how to use the standard settings than forever me tinkering on my own. One could always wish the standard settings were more sane, though…


Came here to say "Don't put anything in your vimrc that you don't understand". Pleasantly surprised when I clicked the link!


I, too, wondered about $ and ^ - they are rather inconvenient to type. But instead of B and E, why not map <Space> as leader, then have <Leader>b and <Leader>e?

Space seems like the perfect leader key. Mapping , means you lose prev-finding for some searches (f).


I actually map H to ^ and L to $. In my head it's like "h is left, H is far left"


I've played around with vimscript and my .vimrc many many times, and always found it very unwieldy. I've started using a new and very different approach, which involves using the amoffat/snake library to write my new .vimrc functions in python. This is definitely not for everyone, but I've been able to do some pretty cool stuff with it, like creating a function for writing trace like debug statements, or sending the currently selected vim lines to a shell via the window manager/os level, rather than a terminal multiplexer like screen. If anyone else is interested, an example can be found at gist.github.com/sac2171/ce7b086421e8387193fd


    syntax enable           " enable syntax processing

    The comment should be enough to describe this one.
Sorry, no it's not. The syntax processing of what? The syntax of the current file loaded? Some sort of commands?


A good example of a completely useless comment.


I just realized something - my vimrc is 12 years old (carried on from my college). It has all my quirks and shortcuts that doesnt make sense to anyone but me. Every now and then, I pick up sone cool stuff from other vimrc and it becomes part of my own.

What I just realized is that my Dockerfile is becoming something like that. Everything from the way the file system is laid out to the supervisord config is something that has become familiar. I do my development in it and its already a year old. All my various production servers use the same base Dockerfile (it includes Ruby, Python, Nginx, Openssl, Golang and Java!).


I don't understand why you'd want to map leader to anything but space.


I fully agree. I think it seems like this key that people think is special like caps lock. The symmetry afforded by the space key and every other key on the keyboard is phenomenal.


The first line is what I wrote about on my blog http://ricardolovelace.com/blog/2015/01/11/vim-is-not-a-blac.... Oddly enough there aren't more articles like these, just repos with a couple hundred line long blobs with every plugin, "hack" and keybinding known to man.


One thing I've added fairly recently is:

    try
            source ./.vimlocal
    catch /^Vim\%((\a\+)\)\=:E484/
    endtry
which lets me tweak my settings (project specific key bindings, &c) by dropping a .vimlocal file in the directory I'm editing from. The try-catch ignores the error raised when the file is absent.


Why not check for file existance, instead of try-catch:

  if filereadable(expand("~/.vimlocal"))
      source ~/.vimlocal
  endif


I've no strong objection to that - it's racy but not in any way that probably matters. Otherwise, it's mostly just a question of forgiveness vs permission...


Good tutorial. Looking forward to combing over my vimrc tomorrow when I have some time. It's similarly copied from somebody else's many moons ago, and there are things that it does that I don't really like but haven't been bothered to change (eg. sometimes I want 2 space indents instead of 4).


Nice writing. One point/one question:

. section titles can be finished with {{{1 and then no closing brackets are necessary. It will just wrap to the next {{{1 occurence.

. regarding nvim: how can I find out what the defaults are there? Probably I have quite a lot of definitions which are no longer needed...


Neovim Defaults

From the current docs:

[0] https://neovim.io/doc/user/vim_diff.html#nvim-option-default...

From the GitHub issues page:

[1] https://github.com/neovim/neovim/issues/2676


I've been testing your recommendation of using ag in ctrlP (let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'), but the performance seems to be pretty much the same. Do you notice that much of a difference?

Disclaimer: I'm using a SSD.


I'm using command-t and it works fine for me even in large code base.

AFAIK, ag shines for searching code in large code base, if you are just doing matching with a list of file paths, ag is an overkill.

EDIT: And if you set `wildignore` correctly, you wouldn't have a lot of files. Getting node_modules/ out of my Command-T result made it much faster. I actually wrote a plugin[0] to extract patterns from `.gitignore` and apply to `wildignore`, so that Command-T and CtrlP could have a shorter list to search for.

[0]: https://github.com/octref/RootIgnore


Shouldn't even large code bases fit into your RAM's disk cache these days?


Nice writeup, give Sift a chance - https://sift-tool.org/info.html - a nice replacement for the silver searcher


Offtopic. But still: Thanks. Nice.


Heh, I store my entire config in a Github repo: https://github.com/Diablo-D3/config


A must have plugin for moving to the middle of a word:

https://github.com/bkad/CamelCaseMotion


nothing special about this vimrc.

This is what I have:

https://gist.github.com/halayli/ef3dd268986914ed77d5

At the very least, you need vim-session if you work on multiple projects (or branches)

vim-airline is a nice to have

Ag is a must have. it allows you to search files and preview the results directly.

I've also written a small function SwitchHeaderSource to switch between .c/cpp files and their headers. ,s is the shortcut.


can anyone suggest similarly helpful resources for those of us stodgily using nvi?



Great guide, thanks for sharing. Although that B and E remapping.. man, it hurts!


I'm seriously interested in such an article for Emacs. Anyone?


Check out spacemacs


I'm a relatively long time Spacemacs user, and just recently dropped it exactly because it abstracts too much, and I wanted Emacs keybindings. I've failed to comprehend how it answers my question. Thank you anyway.


A couple times a year, I'll scour a few .emacs.d repos on github and see if I can find something interesting in there.


My advise is to migrate to spacemacs


the best vimrc is the one that doesn't exist, so that vim runs in compat mode


Badwolf is great


goods


what is the benefit of representing tabs by 4 spaces?


one argument for spaces > tabs is that with tabs you cannot see if you have (mistakenly) added spaces to indent a particular line (without :set list which can be annoying to some). If someone else opens the file and their tabstop setting was set to a different number than you, they'll see different indentation on those lines. If everyone uses spaces, everyone will always see the same thing.

I think tabs settings as something that should be agreed on by a team or project lead - too easy to screw things up. Same with line ending settings in version control if you're working with a mixed OS team.


It is called personal choice.


Did he mention pathogen, vundle, youcompleteme, nerdtree, and powerline?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: