Live data from Hacker News

Vim Anti-Patterns

sanctum.geek.nz

181–190 of 249 posts

Re: Vim Anti-Patterns

#181

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've found it helpful to use relative numbering in normal mode and switch to absolute numbering in insert mode:

  set relativenumber nonumber
  autocmd InsertEnter * :set norelativenumber number
  autocmd InsertLeave * :set relativenumber  nonumber
IIRC this tip was from the Practical Vim book

Re: Vim Anti-Patterns

#182
I'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.

Re: Vim Anti-Patterns

#183
post #145

Movement 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?

Pretty 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

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

Re: Vim Anti-Patterns

#184

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

I sort of agree, but still ended up in the opposite corner. I use a keyboard which has no arrow keys and instead use -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.

Re: Vim Anti-Patterns

#185
post #178

Earlier quoted context omitted.

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

Ahg, no I couldn't do that, I need to keep J as Join lines. That's pretty useful to me. Kinda the inverse of gq.

Ah, I bound join lines to :join since I don't use it that often. I still encourage you to try binding something to 7j (or whatever number of j's feels right). One of the best shortcuts of my life.

Re: Vim Anti-Patterns

#186
post #104

Earlier quoted context omitted.

I suggest remapping Caps Lock to CTRL if you haven't remapped it already.

Plug for Karabiner on OS X, which lets you use capslock as a control if you press it with another key, and escape if its released on its own. It has ruined me for other computers that don't have this set up. There's also a way to do it under Linux, but I can't remember what the package is that lets you do that.

You're thinking about xcape: https://github.com/alols/xcape.

FYI, Karabiner is incompatible with MacOS Sierra. There's a project (Karabiner-Elements) to replace its (and Seil's) functionality, but I don't believe it has feature parity yet: https://github.com/tekezo/Karabiner-Elements

Re: Vim Anti-Patterns

#187
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…

Yeah, I dunno. I see your point and will certainly explore it, but I easily use tabs for both. I mostly use marks to skip around in a file and tabs for opening different files. Why? Because I can see them. The drawback with buffers (and too many marks and registers etc.) is that it's easy to lose track of where things are. So tabs make buffers easy- you can glance up and see where the file that you need is.

The numbering system is a little screwy (starting at 1 instead of 0) though.

Re: Vim Anti-Patterns

#188

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 can't remember or find what the "slow O" is about, but it's definitely real; I think I read about it in relation to it being fixed in v8.

Re: Vim Anti-Patterns

#189
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…

Well, I've been using vi and it's brethren since about 2002 and I've pretty much always used the arrow keys; after some point it becomes muscle memory...

I never really understood what the problem with this was; I rarely actually use them (esc|capslock /str,ctrl+f|b etc) is usually how I move around and if I'm wanting to move a few chars my little finger is not moving very far (at least, on apple keyboards)...

Is this heathen territory? ;)

Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux? My workflow seems to be more multiple vim's and shells inside tmux (I have ` as my "control key" in tmux, which is right beside z on my keyboard) which always feels quicker to me than ctrl+ww or ctrl+w; and I really like the "zoom" functionality there...

hitting `` to switch between windows in tmux is really nice, too.. :}

Re: Vim Anti-Patterns

#190

This 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 le…

Either way, mapping the arrow keys to seems wasteful. In normal mode I map up/down to :cprevious/:cnext and left/right to :colder/:cnewer, which makes error list navigation effortless. Some other good targets are the buffer, tag and location lists (with a little work you could make them context-aware too). I don't remap the arrow keys in insert mode though, it'd be annoying to have to exit insert mode only to move the cursor a few characters.
Post reply on HN