15 ms·
Vim Anti-Patterns
- clifanatic 10y ago> Vim isn’t the best tool for every task Begone with your heresy!
- rhinoceraptor 10y agoI have a programmable keyboard, so I just map escape to be right above tab, where tilde usually is.
- sotojuan 10y agoI use Karabiner + Seil to make my Macbook Pro's Caps Lock be Escape when hit by itself and Control when hit with another key. Unfortunately this doesn't work on Sierra yet so still on El Cap.
- lathiat 10y agothe lack of tilde doesn't drive you mad? This is built-into my Lenovo Carbon X1 (gen2) keyboard, drives me bananas as I use tilde quite a bit (being home on linux): http://www.lenovo.com/images/gallery/1060x596/lenovo-laptop-thinkpad-x1-carbon-2-keyboard-3.jpg http://www.lenovo.com/images/gallery/1060x596/lenovo-laptop-... What kills me more though is that "Shift" is now caps-lock if you double hit it (because home/end are where capslock normally is). The standard way I wake up a machine when it's locked/asleep/blanked? Tapping the left shift key a few times. ergh. Should get a gen3, they reverted to a more sane keyboard layout.
- vlunkr 10y agoThey are working on a new version that for sierra: https://github.com/tekezo/Karabiner-Elements https://github.com/tekezo/Karabiner-Elements. I'm using it. It works, but you have to configure it by editing a json file, and there are some bugs still
- yes_or_gnome 10y agoAre you using a US-QWERTY keyboard layout? If so you're losing "switch case" (~); close alternatives are 'gu' lowercase, and 'gU' uppercase, not quite the same. And, "goto mark" operator (`); close alternatives is "goto mark, beginning of line" operator (').
- rhinoceraptor 10y agoYes, I use an Ergodox keyboard. My `-=\ keys are right below my zxcv keys.
- qwertyuiop924 10y agoI have xmodmap. All keyboards are programmable. I do the control-capslock rebind, as is traditional among Emacs users. I also typically use a Unicomp Model-M style keyboard, complete with springs. But that's an entirely different flame war.
- rhinoceraptor 10y agoYeah, it's just nice to have the layout in hardware. And programming your own keyboard can be fun.
- clifanatic 10y agoI recall reading somewhere that Stallman's keyboard had the CTRL key where the (totally useless) caps-lock key is on modern keyboards, and that's why he used CTRL+ combinations throughout emacs.
- petepete 10y agoThe most perfect keyboard ever envisioned (whose name shall not be mentioned) has the CTRL key there. It has no dedicated caps-lock key at all.
- qwertyuiop924 10y agoNo, the Model M had a capslock there. It's one of its great failings. ;-)
- sdegutis 10y ago> "If you have to move more than a couple of lines, moving one line at a time by holding down j or k is inefficient." This very point is actually why I moved from Vim to Emacs years ago. After mastering Vim, I realized that Vim strongly encourages you to think a little too much about exactly how to get there or do that thing in the fewest keystrokes, and that it's incompatible with muscle memory. Even years later, I still had to think too much about it. Whereas in Emacs I can just use basic character/word/line-based movements and let my muscle memory do its thing while I let my brain focus on the code itself instead of how to use the text editor.
- xemdetia 10y agoAs an Emacs user I want to plug ace-jump-mode to move around the viewable part of the buffer more efficiently than many of the commands mentioned in the OP's post. 1. look at character you want to go to 2. M-x ace-jump-mode (I have this bound to F9) 3. Hit key for the character you want to go to 4. All instances of them are rewritten in the buffer with a coloured character. 5. Hit the coloured character you are looking at. The trick is to just look at where you want to go and touch type the rest. Even on very large monitors with dense data (I find this invaluable if I am going through an minimized HTML blob or a plaintext database dump) this can turn any point to be 3 keystrokes away. Cursor + search forward doesn't work if there is a lot of duplicate text around where you want to go, like a string of five .set* methods and you are trying to kill the third one
- qwertyuiop924 10y agoI have got to try AceJump one of these days...
- mrkgnao 10y agoThis reminds me of easymotion.
- to3m 10y agoJust a question of practice, I found. I was a regular vim user in the past, and this was my criticism of in when first starting out - but after a while I found myself unthinkingly coming up with surprisingly complicated sequences of keypresses. It's possible to get very good at subconsciously sizing up editing operations. These days I use emacs, and I pretty much always move the cursor using the mouse.
- bpierre 10y agoShameless plug: I wrote a small guide about how I switched to Vim, after having “tried” for years. It’s not a universal approach, but maybe it can be useful for people here: https://github.com/bpierre/switch-to-vim-for-good/blob/master/README.md#switch-to-vim-for-good https://github.com/bpierre/switch-to-vim-for-good/blob/maste...
- yes_or_gnome 10y agoThis is a great resource, but the article is pretty strict on the arrow keys. I would recommend `nnoremap`, over `noremap`, because it only disabled the arrow keys in Normal Mode. The author's explains his rationale in the next section, it's to prevent users from living in Insert Mode. Fair enough. But, when making several relatively close edits, the ability to tap a few arrow keys in Insert Mode is far easier and less mentally demanding than any key combination that requires the user to bounce around different modes.
- DSMan195276 10y agoI don't really disagree with your overall point, the arrows keys are not horrible, but I think for beginners removing all arrow keys is the best approach. I used vim for a while just relying on the arrow keys, and it wasn't until I disabled them completely that I really started to use vim. If I left them on in insert mode, I would have just ended up using them that way, just due to muscle memory. I'd also add that if you remap Esc to something more manageable, leaving insert mode for a second to move around starts feeling a lot more natural. I still do get where you're coming from, the arrow keys do have a time and place. But since I do all of my moving around in normal mode, leaving insert mode to do it just 'makes sense' now and I really don't even have to think about it.
- yes_or_gnome 10y agoAbsolutely agree. I completely disabled arrow keys for a short time; ~3 months. It started out after reading a similar recommendation. It was difficult for a few days, but then I completely forgot about my arrow keys and the fact that I disabled them. It wasn't until months later that I was in one of these situations that I wanted to use the arrow keys, but they didn't work. Which was confusing. This must have been around the time that I started to understand, and manicure, my vimrc because I remember having to learn all the mapping modes to recover arrow keys for Insert Mode. So, anecdotally, completely disabling arrow keys led me to learn more Vim than just efficient movement. Today, though, I don't have the makings anymore because it's no longer a problem. One quick question; I can't answer this because I am currently commuting. Does 'noremap' disable keys in Command Mode? Now, that would be aggregating, to me. Also, there a remap mode that combines Normal and Visual modes (right?), that would be one better than 'nnoremap'.
- glormph 10y agoUseful stuff. I'd add typing J to move the next line to the end of the current line. A move I normally do by being on the next line and then type 0dwiBackspace. Only just figured that one out by mistakingly having the capslock on when moving around.
- sevensor 10y agoThat's how I discovered "K". Which is usually not what I want, and tends to provoke a moment of "where did this garbage come from and where did my code go?" panic. I'm close to masking it out, but I remap very reluctantly.
- sevensor 10y agoThis is good solid advice -- I have a problem with vim advice that golfs more unusual circumstances to save a keystroke or extensively remaps the keys. (Generally the only thing I remap is F1 to ESC, because I use laptops that place them inconveniently close together.) Devoting too many cognitive resources to text entry is also an anti-pattern!
- Lxr 10y agoI highly recommend not using the Esc key, remap to jk or caps lock that you can reach without moving your hands. It makes a pretty big difference.
- servlate 10y agoEven easier to use the default Ctrl + [ instead of ESC.
- lathiat 10y agoThis is a really good guide.
- tremon 10y agoNote that d2wi and c2w are not exactly equivalent: d2w will consume trailing whitespace after the second word, while c2w will not. FAFAIK, there is no exact equivalent of d2wi using c. I usually end up using c2aw, but that will also consume any word characters preceding the cursor (not a problem for me since I usually navigate using b and w).
- no_protocol 10y ago> d2wi and c2w There is a nice chart on this page with a few more inferior/superior motion commands: http://vimcasts.org/episodes/modal-editing-undo-redo-and-repeat/ http://vimcasts.org/episodes/modal-editing-undo-redo-and-rep... One problem I commonly see with most vim advice articles is they just have too many tips for the reader to consume at once. But if you just make sure to pick up at least one of the tips, you'll at least gain something.
- skykooler 10y agoIndeed. I try to come back to pages like this every few weeks, and to start training myself to use one more of the tips from it. Today it's * and # to go to the next/previous instance of the word under the cursor.
- deleted 10y ago[deleted]
- lunchboxsushi 10y agoI was originally a die hard Emacs user, but I started to feel a bit of strain on the whole holding Ctrl+p, Ctrl+n etc. I was trying to find an editor/plugin that can reduce keystrokes or at least the strain. I ran across EVIL for Emacs which is just a Vim emulation and keybindings for Emacs users. Unfortunately I did not like it at first the entire hjkl felt awkward and all those modes - OMG. But after toying around with it a bit and playing the online interactive vim learning game I started to see the benefits of Modal editing. I can easily without leaving home row move a few letter to the right or back with hl or f and F. but things started to get a lot more fun when you realize that Vim is a programming editing language and it's beauty is in the commands. This leads to amazing things that I hated before, such as deleting 2 words back from my current position would simple be d3b. instead of shift+ctrl+left arrow x 2 + delete. Overall it's been about 2 months since I've started using EVIL mode for Emacs and I love it. I'll stand by the saying that Emacs is a great OS and vim is a great for editing text in it's modal editing. lastly modal mode really felt powerful only after I had re-mapped my CAPS key to ESC. I mean throughout the past decade I don't think I've even used Caps for anything. so I've remapped the machines I work on the have caps as esc. - for those that think it's not reasonable to do so and the whole point of using vim is so that you can edit machines via ssh then use vim on that machine, my suggestion is to use tramp in Emacs with ssh or plink to get to the server and edit (you will still have the local caps to esc key mapped) TL;DR - Vim modal editing is amazing and feels has straining than other editing layouts - IMO.
- tgb 10y agoI love vim but admittedly ctrl-backspace-backspace is just as fast as d2b and works in nearly any editor. The stuff i really like is stuff as dt. which will delete until the end of the sentence, ie until the period. Or di( which deletes everything inside the parenthesis.
- lunchboxsushi 10y agoalso for html cit and the rest for general purposes ci), ci', ci", interchangeably with d, or y. that was probably the first time I just has to sit back and take a second.
- vlunkr 10y ago> don’t forget you can yank, delete or change forward or backward to a search result. Did not know this! (although I've been on vim for ~a month) That's a great trick. Much easier than trying to count words.
- pjungwir 10y agoI agree it is very nice, although you should know one caveat: deleting/yanking with / and ? will do whole lines, so it may go past the match. deleting/yanking with t, T, f, and F will go up to just the char you want, but it won't search onto the next line. I wish there was a way to get a char-by-char multiline search, so I could e.g. cut/yank a whole sentence (something like d/.). But I haven't found it. I wonder if anyone else knows of a way?
- tomku 10y agoYou might find vim-sneak useful: https://github.com/justinmk/vim-sneak https://github.com/justinmk/vim-sneak. https://github.com/easymotion/vim-easymotion https://github.com/easymotion/vim-easymotion is another plugin that does something slightly different, but also useful.
- foob 10y agoThese are all good tips but most of the anti-patterns seem to skew towards beginners (e.g. don't use the arrow keys, don't navigate in insert mode). One that I think is more common among intermediate, and even advanced, users is the misuse of tabs, windows, and buffers. A lot of people have a tendency to think of each tab as corresponding to a single open file. This is very understandable because it closely matches the paradigm of most IDEs but it's actually an anti-pattern in VIM. Tabs are really meant to be more like workspaces where you arrange multiple windows into a desired layouts. You then have one buffer for each file that you're dealing with and view them in your windows. It's perfectly fine for multiple windows to share a single buffer or to switch out the buffer that is being viewed in any given window. This StackOverflow answer [1] and this blogpost [2] both go into a fair bit more detail. If you're trying out this approach for the first time then you probably want to add `set hidden` to your configuration in order to avoid automatically closing buffers that aren't currently being viewed in a window. Coupling this approach with fzf.vim [3] makes managing very large numbers of files a breeze compared to using one tab per file. [1] - http://stackoverflow.com/a/26710166 http://stackoverflow.com/a/26710166 [2] - http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/ http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-... [3] - https://github.com/junegunn/fzf.vim https://github.com/junegunn/fzf.vim
- grimgrin 10y agoFor any Windows devs that happen to use vim inside of mintty (that comes with downloading git), you'll discover that installing fzf doesn't work out so well. It'd be fine on cygwin, surely. In mintty, though, it'll yell about missing ncurses and then offer to install the legacy Ruby version, which also fails for curses related reasons. So, that said, check out ctrl-p. https://github.com/ctrlpvim/ctrlp.vim https://github.com/ctrlpvim/ctrlp.vim It's a nice quick way to see a filelist that you can filter, like fzf. You can filter on: * the whole project, excluding .gitignore stuff * all open buffers * Most Recently Used (MRU) file list In addition to the built in ^p binding, I also add: nnoremap <leader>v :CtrlPMRUFiles<cr> nnoremap <leader>b :CtrlPBuffer<cr>
- sevensor 10y ago> vim inside of mintty (that comes with downloading git), Is git for windows using msys2 yet? If not, do yourself a favor and start using msys2 instead. It has packages for git and vim, and it uses pacman for pacage management. I've had a great experience using it.
- SCdF 10y agoSo I have used ST3 for years now, and I realise that I'm slowly moving toward Vim. I started using Vim shortcuts in Chrome, and now I use Vintageous in ST3. Vintageous is good, but it is incomplete. It can't even do the first examples on this article (ctrl+f / ctrl+b) correctly. Thinking I should just bite the bullet. Would mean I could work on a server using Mosh + Tmux as well, which should be rather nice. What would the current canonical guide be for getting up and running with Vim, with plugins, auto-complete[1], inline linting, multiple carets etc? [1] Just the ST3-style of parsing out tokens in the same file
- yakshaving_jgt 10y agoVim has “multiple carets” out of the box with visual block mode.
- Lxr 10y agoNote sure about a guide but I would start without any plugins at first. Otherwise you never learn what's vim and what's a plugin, and working on remote servers will be a pain. Also for a lot of plugins, there's a better way of doing things in native vim if you learn it properly. What worked for me to bite the bullet at uni was making myself do an entire programming assignment in vim and not opening in any other editor. If you commit it doesn't take that long to learn. Keep a list of commands handy and learn a few new ones each day.
- e12e 10y agoFor 1: ctrl-n [ed: a little more context and detail: http://usevim.com/2012/07/06/vim101-completion/ http://usevim.com/2012/07/06/vim101-completion/ ]
- dopeboy 10y ago> It’s always useful to jump back to where you were, as well, which is easily enough done with two backticks, or gi to go to the last place you inserted text. I And here I was undoing and redoing the entire time.
- protomikron 10y agoHa, I do the same - you always learn something new in vim. For me the biggest boost in Vim was configuring the shell (i.e. readline via .inputrc) to use my vim key bindings, so I can use it without arrow keys. Not because of efficiency, but more for wrists comfort. Furthermore I am in the camp of mapping ESC to 'jj'. My index finger has more power and using the pinky (e.g. via CAPS or ESC) is too exhausting for me.
- taneq 10y agoHah, me too. Also yank-then-undo instead of finding out how to actually select and copy text. Meh whatever, it works, and the amount of time I spend in vim these days is so minimal that I doubt it's worth it to retrain.
- lucb1e 10y agoPage loads very slow and uses Wordpress. In case it goes down: http://archive.is/JaOXd http://archive.is/JaOXd
- Philipp__ 10y agoNot trying to start a flame war here, but I in recent few years I am seeing Vim being more popular, and I feel it adoption in terms of younger developers (those who weren't programming when original Vi was around) grows. (Ok, please forget about GUI editors, they have their audience, and I am not comparing any of those facts to them) I used Vim for 3 years, and found philosophy and implementation of modal editing amazing. Writing and manipulating code in it went like bread and butter. But then I told myself, hey, why not try Emacs? So I've been using Emacs for ~6months now and cannot but notice that community is much more niche and humble compared to Vim. Just look at the sheer number of color schemes available for both editors. And I had to agree, Vim was far superior text editor, but that wasn't enough to keep me away from Emacs, since I gave the advantage to other things (everything else) that Emacs does better. I tried EVIL mode, and it is amazing, but something just felt wrong using it inside Emacs. I wasn't using either Emacs or Vim. I would often shuffle and mix commands, sometimes I would do :w, sometimes C-x C-s. So I decided to ditch Evil until I get more comfortable with Emacs key bindings. I came to Emacs because of Lisp (and general FP audience is much, much, more based around Emacs, makes sense), amazing tools and plugins which I found more stable, better designed, and it is weird to say this but things just worked with Emacs, things like auto-completion and code navigation (ivy, ace-jump-mode) were really fast, hustle free experiences. Disclaimer, I have never touched older versions of Emacs, spent my time in 24, and now in 25, so many of myths and problems that Emacs got known for over the time, I think, aren't there anymore. And to sum things up, what is really weird to me is that functional programming is on the rise and every year I see it more and more being adopted, but that doesn't help Emacs audience grow. (Maybe because I am young, and I am nerd often found in nerd communities where things like FP are often praised, but in the real world considered a bit awkward or esoteric.) I showed up at the FP workshop few weeks before in local dev/hacker community place, everybody rocking Sublime Text/Vim, but nobody used Emacs, people were looking at me like I was an Alien. Spacemacs is doing good job at attracting people, but maybe Emacs will stay that programmers/nerd phenomenon, the all-mighty lisp OS, that in the end people often reject or overlook. And why is it like so? I do not know. If somebody can sink into and learn Vim, I don't see a reason why it is different story with Emacs.
- qwertyuiop924 10y agoEmacs was far easier for me than Vim was. To this day, I have no idea how people learn Vim. And the scripting is awful, especially compared to Emacs, which is really a script interpreter that has a built in text-editor script and some useful primitives for text editing.
- jnordwick 10y agoI started off using Emacs a lot (like tons and tons of Emacs with tons and tons of custom modes, functions, and craziness - network pong anybody?). For almost a summer, my xinitrc at the school labs literally opeed up a full screen Emacs; it was my window manager too. The simplicity of vim (and pretty colors) drew me in. Plus as I learned more sed/ed, I understood vi more. That, and a slow connection from off campus really sucks. I learned that too pretty well. Well enough to hack together some vim scripts, but nothing near my Emacs level. I feel like vim mode hacking is a beast you need to be specially equipped to handle (and I can write APL in any language so it isn't the syntax). Then Eclipse and IntelliJ came around and I only really used vim for quick one off stuff (if I didn't use printf, echo, or cat). The only time I used vim was for C/C++ or something esoteric, like KDB+/Q/K, that didn't have their own dev environment (unlike say VHDL or Matlab where I could sit in their ugly cocoons). Now I'm growing tired of the very buggy, slow Java environments that seem to require a gaming rig to compile HelloWorld.java (or sorry, HelloWorld.xml with SpringBoot). And I see all these poor Emacs clones playing catchup with 2000. You have editors written in JavaScript inside a web browser with modules transpiled to JavaScript (for some reason JavaScript is too low-level to write text editing packages in now -- God help us all). That, and they don't support a tenth (I'm being generous) of the functionality that Emacs does and they probably never will. What is so hard about an extensible text editor? Just getting the basic hooks down for self-insert and movement without having to go to swap? I remember when Emacs was called "Eight Megabytes and Constantly Swapping". I now see Atom routinely take up over 800 MB. And it still can't play Pong. Now with Rust and other languages, I'm back home in Emacs, but the keystrokes do tend to bother me a little. I liked the HJKL movement keys in vim - I just hated the modality and think I spent more time trying to figure out "my cursor is here, but I need move it over there - so first I need to jump on that log, shoot the rocket to knock down flowerpot then run quickly while the line is falling to catch it and K it to the next line" -- like some sort of weird text editing puzzle (I wonder if you could make a vim code golf puzzle set). Emacs has these bindings that feel like finger yoga, even when I've remapped Caps, control, half my F-keys, etc. What I really need to do is remap my toes to my hands, I think. It would have been really nice to see C-[hjkl] style movement (with maybe CS-[HJKL] be the distance mods or something). It's too late now. You of course you can remap those keys, but too much of that behavior is baked in to people). Maybe one day when I'm old and gray I'll do the Knuth thing and start a new text editor, but before that I'll probably need to redo the monitor, mouse, and keyboard and that is just too much right now.
- idobai 10y ago> So wean yourself off the arrow keys, by the simple expedient of disabling them entirely... I thought the opposite was proposed by the community - avoid hjkl and I've felt the same way...
- deleted 10y ago[deleted]
- oolongCat 10y agoInstead of c2w I prefer v2ec selecting with v helps me avoid making mistakes.
- bbrik 10y agoThe advantage of c2w is that it combines everything in a repeatable (using .) operation.
- oolongCat 10y agoand so does v2ec
- godd2 10y agoIt's not the same. That will only repeat the change of the number of characters of the length of those 2 words. c2w, when repeated, will change 2 words, no matter how long the words are. For example: This is a string of text. This is a string of text. If the cursor is at the "i" of "is" on line 2, and you type v2echello<Esc>, you will have: This is a string of text. This hello string of text. If you move the cursor to the "s" of "string" on the first line, and press ".", you will get: This is a hellong of text. This hello string of text. However, if you had used c2w, it would have replaced "string of" with "hello" like so: This is a hello text. This hello string of text. Visual mode is lossy in terms of text objects. It only remembers counts of character movements, that's why it replaced 4 characters with "hello" instead of replacing 2 words with "hello".
- grault 10y agoct" or even ci" (or ci) ci] etc) is really useful to reset the inner contents of text delimited by ")] etc.. I use these a lot - http://fuckyeahvim.tumblr.com/image/122372862496 http://fuckyeahvim.tumblr.com/image/122372862496
- vacri 10y agoci", ci), ci]... I love these, and use them all the time.
- deleted 10y ago[deleted]
- pjungwir 10y agoI never got into the habit of using { and }. I just use H M L (high/medium/low) to get approximately in the right part of the screen, then go line-by-line. You can also do 5H or 10L to get "5 lines from the top" or "10 lines from the bottom". I make pretty good use of vim features, but I like to mix some sloppiness with the precision. I don't often count things before typing commands, because that breaks the second-nature quality of navigation. If something is more than 2 or 3 objects away, I approximate. I do use counting with t, T, f, and F a lot to hop around, including things like c2f). Very frequently that combines well with spamming j.j.j.j.j. I use . with trivial movement (like j or n) at least 10x more than @a. Another way to move fast sloppily is W and B. I guess I'm saying: learn all the cool stuff you can do, but don't feel like you have to find the most precise way to do every little thing. If you're just starting out, relax and don't try too hard. You can always just pick one new thing every couple weeks and try to add it to your habits. Oh also: he mentions O to insert above the current line. I use that a lot, but on my systems (going back 15 years or so I think) it has always required a pause, like vim is waiting to see if I'm typing O or some longer command. If I type O and immediately start entering text, strange things happen. This doesn't happen with o. Does anyone else experience this? Maybe it's just something weird in my own setup. EDIT: Some more "moving fast sloppily": 1G goes to the top of the file. G goes to the bottom. Also you can not-move, but scroll the visible area so that your cursor is on the top line (zENTER), middle line (z.), or bottom line (z-). I use that a lot when I am Ctrl-Fing through a file, so I can see more context.
- rogual 10y agoSounds like you've got something mapped to a key sequence that starts with O. You can look through :map and try and find it -- not sure if there's an easier way.
- pjungwir 10y agoSo this prompted me to Google for it (Googling for one-letter vim commands works better than I thought!), and this looks like the issue: http://stackoverflow.com/questions/2158516/delay-before-o-opens-a-new-line http://stackoverflow.com/questions/2158516/delay-before-o-op...
- deathgrindfreak 10y agoI find that marking my place with "ma" and returning to it with "'a" is a huge productivity boost. Of course the "a" is just a label, you can use any character (this allows multiple marks as well).
- lunchboxsushi 10y agoif you only browse code use gi, that saves me a ton of time. gi brings you back to last inserted text.
- stewbrew 10y agoWhile these tips are good per se, in retrospect I don't think it's that a good idea to tie your muscle memory that much to a single piece of software. I'd say enjoy the cursor keys. Moving around in insert mode is ok too.
- rocky1138 10y agoThis is normally true, except that in order to be good at your job as a developer, you have to be good with your tools. It helps that vim is installed by default in every modern OS.
- oblio 10y agoBut in reality you'd constrain yourself to using Vim just because it is the lowest common denominator (i.e. it is available - vi - in Sun OS 5.2 & co). Otherwise, if it's a really modern OS, there's a plethora of modern, fast, cross-platform editors that follow CUA conventions.
- Spivak 10y agoRight, but a common characteristic of modern editors and IDEs is that they attempt to be uncontroversial and follow the 'intuitive' keybindings because they're what people are used to from word processors. These editors have sparked a holy war and a cult following not just because they're powerful, but because they're opinionated. They prefer efficiency and customization over familiarity. I will freely admit that there's only only so many of those programs that I can handle in my life, but my text editor is one so frequently used that it's worth the investment.
- __jal 10y agoI sort of agree, but still ended up in the opposite corner. I use a keyboard which has no arrow keys and instead use <fn>-hjkl in every app with no (non-keyboard) configuration needed. Also, combined with some other changes (the space bar is fn if depressed with another key, space bar otherwise; caps-lock is mapped to control; a couple somewhat more complicated macros), it is pretty effective at keeping others off my machine. A programmable keyboard offers useful options.
- foo101 10y agoMoving to the far left-corner of the keyboard to reach Escape has been a major annoyance for me. On the other hand, the Caps Lock key on my keyboard is almost useless. I never use that key. Is there a way to map Caps Lock to Escape in Vim?
- yakshaving_jgt 10y agoI map Caps Lock to Escape, but I had to do it system-wide on MacOS.
- minitech 10y agoRun setxkbmap in your .xinitrc if applicable: setxkbmap -option caps:escape Linux desktop environments’ keyboard configuration tools should also let you do this.
- foo101 10y agoI am using Windows. Is there a lightweight solution to map Caps Lock to Escape on Windows?
- jackrh 10y agoCopy and paste the below into a .reg file and run it. I used Sharp Keys ( https://sharpkeys.codeplex.com/ https://sharpkeys.codeplex.com/ ) to create it, but since every major Windows 10 update resets your key mappings I just extracted it from the registry and double click the reg file after each update. Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout] "Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00
- deleted 10y ago[deleted]
- nocman 10y ago"Hitting Escape is usually unnecessary; Ctrl+[ is a lot closer, and more comfortable." I agree with a lot of the things in this article, but wow, I could not possibly disagree with this quote more. Ctrl+[ is WAY more uncomfortable than using the Escape key. Granted, I have many years of vim usage that have made hitting Escape a habit, and that probably plays a big part in it, but Ctrl+[ is downright painful for me (and yes, I sat and tried it for a while in vim to see what it would be like). I can get from the home row to Escape and back with very little effort, though I understand that is not the case for many people. Perhaps it is due to the fact that I use my ring finger to hit Escape rather than my pinky (which would be a lot more work, I think).
- OhSoHumble 10y agoI double tap j to get out of insert mode.
- btym 10y agoI suggest remapping Caps Lock to CTRL if you haven't remapped it already.
- nocman 10y agoYeah, I've seen that suggestion for many many years, but unlike evidently almost every other programmer in the known universe, I still use Caps Lock for its intended purpose (and yes, I know all of the ways I could avoid using it, but I still want to use it for that). I understand why people would like using Caps Lock for a CTRL key, as it reduces the stretch distance for many key combinations, but I don't find it enough of a problem to justify the change. So, I basically don't mind CTRL right where it is. It doesn't bother me for the things I use it for. For me, the two-handed combo of CTRL-[ is just a lot more work than the single-handed move of my ring finger to the ESC key. I don't have trouble getting my left hand back to the home row quickly after doing so either. Moving CTRL to Caps Lock would alleviate that some, perhaps, but I don't think it would be enough of an improvement to make me prefer CTRL-[ over Escape.
- 10y ago
- godelski 10y agoMovement is an important part of vim, but so is auto-competing. Probably the biggest thing that helped me greatly improve speed in vim was learning the C-x keys and that they are context aware. Having to repeat an entire or similar line/s becomes quick without having to go back to that place. Why move in the file when vim can find the text for you?
- nocman 10y agoPretty funny. I found myself asking "What does C-x do when autocompleting?" I took the 'x' literally, instead of realizing you meant C-n, C-p. xD
- Tyr42 10y agoIn insert mode, C-x actually lists the different completion methods, so it's actually accurate. ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y) I really like having C-x C-f, which autocompletes file names.
- nocman 10y agoyeah, see my reply to the parent below. :D
- godelski 10y agox is literal. For context aware auto complete of a word try C-x C-n/p. For a line try C-x C-l. For a directory do C-x C-f. And remember that this is context aware, you can hammer C-x C-n C-x C-n or C-x C-l C-x C-l. Stuff is really powerful. Changed the way I program and I never see enough articles mention it.
- nocman 10y agoAh, this should really be easier to find in the vim docs. I did ":help ^x" and only came up with: CTRL-X Subtract [count] from the number or alphabetic character at or after the cursor. {not in Vi} After trying again today, I could not find any thing on context-aware completion no matter what help commands I tried. And I can usually find what I'm looking for there. When I tried C-x in insert mode a couple of days ago, I'm not sure how I missed the: "-- ^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)" string that appears in the mode line. Perhaps I saw it and didn't grasp what it was. I'm always amazed after so many years of using vim how many new things there are to learn about it.
- bcheung 10y ago<C-c> works likes escape almost all the time. Mapping the caps lock key to Ctrl makes hitting <C-c> super easy. I usually use that instead of escape. In general I would agree 1 character at a time is an anti-pattern but it needs to be balanced with the cognitive load of counting how many words or deciding what is or is not a boundary when there are symbol characters.
- icen 10y agoThis is why `f` is really my workhorse key in vim.
- tomc1985 10y agoWhile I prefer vim for text-mode editing, it is so frustrating that it just has to use its own damn keyboard shortcuts and that the ones burned into muscle memory from 20+ years of using pretty much every text editor under the Windows/DOS sun don't work without significant hacking.
- yumaikas 10y agoI'll just drop my 2 cents here as a vim user. I've tried emacs a number of times, but I've gotten too familiar with what vim has on offer. I think where vim often wins over emacs is the 110 vi modes that every IDE eventually gets. Vi is an idea that can prosper in many environments. Emacs is kinda like smalltalk. To get much benefit from it, you have to buy into it whole hog, or not at all. I can write C# in VS with vim keybindings, go in sublime text, and then just hack on a Lua snippet in vim itself. Emacs has ways to work with all those, but that requires a new skill set that I don't need at the moment. Maybe after I graduate from college, but right now isn't the time for me.
- mastazi 10y ago> If you happen to know precisely where you want to go, navigating by searching is the way to go, searching forward with / and backward with ?. It's worth noting that, after searching with ?, you can still move back and forth through occurrences using N and n, in the same way you would after using / for a search.
- choicewords 10y agoMy eyes. Good content, but very hard to read.
- dvcrn 10y agoI can recommend vim-hardtime [0] for anyone wanting to force themselves to learn the "vim-way" of navigating. It disables n subsequent presses of hjkl where n is any number you want. For me I set it up to not allow more than 2 steps in any given direction to remind me to use jumps instead. [0]: https://github.com/takac/vim-hardtime https://github.com/takac/vim-hardtime
- JackMorgan 10y agoFor anyone who wants to build muscle memory in Vim I'm writing 10 Minute Vim, a book of pre-made exercises for practising advanced macros, RegEx, and navigation. It's already helped me learn a number of new commands in just a short time. https://leanpub.com/deliberatevim https://leanpub.com/deliberatevim
- taneq 10y agoWhile it's unarguably fun, I can't believe the effort required to become actually good at vim (as opposed to just using a few of the easier features) will ever pay itself off. (These days, at least - if you spend your days editing code in a terminal over a dialup connection, then it's absolutely worth it!) Maybe there are scenarios where the busywork of text editing really is on your critical path, but even as a fluent coder who uses some verbose languages at times (my current project is C++ and IEC Structured Text, does it get any more blabby?) I still spend far more of my time looking at, and thinking about, code than I do actually typing. Any extraneous cognitive load just takes focus away from what I'm actually meant to be doing.
- mablap 10y agoDid you take the time to learn vim? Just start using it. With only a small subset of commands you can be pretty damn efficient. The fact that you can compose actions means that you don't need to remember every command - you can just create them yourself. After a very short while you will "get" it. You can say to yourself "I want to change the next three words" and immediately do it by pressing "c3w". Or you can move around with your mouse. The former is much faster. BTW, I rarely use escape. I am using Spacemacs with evil-mode, and the default "fd" is perfect for me. It's much faster than using ESC.
- taneq 10y agoOh, I've been using it for years and I'd consider myself an adequate vim user. I'm quite comfortable in it, just using the basics - but given the small amount of time I spend using it these days, the added investment to learn the more seems redundant.
- tomlu 10y agoIt's not really about adding up time saved, it's about staying in the flow. I think you can probably achieve that by being really good at almost any editor, but vim probably does it a little better than most and it has the advantage that it's everywhere (including IDEs).
- dimal 10y ago
- bagol 10y agoMy favorite is mapping '()' to 'vi)', '[]' to 'vi]', '{}' to 'vi}'. So I can read is as "grab parentheses" instead of "visual inside parentheses"