14 ms·
Moving fast with the core Vim motions
- jerpint 3y agoFor me, the killer vim feature, apart from navigation of course, is macros
- bartq 3y agoI tried to understand what vim/nvim is all about and why people love it so I've learned it a little bit. I grasped the Zen of VIM, it's actually very comfortable to navigate files and files tree assuming Ctrl is swapped with Caps Lock and you don't use ESC but Ctrl+] or jk/jj. BUT. But. but... VIM was shining when it was designed and created, it doesn't shine that much today, because for working with code you need things like LSP, syntax awareness etc. Thing like VS Code with Emacs cross platform keybindins AND WITH smartSelect is amazing for me. Go to VSCode, put it into your `keybindings.json`: { "key": "ctrl+cmd+j", "command": "editor.action.smartSelect.expand" }, { "key": "ctrl+cmd+k", "command": "editor.action.smartSelect.shrink" } go to TS file and press keybinding multiple times to see how it grows/shrinks. Having Emacs keybindings like C-w, C-y, C-d (I'm using it to move char left), C-S-d (word left, S is shift, I'm using right one) and more I feel like flying through things like selecting block, expression, function, moving in and out etc. I guess Emacs people using paredit feel something similar taken to the next level. Ideas in VIM are still brilliant, the same goes for Emacs, but they both need to reincarnate in modern skin taking pixel perfect GUIs with proper animations to the extreme. In fully multithreaded and multiprocess environment.
- she11c0de 3y ago> VIM was shining when it was designed and created, it doesn't shine that much today, because for working with code you need things like LSP, syntax awareness etc. This is not true at all. Nvim has built-in LSP support now, there's a huge amount of plugins you can use that integrate with LSP and they work great. I even use ChatGPT inside my vim (check out this plugin: https://github.com/dpayne/CodeGPT.nvim https://github.com/dpayne/CodeGPT.nvim). The smart select functionality you mention is trivial to implement and I bet there is a plugin for this (btw, try `dit` to "delete in tag", or `di(` to delete in bracket, etc...). I will admit that you have to spend a lot of time to configure it to your liking, not everybody wants to and I understand that. Honestly I feel like (n)vim is going through a renaissance period lately, check out streamers like ThePrimeagen or TjDevries for some great content on how to get started.
- bartq 3y agoYou're defending n(vim)+plugins, not naked (n)vim and I agree it can be taken very far and can start to look like Emacs which integrates multiple external processes in single place. Actually anything can be taken anywhere with sufficient time and effort. That's the secret of transmutation. But you won't overcome the fact it uses terminal by default which I find subpar compared to pixel perfect GUIs. Terminal UIs are useful for sure, but I see them as a hidden cry of despair when people are trying to avoid touching modern GUI systems. The strength of vim (vim motions) should be stripped away and be embeddable in any other system as a leaf, not the other way around where (n)vim is in the center and other pieces are plugged into it. I know it's happening and you can use native nvim inside e.g. VSCode which is great. I know there are tools like GVim etc, but again, they are created with high engineering effort which for some people is simply pleasant to undertake. Again, I'm not trying to defend or favor any system, I'm actually using at the same time VSCode (for best TS intellisense), WebStorm (for refactors), nvim (for quick browsing and small config file edits) and Emacs (for Magit). My computer is my tool, not single thing inside it.
- mekoka 3y agoSometimes the world can be improved. Most times it's just fine and any suggested external change should probably start from within. There are those who like letters, words, and the sound of keyboard keys. Then there are others who like pretty pictures in big buttons and the click of the mouse. All this to suggest that perhaps you are the wrong target for text-base interfaces.
- bartq 3y agoWhy did you make it personal, let's focus on talking about things/ideas. I'm not even trying to comment your guess about what "target" I am.
- mekoka 3y agoBut but but... your posts are about you! They're just presented as though it's a problem with the tools. I'm simply holding up a mirror, using a similar language, and suggesting that perhaps you are not the target of the tools you only dabbled with and presumed to then criticize.
- deleted 3y ago[deleted]
- blindstitch 3y agoThis article sadly passes over one of the most important features of vim, which is its ability to work as an ascii art editor. To begin, open a new buffer and create your canvas: "99i<space><Esc>yy99pgg0". This will make a buffer of 99x99 space characters. To draw horizontally, press shift-R to enter Replace mode, similar to overwrite mode in Word. To fill rectangular areas, use control-v to select the first corner, use motions to select the second corner, then r<character> to replace the block with what you need. To copy and paste areas of your art, use y and p on areas you select with visual block mode. If anyone else has any tips please let me know.
- Mimmy 3y agoOne I use often but haven't seen here yet is `i(` or `i{` or `it`. Basically an adverb for "inside parentheses", "inside braces", or "inside html tags". I most commonly use it in combination with `c` to rewrite whatever was inside. For example `ci(` will automatically delete everything inside either the current parentheses or the next closest pair of parentheses and put me in insert mode.
- AntonyGarand 3y agoIn this same vein I also use `a`: `a(` `a{` `at`, which I use as "around [item]". It behaves like `i` but also includes the "container", which is especially useful with html tags as you can quickly change or delete the whole tag this way.
- umutisik 3y agoIf a Vim plugin could analyze what I do and suggest commands I don't already use that would save me time, that would be fantastic!
- tmaly 3y agoback in the university days, I could get an extra hour on my CS assignments if I went to the library and connected to the systems on a green VT100 terminal. Vi was the only editor available, so I forced myself to learn it. Still using it to this day.
- sva_ 3y agoI think the article is missing ctrl-y move up 1 line without moving cursor ctrl-e move down 1 line without moving cursor ctrl-b move up 1 page, placing cursor on last line ctrl-f move down 1 page, placing cursor on first line. These are really useful when looking around without wanting to edit.
- grelek 3y agoThanks, didn't know about these.
- sodapopcan 3y agoI've always used ctrl-e and ctrl-y with `:set scrolloff=2` to make it a bit quicker. It was one of the first things I learned as I found ctrl-d and ctrl-u incredibly jarring and thought there must be another option.
- simias 3y agoLike TFA I only use ctrl-u and ctrl-d since it's faster than moving one line at time and not as disorienting (in my experience) as moving one full page at a time. It's also easy to learn since it's [u]p/[d]own.
- AdieuToLogic 3y agoDon't forget the handy "z commands": z<CR> redraw, cursor line to top of window, cursor on first non-blank z- redraw, cursor line at bottom of window, cursor on first non-blank z. redraw, cursor line to center of window, cursor on first non-blank (source: :help z)
- cryptonector 3y agoThere's also H (move to the line at the top of the current screenful), L (move to the bottom line in the current screenful), and M (move to the middle line in the current screenful).
- kagevf 3y agonH is also good if you want to go to line n from the top. Works in reverse with nL too :)
- auto 3y agoWe've got younger guys on my team that hem and haw about the fact that we only have vim on our hardware implementation (SAMA5 busy box), and straight up don't understand why I basically can't use VSCode without the extension, and this article hits on so many good points. Vim is extremely expressive, and everyone ends up using it in slightly different ways. For me, my movement tends to center around: - 'e' and 'k' rapidly, or 'h' and 'b' rapidly to move left and right, or using 'f'/'F' and a target character, with '0' and '$' as needed - For vertical movement, I tend to use ctrl+'d'/'u' to move the document up and down in chunks, then specific line numbers, as well as marks (usually at most 2-3, with 'a', 'b', and 'c') to hold on to specific areas, or I just end up remembering line numbers and jumping to them. - Lots of yanking and deleting to specific targets, be it hori or vert There's plenty more beyond that, but that really is the "crux" of my vim usage, and from what I've seen watching over the shoulders of many programmers over the years, it makes me way faster than most. Programming isn't about typing speed, but my work is often in doing large refactors in enormous codebases. I need to be able to move around as close to the speed of thought as possible, and I have never found a tool that comes anywhere close to providing that ability as vim. Also, any chance I get to plug the greatest StackExchange answer ever, I will: https://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118 https://stackoverflow.com/questions/1218390/what-is-your-mos...
- yodsanklai 3y agoMy usage is similar. I also use all the time - shift - v - } to select a block, or v - w to select a word. It's not strictly needed but help ensure selecting the right stuff - ctrl i - ctrl o for navigation I've never been able to use tabs, buffers, multiple file edition, that's just too much overhead for me. I rely on vscode for that. That being said, I don't think using vim gives me a competitive advantage. I'm also rather proficient using standard OS shortcut. I like vim out of laziness, it minimizes hand motion, but don't make that big of a difference IMHO. (also lots of young guys use vim too, some younger guys in my team even refuse to use vscode...) EDIT: also vi adds a lot of value in the terminal where standard OS shortcuts don't work, at least on MacOS (i'm waiting for comments telling me how to make them work!)
- 3y ago
- u801e 3y agoIt's also missing H, M, and L for moving the cursor to the top, middle, and bottom of the window respectively. You can also navigate using the % command. For example, you can use 50% to scroll to the middle of the file, 75% to go down 3/4ths of the way, etc.
- j2kun 3y agoNot to mention using the % key for jumping to the matching bracket. Or tree-sitter for navigating scopes
- sodapopcan 3y agoI rebind all of these keys. I don't know why but I never find this useful in vim. In tmux's copy mode I use them all the time, but ya, I can't quite put my finger on why I never miss them in Vim. A long time ago I mapped `H` to `^` and `L` to `$` but it got too annoying when I'd use Vim on a server. I've met a couple of people since who have those exact mappings, though!
- peoplearepeople 3y agoThat page is really hard to read on a desktop monitor, everything is huge and wide
- Gualdrapo 3y agoNot everything - the code blocks take the full width of the page and break the reading flow so hard. Also the font title is just huge and so bold. Even on a narrow window.
- stevebmark 3y agoTo move fast, use the mouse[1]. Trust me. I've played that game of always trying to find the most efficient way to target something on the screen in Vim. If you haven't already learned about EasyMotion, tried it, and gave it up, you probably haven't tried to perfectly optimize your movement in Vim. It's not a game worth playing. Figuring out how to navigate your screen with the keyboard is a Vim problem: editing text now is something you have to think about, a lot. [1]There is no conclusive evidence that Vim's motions help you type nor navigate faster
- ykonstant 3y agoIt is extremely frustrating to see a post downvoted just because it is a diverging opinion, especially when it contains some of the best advice in this thread. Indeed, for random access on screen, there is no better alternative than the mouse or trackpoint (the latter defeating the non-argument about moving your hand, since it is literally in the middle of the home row), that is what it was designed for. And if for whatever reason you don't want to use a trackpoint, install EasyMotion and map the random access motion to spacebar or another big key as I have done. It is the second best way to achieve random access on screen. For more structured motion/editing tasks, I am perfectly happy with Vim's advanced motions on text-objects. But random access is still a very common task, and trackpoint or EasyMotion is just both faster and more "ergonomic".
- jodrellblank 3y ago> "Indeed, for random access on screen, there is no better alternative than the mouse or trackpoint" There should be. Touchscreen. Eye tracking. With a mouse I have to go via a silly walk[1] moving my arm and scraping a chunk of plastic over a desk as a proxy for scraping a mouse pointer over the screen. With a keyboard I have to invent a magical incantation of button presses to poke the state machine and make the cursor do a silly walk over the lines/rows/words/brackets/search term/etc. from where it is to where I want it to be. Why can't I look and "go there" directly without either silly walk? [1] https://4.bp.blogspot.com/-53TOKiAMoow/VD0EeGQ24oI/AAAAAAAAW3A/CFCQb3XD4OE/s1600/Ministry%2Bof%2BSilly%2BWalks.gif https://4.bp.blogspot.com/-53TOKiAMoow/VD0EeGQ24oI/AAAAAAAAW...
- lkbm 3y ago"Vim as a Language"[0] is a similar article I benefited greatly from back in the day. One additional tip once you start using things like d8k: Try "set relativenumber" in your vimrc. It makes all except the current line display offsets rather than absolute line numbers. Initially, this seems silly, but you quickly realize that if you're at line 1668 and need to delete up to line 1619, it's much more helpful to see line 1619 listed as "line 49" rather than "1619" and having to do the mental math to figure out that the command you're looking for is "d49k". [0] https://benmccormick.org/2014/07/02/062700.html https://benmccormick.org/2014/07/02/062700.html
- lachlan_gray 3y agoI wonder if eye tracking could be used as a vim motion if it becomes really good on new vr/ar headsets. Vim is already fast, but…
- dialogbox 3y agoThat will make my eye super tired. Just looking at a word doesn't need much effort but focus on very precise location in between two character is very different. Try it with for example iiiiiiiiiiiiiiiiiiii or |||||||||||. Actually, the presence of a cursor makes it much easier. Place a cursor and looking at it vs Place the cursor by looking at a place are very different.
- Tmpod 3y agoDunno about eyes, but feet sure have untapped potential :p https://github.com/alevchuk/vim-clutch https://github.com/alevchuk/vim-clutch
- renewiltord 3y agoI actually did not enjoy using a vim pedal in clutch or toggle mode. YMMV Mostly because my pedal was too sensitive and so I could not rest my foot on it.
- thezorg 3y agoI recently learned about the `])` motion (and similarly, `]}`), and it's probably my absolute favorite. I used to rely on e.g. `df)` to delete function parameters. The problem is that 1. it doesn't work when the function call spans multiple lines, and 2. it doesn't work if there's a nested function call. With `d])`, Vim will delete until the next unmatched ')', regardless of which line it's on! And to think this motion is buried under "Various motions": https://vimhelp.org/motion.txt.html#%5D%29 https://vimhelp.org/motion.txt.html#%5D%29. Edit: an example: // This will become my_func(foo); my_func(foo, MakeBar(), MakeBaz()); ^
- sarthak-ag 3y agoWow this is awesome, thanks for sharing. I used to use visual mode for this edit in particular but this feels much more intuitive and faster
- lkbm 3y agoIn most cases `di)` is what I want, deleting everything inside the current parens, forward and back. I can see use-cases for "forward only", though.
- ninkendo 3y agoI’ve learned to favor using c instead of d if I want to edit after deleting… it keeps things in one logical command from vim’s perspective, so that I can repeat it a second time on another line by just using `.`. Using d and then i, vim treats as two commands and thus `.` only repeats the insertion.
- skupig 3y agoThat's a great one, I should read the docs more often... Two very useful ones I just saw on there, for undoing movement mistakes: `` to jump back to where you jumped from `< to go to the starting character of the last selected visual mode region
- nzach 3y ago
- drekipus 3y agoI'm a big vim user but I disagree with the notion of being faster with it. It's usually not so much the motions themselves that work, but rather the ergonomic shortcuts for everything else (like LSP functions, nvim-harpoon fzf) Frankly, I'm just too used to the vim motions now to be good at other editors.
- mrinterweb 3y agoI use the leap plugin quite a bit. I can look anywhere in the buffer and jump there with 3 or 4 key presses. ggandor/leap.nvim
- maximilianroos 3y agoFolks misunderstand why Vim is so popular. Do you prefer navigating files like a startled hamster, jabbing "alt-left" incessantly? Or like a ninja, swift and accurate? Fancy playing Whack-a-Mole, relentlessly pounding a single key? Or Tekken, delivering insane combos with a precise 9 character sequence? Vim is about gaining mastery rather than actual efficiency. And it's great.
- deleted 3y ago[deleted]
- scubbo 3y agoWhen claims like this are made, I'm skeptical people have retrained their minds such that "press this combination of keys repeatedly until the cursor is where you want it to be" is easier and more accurate than "mentally count the number of word boundaries your cursor is away from where you want it to be, then enter the command to get it there". I don't disagree that vim's movement commands have greater precision, but I find it hard to believe that that precision is actually useful in practice. EDIT: Oh, my bad, you specifically called out that efficiency is not the actual goal. In which case - yes, for "feeling like a badass", I am wholly on-board :)
- xwdv 3y agoPeople who never master vim will never know the high of pounding combo after combo and watching lines of code morph and manifest before their eyes at the speed of thought. Once you’ve experienced this, no other editor will satisfy you. Combine this with the sounds of a clicky keyboard, and it feels like heaven.
- scubbo 3y agoI've used my fair share of macros to transform text. Vim's great for that. But that's less than 1% of my work as a developer. Much more often, I'm wanting an IDE to do things like: * Run/debug code * Jump to a declaration of a function/variables, or find it's uses * Extract some code as a function * Rename a variable (and all uses of it) I bet vim probably _could_ do all of that with the right plugins - but dedicated IDEs do it out-of-the-box. Even something as simple as indent/dedent a block of code is "click-and-drag, tab/shift-tab" in an IDE, vs. ":<range declaration>s/^[^$]/ /" in vim.
- jeanlucas 3y agoSo that's what they mean when they say you need to exercise your core
- astrod 3y agoMy favourites are A and I, finding them easier to reach for over $ and ^. I find myself stalling sightly whenever I use f, while I try to pinpoint the character to jump to. It's the only motion I am not fluid with.
- yakshaving_jgt 3y agoThey do different things though. I also think $ and ^ are uncomfortable to reach for, so I remapped them like this. https://jezenthomas.com/2015/05/a-function-for-moving-to-the-beginning-of-the-line/ https://jezenthomas.com/2015/05/a-function-for-moving-to-the...
- keithnz 3y agoI really like sneak which is basically like f but with two letters, works really well.
- herewulf 3y agoYes, this. Single lines don't often have the same two characters in a row (or if they do, then you can get to the one you want fast with ; ). Even large paragraphs don't often have many of the same two characters. Sneak is amazingly fast for moving around without gumming up your search history (since one can do similar with / ).
- mabil 3y agoI was in awe of a friend using vim, I asked him how someone could possess that power, he promptly gave me a license of https://vim-adventures.com/ https://vim-adventures.com/ and now I can't use any other editor that at least have a vim plugin. Give the game a go, totally worth it if you want to ease into learning vim, after some time try and use it for everything, even if it fells slow, persist and it will be worth it.
- eviks 3y ago> None of these are my favorites but they’ll do for the time being. In the custom mappings chapter, you’ll learn how to create a custom key binding for the ultimate mid-range vertical motion. Yeah, vim defaults are bad, so it'd be better to teach the improved keymap rather than wasting time learning the ones even author doesn't like and then learning how to remap them It's a pity vim is so inflexible with keymaps that it ships with only one by default, making the step above harder (also, "melodies" are chords, and the other ones are just combos)
- AdieuToLogic 3y agoAn epiphany I had years ago was realizing that keyboard-based commands enables semantically dense editor interaction. Specifically, vi(m?) has a large number of commands available as 1+ letter combinations. This allows for a very large set of operations usually available within 5 or less characters. Compared to WYSIWYG editors, the theoretical efficiency difference is tremendous. Of course, for any given person using such a powerful editor, no two usage patterns will be the same. This is a testament as to why vi(m?) has lasted so long IMHO.
- cryptonector 3y agoBut also modal editing increases the number of such combinations. And most importantly modal editing decreases the number of modified keys (control, shift, alt, meta, two of those, ...). Your lack of carpal tunnel might thank vi and VIM, if a lack of something could be a conscious thing.
- AdieuToLogic 3y ago> But also modal editing increases the number of such combinations. And most importantly modal editing decreases the number of modified keys (control, shift, alt, meta, two of those, ...). +1 > Your lack of carpal tunnel might thank vi and VIM, if a lack of something could be a conscious thing. I totally agree regarding how using vim as a program editor helps reduce RSI[0]. Another way to reduce same which I employ is to swap caps lock and the left control key. Not only does this reduce unnatural contortions, it also facilitates easier use of common keyboard combinations in both vi and terminals, such as: - using ^[ instead of ESC. - using control-based vi navigation commands (^B, ^F, et al). - using ^M instead of return (less useful). - making terminal control characters much easier to produce (^U, ^\, etc.). 0 - https://en.wikipedia.org/wiki/Repetitive_strain_injury https://en.wikipedia.org/wiki/Repetitive_strain_injury
- cryptonector 3y agoAnother thing that helps is the accessibility feature known as "sticky keys". Specifically it helps prevent/reduce ulnar and other deviations. The paucity of modifier keys in vim also helps, as noted earlier.
- ckw 3y agoThis is a little off topic, but some people might find this useful. I have bindings that allow me to execute the current line or paragraph under the cursor in the underlying shell and then inject the result into the current buffer. "execute the contents of the current line => sx exe "nnoremap " . g:leader_prime . "x :call ExecuteCurrentLine()\<CR>" Here leader_prime is just a second leader key I use: 's', but you could map the command however you like. ExecuteCurrentLine() is implemented as: function! ExecuteCurrentLine() let l:com = substitute(getline('.'), '\#', '\\#', '') exe "norm! mc" exe "norm! o\<Esc>" exe "r! " . l:com exe "norm! mr" exe "norm! o\<Esc>" endfunction Two more mappings: exe "nnoremap " . g:leader_prime . "p :call ExecuteCurrentParagraph()\<CR>" exe "nnoremap " . g:leader_prime . "c :call ExecuteCurrentLineWithBC()\<CR>" and their implementations: function! ExecuteCurrentParagraph() let l:init = line('.') exe "norm! {j" let l:start = line('.') exe "norm! }" let l:end = line('.') exe "norm! o\<Esc>" exe "r! " . join(getline(l:start,l:end), ' ') exe "norm! o\<Esc>" endfunction function! ExecuteCurrentLineWithBC() let l:com = getline('.') exe "norm! o\<Esc>" exe "r! " . "echo 'scale=12;" . l:com . "' | bc" exe "norm! o\<Esc>" endfunction As written above, I type 'sx' to execute the current line under the cursor as a shell command, and then inject the result back into the buffer where I am. 'sp' does the same, but for the entire paragraph the cursor is on; this is really convenient for things like a large sql query which is more readable written over many lines. And finally 'sc' executes the current line in the bc calculator program in the underlying shell, so you can evaluate arithmetic expressions in the buffer.
- kps 3y agoWhy not just use `!`?
- ckw 3y agoSee my reply to AdieuToLogic.
- AdieuToLogic 3y agoAnd see my reply to you :-).
- thot_experiment 3y agoI gotta give a shoutout to `gj` and `gk` because sometimes I write really stupid loooong oneliners or just use vim to edit markdown and i want to move up and down in screen lines, not real lines.
- yeck 3y agoI just came across this yesterday. While I'm pretty good at keeping my code <= 80 columns, I also write a lot of markdown where lines often wrap. Remapping `j` and `k` to `gj` and `gk` is a really nice quality of like improvement :D (If doing such a keybind, you'd want to check to make sure count is 0 or things will get wonky for you)
- herewulf 3y agoType gqip with your cursor on that long line to tame it (and neighboring ones in the paragraph). ;)
- AdieuToLogic 3y agoMore fun with vim. Assume you have a vim editor open with multiple files, each of which need to have their lines lexicographically reversed. Is this a contrived example? Sure, but bear with me for a moment. A macro can do this pretty easily and could be recorded via 'q<buffer>', where '<buffer>' is a letter. But recording macros this way can be a bit opaque. Plus, having to manually invoke it for each buffer is suboptimal. Here is one way to do the above: - enter the desired commands on an empty line (such as :1,$ !sort -r^M:w!^M) - review the vim commands and refine as you see fit. - execute the following in normal mode on the same line (to load the 'a' register): 0"ay$ - execute the following ex command (to discard loading the 'a' buffer): :e! - execute the following ex command (to apply 'a' to all buffers): :bufdo normal @a In this example, all buffers in the vim session will have the commands in the 'a' buffer applied (reverse sort their lines and contents saved).
- zyl1n 3y agoSomeone should implement an editor for Apple's Vision Pro that moves the cursor using eye tracking.
- rasengan0 3y agowow, no one mentioned, gm. The middle way, all day long.
- endorphine 3y agoA bit off-topic, but I only recently discovered these and found them pretty useful for navigating big codebases: c-w-| zoom in a particular window c-w-= zoom out I'm wondering how many people know this and if they use it or have a better way of putting other windows at the background for a while.
- jodrellblank 3y agoWhat do you mean by zoom? `cw |` is change word and then types the pipe character. `Ctrl-W =` is "make all windows the same height & width" `Ctrl-W |` is "set window width to N columns"
- endorphine 3y agoDoes anyone have any screencasts to suggest showcasing people being very efficient in vim, in action (e.g. like Gary Bernhardt)?
- Zizizizz 3y agohttps://youtu.be/y6VJBeZEDZU https://youtu.be/y6VJBeZEDZU
- koinedad 3y agoLots of good stuff. I use most of these already when I am reading through files or making quick edits but in the terminal. I have never found a use for counts. It always feels like my brain slows down. Relative line numbers helps a little. I sometimes try to estimate counts but it’s also kind of annoying.
- kagevf 3y agoI think most of the movements covered work with the Visual Studio vim plugin as well. Just in general, when using an unfamiliar editor, having a vim plugin lets you bypass having to learn (most of) that editor’s navigation and movement shortcuts.
- isoprophlex 3y agoAnd here I am, hitting the numeric row "1234567" and h, j, k or l because I never leaned how to move to the beginning or end... and i can't get the muscle memory out :(
- deleted 3y ago[deleted]
- 0x0203 3y agoIf you're actually interested in getting some of that muscle memory, my suggestion to people just getting started has always been to simply force yourself to use vi(m) for whatever you're working on and only learn one or two new things at a time. Say you've just learned gg and G to move to the beginning or end of the file. Whenever you find yourself wanting to move to the beginning or end, use your new command. Don't try to learn any more until gg and G have become second nature (or unless you find you don't really use it often enough to justify committing it to memory; it will happen). Then figure out what your next biggest slowdown or frustration is and figure out the "vim way" of doing that and add that to your repertoire. Rinse and repeat. If you do even a moderate bit of coding, it really doesn't take long to learn enough to improve your speed/efficiency. It may feel slow and frustrating at first, but in my experience, and for everyone I've "coached" on vim, it's a pretty small hump to get over if you just stick with it. By the time you've got 20+ years doing this, you'll have a workflow that is extremely well suited to your needs/preferences. And that's the nice thing with vim; it will always have room for you to expand your skills with it, but you don't have to know even close to all of it to benefit from it. Use what fits your needs and what helps; the rest is just candy.
- lelanthran 3y ago> And here I am, hitting the numeric row "1234567" and h, j, k or l because I never leaned how to move to the beginning or end... To navigate I use a very reduced set of commands: Shift-A, Shift-I (insert at end or beginning of line) o, O (insert line below, line above) For everything else, I use /<snippet> or f<snippet>.
- amoss 3y agoTry playing this: https://vim-adventures.com/ https://vim-adventures.com/ It's great for learning the muscle memory of basic motions.
- sjaak 3y agoI've become comfortable with using vim /within a file/, what I'm having trouble with is using vim while having multiple files open (keeping track of which ones I've saved, switching between them, etc.) My current workflow is to have multiple files open each in a separate terminal tab, but navigating between them Cmd+Shift+[ and ] feels suboptimal. Does anyone have any great tips? I work on Java and Ruby (rails) projects most of the time.
- themodelplumber 3y agoLess of a core vim tip, but since it's vim-style: I like to use ctrl shift H and L to move L/R between tabs in whatever terminal app I'm using. (And since I'm open to learning other tips, I'm just going to say that this is the best method possible for navigating the tabs, period)
- flashgordon 3y agoI have taken a while but I live in split windows. Ctrl-v to split horizontally, "new" to do so vertically. Ctrl-v them h,j,k,l to navigate between splits. I have two nice short cuts that help you open files relative to the directory of the file in which ever split you are in!! I am not a vim expert and I usually stick to a vimrc file that intake with me everywhere and I get my zen quickly. Happy to share more.
- mo_42 3y agoI'm using these for switching buffers: " Move between buffers nnoremap <silent> <c-l> :bn<cr> nnoremap <silent> <c-h> :bp<cr>
- lelanthran 3y agoI use Vim for development with multiple files; I find that up to 9-12 open files are manageable, but more than that and the lack of a file browser impedes me[1]. Example usage: Open files in vertical splits: vim -O src1.j src1.c src2.c Open files as I need them in new tab: :tabe src3.c In new tab, open two more files (as I need them): :vsplit src3.h :vsplit CHANGELOG I've mapped Ctrl-PageUp/Down to next previous tab/next tab. When I want to exit, I save the session: :mks! When I want to restart that session: vim -S Session.vim Like I said, it gets unwieldy after around 9-12 files open (typically 3 in a tab). [1] Nerdtree messes up my splits so I don't use it.
- ed25519FUUU 3y agoThe nice thing about vim is all modern IDEs have vim movement plugins. Once the movements become muscle memory you can keep using them in new environments. Nice!
- herewulf 3y agoThey come close.. Then you start running into discrepancies which become really aggravating. I've never been a NeoVim user but probably the best solution is to embed it in an IDE rather then reinvent the wheel badly.
- nathias 3y agoI prefer H, L, zz.
- littlecranky67 3y agoI've recently discovered vim and I've been using it ever since, mostly because I don't know how to exit it. - Obligatory joke on every vim thread.
- JenrHywy 3y agoThe most amazing thing about vim is that, even as a fairly basic user, I can read an article like this, learn a ton, and still realize that I have an easier way of doing something than the author (why use 100gg when :100 exists?). It seems no matter how much you know about vim, there's always more.
- TonyStr 3y agoTechnically yours (<Shift>, :, 1, 0, 0, <Enter>) is one more keystroke than his (1, 0, 0, g, g) if you count shift and enter. If you don't count shift, you can also do 100G. I personally prefer :100 even though its technically the most keystrokes
- JenrHywy 3y agoThat's an interesting observation. I can't justify why, but : feels a lot more fluid to type than gg, even though as you say, gg has less keystrokes and still keeps you on the home row.
- fractalb 3y agoAny one knows how to jump to the beginning of the pasted text?
- AltruisticGapHN 3y agoI love Vim but I also am not convinced that having more "motions" makes you more efficient. Specifically, I think the "Javascript the Good Parts" approach applies to Vim as well : if 90% of the vim shortcuts I use only 5% of the time, it's both not worth my time to invest in learning them, it's also making invest less time really mastering the best shortcuts. So I feel like Crockford's mindset in that JS book totally applies to vim: if you can do some motion with two keys instead of one, but using a smaller set of motions that you get to know REALLY well, then trying to remember the extra shortcuts just so you can save a key is not a good investment - on the other hand it is a great way to continue to mythologize some kind of "super efficient" developer/writer whose work somehow is made better by typing faster. Vim is complex enough as it is. I'd love to see a really opiniated "Vim : The Good Parts¨ manual - where the author collects the most useful motions, and bluntly says "these are NOT worth learning".
- xigoi 3y agoThe problem is that everyone has a different small set of shortcuts that are useful for them.
- bionsystem 3y agoI feel pretty fast with just a handful of shortcuts and I learned those for maybe an hour, years ago. Somehow I can't bring myself to learn much more and I agree that the incremental gain is probably low. Although when writing C I also tried cscope (which is more of a search in the entire repository, not really a vim motion) and it was pretty damn useful to browse code. Nowadays I mostly use grep and find.
- h43z 3y agoI created https://vtip.43z.one https://vtip.43z.one to help me learn vim one tip at a time. It's just 3 lines of vim script that if called will show you nice tip like Use Ctrl+n to open the auto-complete menu while typing. Press zz to center the current line in the visible window. Use G to move to the end of the file. function! Vtip() echomsg system('curl -s -m 3 https://vtip.43z.one') endfunction
- absoluteunit1 3y agoSecond this ^. I saw your post on Reddit and started using it. Thanks!
- xphos 3y agoMaybe a hot take but if you want to convince people to use vim show them box select and yank and replace. It's just extremely efficient and no other editor(ide) I've used really has it by default. Or ask them to open a 100 mega byte log file in eclipse. Even Advance IDEs simply just die. Cannot count the number of times smart diffing with vimdiff and box cutting has helped me diagnose problems that were extremely subtle. Without vim I simply couldn't do that type of diagnostics Sames true if emac or other text editors too
- d4rkp4ttern 3y agoNever really got into Vim. I grew up on Emacs a happy with my Doom-eMacs setup. But recently discovered the Vimium extension for Chrome and wow it is a life changer! It is what I have always been looking — a noiseless way to quickly go to any tab, history or bookmark.