Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

121–130 of 249 posts

Re: Vim Anti-Patterns

#121
post #29

Earlier quoted context omitted.

I 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.

I decided one year that I would force myself (a vi die-hard) to use emacs for everything for an entire year, to see if I ever got used to it. One thing that never stopped driving me crazy was that there's no efficient way to duplicate a line like yyp in vim. The closest I could ever get in emacs was ctrl+k k ctrl+y ctrl+y (that is, delete the line and then paste it back twice). Looking online for a solution leads me…

...Which is actually quite simple. Here's my function for doing that that I wrote just now:

  (defun duplicate-line 
    (interactive)
    (kill-whole-line)
    (yank)
    (yank))
Five lines, and it took me all of ten minutes to write, including looking up the names of all the functions. Of course, there's probably a better way to do this, but I don't know what it is. Now all you have to do is bind it to a key.

Or, of course, you could just record a keyboard macro to do it instead.

Re: Vim Anti-Patterns

#122

I 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…

I switched to Spacemacs a few months ago and didn't look back since. Its basically Emacs+Vim+Steroids+More. Just the leader key and layers alone are incredibly powerful concepts Spacemacs brings on top of Emacs/Vim :)

I can't stand Spacemacs. It's too complicated. I'd rather write my own config, thanks.

Re: Vim Anti-Patterns

#123

I 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-n…

I have two tricks for better movement, add the following to your .vimrc: " for scrolling up and down quickly nnoremap J 7j nnoremap K 7k vnoremap J 7j vnoremap K 7k and the second (which requires a third party plugin): " easymotion allows us to jump to all places that could have been reached by " (w in this case), and the bd- indicates we want to search backwards too. nmap f (easymotion-bd-w) vmap f (easymotion-bd-w)…

Have you tried using :relativenumber? You still have to type eg 12j or whatever but at least vim does the counting for you. If so, can you share why you like easymotion more? Thanks!

Re: Vim Anti-Patterns

#124

Earlier quoted context omitted.

Unfortunately I'm using windows for my main os, and emacs does not work as smoothly on windows as it does on mac/linux. But now you got a beefy framework with all the bells and whistles from spacemacs, I really like to keep my plugins lean and specific to my needs. also now you need to worry about layers being maintained in spacemacs, which can be a good/bad thing. I have tried it out loved the ease of it, but not th…

I've been using emacs on Windows at work for the last few years (at home I use macOS (nee OS X) and linux). What issues have you found, in particular, that were hard to adapt to with emacs on Windows?

I was referring specifically to Spacemacs, vanilla Emacs I don't have any issues aside from missing a few features such as ssh on a clean machine (I had to install plink from putty to use with tramp but spacemacs would have the same issue). Everything else I use mainly for golang or front end and it works really well, I don't crash or hang on anything including autocomplete, eldoc, godoc. I would sometimes freeze in Spacemacs for unknown reasons on start up or even opening a .go or .php file. I didn't feel the need to learn the ecosystem of Spacemacs for the small benefit of layers. I just install EVIL and configured it as I wanted and learned the packages I found useful from Spacemacs and just installed them from Melpa.

I found that on windows Emacs feels sluggish, load times (first open + os files or Ctrl+r+l, scrolling), GUI update on scroll, colors and overall speed of things like shell/auto-complete work 'faster' in mac or Ubuntu/Arch. I don't have any benchmarks to prove it but I do notice a difference between the environments I work on and the machines are relatively close in hardware specs.

as a side note, I did try to use Emacs as a SQL client but it becomes really difficult really quickly, for db development SSMS/VS, or pgAdmin would be better. Unfortunately I was still unsatisfied with those tools until I found Data Grip from JetBrains, it's worth every penny and has an a-okay vim plugin that allows me to work on databases a lot easier. Sadly there are limits to what I can develop inside Emacs productively.

Re: Vim Anti-Patterns

#125

I 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-n…

I have two tricks for better movement, add the following to your .vimrc: " for scrolling up and down quickly nnoremap J 7j nnoremap K 7k vnoremap J 7j vnoremap K 7k and the second (which requires a third party plugin): " easymotion allows us to jump to all places that could have been reached by " (w in this case), and the bd- indicates we want to search backwards too. nmap f (easymotion-bd-w) vmap f (easymotion-bd-w)…

For better scrolling:

    nmap  3j3
    nmap  3k3
(replace "3" with whatever number you like best). These shortcuts will enable you to scroll the text, while keeping the cursor fixed. It's similar to web page scrolling. It helpls you type in code while maintaining an overview on what's going on below and above it. Add these to your .vimrc and use them for some time. You'll thank me later.

Re: Vim Anti-Patterns

#126
post #33

I 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…

> feel a bit of strain on the whole holding Ctrl+p others don't seem to like this, but i've found the following global key swaps effective swap ctrl->alt LCtrl::LAlt RCtrl::RAlt swap capslock->alt Capslock::Alt this enables you to hit "ctrl" with your thumb (next to the spacebar), and capslock becomes the new "alt". so no more reaching for that hard to reach LCtrl key with your pinky.

Nah, swap Ctrl with Capslock. Alt is by far less commonly used. I swapped alt with RShift for a while, but Alt is fine as Alt really.

Re: Vim Anti-Patterns

#127

Earlier quoted context omitted.

Emacs 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.

Best of both worlds: http://spacemacs.org/ Modal editing is far superior, once you learn it. Emacs runtime and configurability thanks to Elisp is far superior to VimL. So just use Spacemacs. ^^

I can't stand Spacemacs: it's far too complicated, and I'd rather write my own configs, thanks. Also, I could never get used to Vim-style modal bindings.

Re: Vim Anti-Patterns

#128
post #26

These 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…

Thank you! you just sent me down a rabbit hole of figuring buffers out, but it was totally worth it. That second link is especially nice.

Re: Vim Anti-Patterns

#129

Not 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 ama…

Couldn't agree more. I just recently switched over to Spacemacs after having used Vim for over 5 years, and the transition has been so smooth. With Spacemacs, everything just works, whereas with Vim, I had constant struggles. Of course all of the smoothness can be pretty much attributed to Spacemacs. Looking forward to learning Elisp :P

Re: Vim Anti-Patterns

#130

Earlier quoted context omitted.

Yeah, scripting a huge focus in emacs: they say it's a scripting environment that happens to have a text editor embedded in it. I don't know who "they" are, but they're quite perceptive. Some lisp experience (especially CL) can help with learning elisp, but it's entirely possible to do so without it. The process of learning emacs is roughly this: -Launch emacs -Run through the tutorial -Learn the shortcuts and gain g…

hehe - I made it to step 4, anyway. The only thing that sort of scared me off of customizing emacs is that if I, say, SSH into a remote box or go to another co-workers computer, my customizations won't be there. That's why I do my best to stick with "out of the box" vim defaults (and vi defaults if possible): I know they'll always be there, wherever vi is.

Well, that's the drawback to emacs. It's also why most people don't change the default keybindings too much: some functionality may be missing, but muscle memory won't betray me if I ssh into a fresh emacs setup.

However, there are some ways to combat this.

Firstly, you can keep your .emacs.d on github, and pull it down to whatever machine you're working on. Indeed, this is what many emacs users advocate.

Secondly, many emacs users will ask: Why are you launching emacs over SSH at all? Instead, use TRAMP or SSHFS, bring up the folders under dired if you need to see the folders, and edit the files with your local emacs.

You can become compotent in emacs without customizing it, but the customization is a big part of why emacs is great.

Post reply on HN