9 ms·
Vim tricks
- periya 7y agoI’ve discovered q: when trying to quit vim in a hurry. You always keep finding new quirky things to do in vim but I guess the same hold true for other text editors like Emacs
- godelski 7y agoThat's how I found `K`. I was surprised the first time I got a man page open. Now I find it pretty useful and wish it extended to more than man pages.
- ronmrdechai 7y agoTake a look at `:help 'keywordprg'`.
- godelski 7y agoCan I do things like get `K` to work on python commands? Including modules? Or with other languages? I see that I can do `set keywordprg=pydoc` but I want modules too.
- matthewn 7y agoCheck out vim-dokumentary: https://github.com/gastonsimone/vim-dokumentary https://github.com/gastonsimone/vim-dokumentary
- dredmorbius 7y agoI remap that to query dict in prose contexts. Mostly for mutt: au FileType mail set keywordprg=~/bin/dictless
- CalChris 7y ago":, @: ": is the register storing the last executed command. You can write ":p to print it to the buffer. @: reruns the last command. That seems like a mouthful. I use :<up arrow> to run the last command and <up arrow> some more to run the ones before that.
- frutiger 7y agoYou can also use `:^F` to navigate your history in a horizontal split using regular motion/search keys.
- tartrate 7y agoAnd if you wanted to repeat that 10 times you would...?
- mises 7y agoPress up ten times. That's still what a lot of us do in terminal (particularly when we're on a machine without fancy shell history fuzzy-searching etc.). I guess I might press and hold at ten.
- grimgrin 7y agoYour machine probably has ^r for working through bash history But that aside, if you’re into arrow pressing, a few lines in your .inputrc can go a long ways Test this out sometime: # Incremental searching with Up and Down and Left and Right "\e[A": history-search-backward "\e[B": history-search-forward Now you can type “find” and press up/down arrow to just cycle through history that starts with find
- jonahx 7y agoUse vim-repeat: https://github.com/tpope/vim-repeat https://github.com/tpope/vim-repeat
- lithiumfrost 7y agoPersonally, I would do 9@@ after the first @:
- dredmorbius 7y agoClickbait title conceals a decent article.
- dang 7y agoChanged now.
- michaericalribo 7y ago> U is the same as u except it does the undo as a new change, which is functionally useless. Unless I’m mistaken, this is the default undo behavior for emacs...What horror to only have vim’s forward and backward undo history! Said the emacser on the vimmer’s post.
- mden 7y agoMaybe misunderstood what you meant, but vim's undo is not linear but rather tree-like. You can undo, make a change, and still get back to the initial state. https://vim.fandom.com/wiki/Using_undo_branches https://vim.fandom.com/wiki/Using_undo_branches Edit: this also seems to be in the original post
- michaericalribo 7y agoYou are definitely right, and I still find the emacs undo confusing...but I did think it was funny that one dev’s trash is another’s treasure—now that I know what to expect, I even kind of like the emacs way, but when I first switched I hated it.
- fwip 7y agovim also has "undo tree" functionality built in, the interface is just different than emacs's. :help undo-branches http://vimdoc.sourceforge.net/htmldoc/undo.html#undo-branches http://vimdoc.sourceforge.net/htmldoc/undo.html#undo-branche...
- roelschroeven 7y agoU is not the same as u, though: u undoes the last change, U undoes all latest changes on one line.
- godelski 7y agoThere's a few commands I LOVE but find frequently unmentioned. In insert mode, <C-x> is a contextual completion. So like the normal <C-n> or <C-p> you just do <C-x><C-n> and you can keep hammering the <C-n> to fill in multiple "words". You can also complete lines, file paths, dictionary words, thesaurus words, tags, spelling, etc. See `help ins-completion`. Seriously, I can't do without this command. <C-x> needs to be in everyone's daily use. Also in insert mode: <C-w> deletes a word back. You'll commonly find this is a lot of editors and stuff where it doesn't close a window. Similar to <C-backspace>, though I many times accidentally hit <C-w> in my browser instead of <C-backspace> because I use this so much (bad speller). <C-[> much easier than pressing Esc 0 much easier than pressing ^ (honestly I have anything that is $,%,^,&. They aren't easy to reach) Honestly, vim has some of the best written documentation I've read. If you really want to master vim, just read the docs on commands you already use. I guarantee you'll find something you didn't know.
- Exuma 7y agocan you give more examples of <C-x><C-n> in code editing? I have tested that out in vim and its cool but i cant think of times I want to repeat a series in another part of the document, perhaps I'm just very uncreative right now Thanks
- godelski 7y agoTotally. But I will tell you, <C-x> is a habit built around the other options too. So I just use <C-x> on any completion (which I frequently use <C-x><C-f>). Here's a dumb example (dumb because there's other ways to do it that are better) Let's say I'm overloading a function. void foo(int a, int b) {} I could do v<C-x><C-p> until I fill in the b, then type ", int c)". Now it'd be totally easier to do "v<C-x><C-l> backspace , int c)", but that's a different point. Maybe this one is a little more useful "def _<C-x><C-p><C-x><C-p>" may expand to "def __init__(self" Note that here I'm holding down ctrl and just hitting "xpxp" Honestly I end up finding a lot of patterns in my code just because I started thinking about it this way. It is more one of those things where once you start thinking about it with it in mind you will find patterns. It is also an easy habit to develop, if you already use <C-n>, because when you press ctrl you just also hit x and keep your pinky down on ctrl. I feel like there is just no downside to using <C-x> because in reality it is just one more keystroke, which is done with the other hand (so even less increase in work).
- m0zg 7y agoThe problem is, how do you remember all of this stuff? Tabdo/bufdo is as advanced as it ever gets for me.
- Exuma 7y agoYou have to make a deliberate attempt to learn it. What i would do is when coding I would focus on a single command and do it 5 or 6 times until it was engrained, then I would go to the next one. I spent about 15 days straight fairly intensively learning vim .. taht was 8 years ago. Best decision I have ever made in my entire programmign career. Now I pick up new vim commands like I am multilingual in 20 languages. All the commands I can usually remember without even typing them, they just stick. It definitely has the rolling snowball momentum effect
- m0zg 7y agoAt my billing rate "15 days straight" is approximately equal to a low end BMW. So I think tabdo/bufdo will have to do for now. At least until I get a salaried job and can learn the rest at my employer's expense. I do think there's Pareto principle at play with all this obscure stuff. Knowing 20% gets you 80% of the benefit, every additional percent gets you exponentially smaller fraction of the remaining 20%. That's how I play it anyway. I don't feel like I'm any less productive with my 20%.
- CardenB 7y agoIt doesn’t take 100% of your time to learn vim. You just work 20% slower while you are intensely learning, then you work back at 100% for a while, then you work at 120% after you have internalized everything.
- Exuma 7y agoUh ok, what a weird answer. Regardless, the benefit cannot be overstated. I am not exaggerating that it was the single greatest decision I ever made.
- tambourine_man 7y ago
- binaryapparatus 7y ago"Exobrains, on the other hand, stuff Vim full of plugins, functions, and homebrew mappings in a vain attempt to pretend they’re using Emacs." This is disturbingly accurate from my point of view. I keep wondering if I should finally jump ship and stop tweaking vim with questionable results. Spacemacs? Pure emacs + evil? Suggestions welcome.
- chestervonwinch 7y agoI write primarily Python. Pycharm+vim bindings has been quite a pleasure in my experience. I still primarily use straight up vim with little to no mods for editing one-offs and isolated scripts.
- binaryapparatus 7y agoInteresting, I don't often use Python but recent project had few 3000+ lines .py files, which make Vim _very_ unresponsive when editing. Other languages weren't so problematic but Python code is what made me look at Emacs direction at the first place.
- brennebeck 7y agoThis surprises me. How does it make vim unresponsive? I frequently open multi-GB sql files without vim choking. Are you using some particular plugins?
- binaryapparatus 7y agoI was using/am using: Plug 'tmhedberg/SimpylFold' "Plug 'python-mode/python-mode', { 'branch': 'develop' } "let g:pymode_python = 'python3' ... in different combinations. Deleting any char takes surprising amount of time, so much so that I usually mark block to delete instead of char by char even if it is three char block. Of course I may be using wrong plugins, however that's what I found that should be used in various articles online.
- chestervonwinch 7y agoOne I learned recently transferring some LaTeX over to rST is visual highlight => "gq". This breaks up long lines to multiple lines based on your stored text width. It can also be coupled with motions, e.g., "gq}".
- xelxebar 7y agoYeah. That's a really nice one. I use 'gqip' a lot when writing prose in latex, md, etc. One really cool thing is that it respects comments, so it will split long comment lines into multiline comments as necessary.
- pugworthy 7y agoIs it bad that I've used Vi/m since the early 80's, and I still don't know (or really feel like I need to know) a lot of tricks? Sometimes efficiency is not about "tricks"
- sandra101 7y agoMy ex ruined my credit due to his incessant extravagant spending spree, I found myself in a big mess. I talked to a credit repair company and I was told that it would take me non less than a year to fix my credit. I was devastated, that's a very long time which I can't cope with. I looked online and came across Neo's contact, took the bold step of messaging him even though I was skeptical about the whole thing and to my greatest surprise, my credit was repaired 3 working days, my credit was restored from 337 -710. Tbh I was shocked and it didn't cost me too much. I advise you to contact him on (neogonzalezhacks at g mail dot com )for all credit issues, he replies quickly and you can text him on +1 773 688 9662 .
- tasty_freeze 7y agoI use gf (mnemonic: go file) all the time -- it will grab the string under the cursor (the cursor doesn't need to be at the start of it), then attempt to open a file with that name. You can look up the details but it uses a path type mechanism so if the name of the file isn't absolute, it will check the path.
- Shoop 7y agogf is awesome. Great for navigating scripts that run other scripts and also useful for creating links within a personal wiki of markdown files without a plugin like vim-wiki. While I do use a lot of plugins, I find it's a lot better to select plugins that add to vim's editing language (vim-eunuch, vim-surround, vim-vinegar, vim-exchange, vim-angry, vim-sexp-mappings-for-regular-people, vim-commentary) rather than plugins which agglomerate IDE features onto vim (vim-wiki, nerdtree, etc). While I do have a few of these IDE-like plugins (undotree, for example), I think it's better to try plugins which embrace the "vim way" first before investing in a full IDE-like plugin. I don't mean to gatekeep by criticizing IDE-like plugins, but just to say that spending the time to learn normal mode as a true language (verbs, nouns, and all) and using plugins that follow this idea is a worthy investment. Then, add IDE-like plugins to work around the frustrating rough edges of vim once you've milked all that you can out of it.
- AlkurahCepheus 7y agoDon't forget about its twin gx. For example on MacOS gx uses the open command to open a file in the default application. Really helpful when you want to open up a website quickly in your browser or you have the url to an image in a markdown file and want to see it. Helpful trick for relativ paths: https://www.reddit.com/r/vim/comments/7xs8x3/opening_local_relative_paths_with_gx/ https://www.reddit.com/r/vim/comments/7xs8x3/opening_local_r...
- srik 7y agoText objects are crucial to composing vim commands. Vim offers quite a few but honestly, there’s plenty more. I’d recommend using the vim-textobj-user as base to add appealing text objects. Personally, I can’t live without the “entire” text object which allows one to act upon the entire file. Like “indent entire file” etc. https://github.com/kana/vim-textobj-user https://github.com/kana/vim-textobj-user https://github.com/kana/vim-textobj-entire https://github.com/kana/vim-textobj-entire
- sullyj3 7y ago> If you’re constantly tweaking your vimrc, do yourself a favor and add a command for that: > command! Vimrc :vs $MYVIMRC I just use marks for this. Capital letter marks work across files, I use 'I (for init.vim, I use neovim).