355 points · by sanjeetsuhag · 11y ago · 170 comments
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.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.
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...
This is brilliant idea. And it works on OSX too - using http://apple.stackexchange.com/a/132569
Having caps as ctrl makes it really easy to hit.
As an added benefit, getting used to this layout will help you out with migrating out of vim to emacs.
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.
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.
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.
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-[.
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'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.
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 guess the question is do people modify vim cause they can or cause they have to?
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.
Actually, one of the main goals of Neovim[1] is to provide better defaults[2], such has syntax highlighting.
Be aware that some plugins might have some bugs. I also got segfaults when using multiple terminals (although that's quite rare).
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.
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.
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.
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.
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...
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.
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.
Maybe you just bought into some myth:
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... ;-)
I will definitely be making that "overcustomization" on my Mac. :-D
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)
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.
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.
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.
"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.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!
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.
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?
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.
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.
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-funkyI 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!
Is there any reason to do this when you have a keyboard that has easily reachable arrow keys? (Kinesis Advantage, in my case.)
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!
: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.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.
Space seems like the perfect leader key. Mapping , means you lose prev-finding for some searches (f).
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?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!).
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. if filereadable(expand("~/.vimlocal"))
source ~/.vimlocal
endif. 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...
From the current docs:
[0] https://neovim.io/doc/user/vim_diff.html#nvim-option-default...
From the GitHub issues page:
Disclaimer: I'm using a SSD.
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.
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.
and
http://www.sontek.net/blog/2011/05/07/turning_vim_into_a_mod...
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.