A Good Vimrc
dougblack.io
dougblack.io
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.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."
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.
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.
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").
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 …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.
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...
Having caps as ctrl makes it really easy to hit.
This is brilliant idea. And it works on OSX too - using http://apple.stackexchange.com/a/132569
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 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-[.
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'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.
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.
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.
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).
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.
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)
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...
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.
Or it's just based on subjective feelings and cargo cult?
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.
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.)
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.
> 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!?
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.
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.
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?
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.
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...
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.
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.
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.
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.
Maybe you just bought into some myth:
But sure, I bought into some typing speed myth, whatever floats your boat. XKCD774.
https://github.com/jleclanche/dotfiles/blob/master/X11/xkb/s...
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.
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 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.
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?
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.
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.
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.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.
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!
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.