News for hackers. Stuff that matters.
Re:Vim Anti-Patterns (2012) by aboutruby on Sunday March 17, 2019 @04:35PM (#19416414)
> Moving one line at a time

I either go down with arrows (I know it's controversial), beginning of file with :1, end of file with G, line number with :[line number] or search with /. I usually don't have large files so this works very well (and I almost exclusively go by line number on large files).

> Moving one character at a time

I use ^ for beginning of line, $ for end of line, e to move quickly in a line

> Searching for the word under the cursor

Nice, didn't know about */#, I just type what I'm searching, gonna use that.

> Deleting, then inserting

Insert mode is fine.

> Using the arrow keys

I use the arrow keys, and I don't care about all the arrow-key shamers out there.

> Moving in insert mode

I use insert mode only while editing (makes sense). I don't get the point of this paragraph.

> Moving to Escape

I'm fine with escape key.

> Moving to the start or end of the line, then inserting

I much prefer just going into insert mode.

> Entering insert mode, then opening a new line

I also use o quite often (as it just goes into insert mode).

> Entering insert mode to delete text

Yes, I delete with dd, de, etc. (. is also useful for that), deleting in insert mode is painful for more than one character.

> Repeating commands or searches

Didn't know about q: and q/, pretty useful, nice.

> Repeating substitutions

I use %s/for/far/g or %s/for/far/, or for a few lines, I select them (shift-v) (visual mode) then : (which auto-sets it to :'<,'>) then :'<,'>s/for/far/ for instance.

Anyway, been using vim for ~5 years with a pretty light .vimrc and one thing I would recommend is bogado/file-line plugin which lets you open a file at a line, e.g. vim app/models/user.rb:48

My vimrc if anyone is curious: https://gist.github.com/localhostdotdev/aa25d1c81f3f3b67ac35...

Re:Vim Anti-Patterns (2012) by therealdrag0 on Monday March 18, 2019 @03:28PM (#19424315)
> Moving in insert mode

He doesn't give the most relevant shortcut for this situation! While in insert-mode, "ctrl+o" will allow you to run 1 movement command and leave you back in insert! I've found this to be amazing once I got the hang of it.

Re:Vim Anti-Patterns (2012) by StreamBright on Sunday March 17, 2019 @05:11PM (#19416642)
Same here. I cannot take my vimrc everywhere I go so keep it on the minimum.
Re:Vim Anti-Patterns (2012) by vram22 on Sunday March 17, 2019 @05:11PM (#19416643)
>I either go down with arrows (I know it's controversial)

Probably not that controversial any more. It used to be (although I would use the word inadvisable instead), because dumb terminals like VT-100 and some emulators of them, would emit escape sequences when arrow keys were pressed. Since an escape sequence starts with the Escape key and then has some other keys following it, it would result in your going from input mode (if you happened to be in it) back into command mode (due to the Esc key) and then the remaining keys in the sequence would be likely interpreted as vim commands (since many letters of the alphabet are vim commands), so any unwanted modification could happen to the file you were editing, maybe without your noticing. Then if you saved the file without knowing that there was some such inadvertent change, you could have lost or mangled some of your content.

Nowadays common emulators that I have come across, don't have that issue, so arrow key usage should be fine.

The other reason why people may comment if you use arrow keys for movement in vim, is because if you instead use the default and recommended hjkl keys (for left, down, up, right respectively), your fingers stay on the home row (on a QWERTY keyboard), which may make for less finger / hand movement, so less strain.

>beginning of file with :1, end of file with G, line number with :[line number]

You can use 1G for beginning of file, G for end of file, and nG for going to line n, without having to hit Enter after some of those commands as you have to with the :[line number] method, thereby potentially saving one keystroke many times per edit session.

>I use ^ for beginning of line, $ for end of line, e to move quickly in a line

0 goes to the real start of the line, ^ goes to the first non-blank character on the line.

>I use the arrow keys, and I don't care about all the arrow-key shamers out there.

Good on you.

>I also use o quite often (as it just goes into insert mode).

O (a capital O) Opens a line above the cursor, o (small o) opens a line below it.

> Repeating substitutions

>one thing I would recommend is bogado/file-line plugin which lets you open a file at a line, e.g. vim app/models/user.rb:48

  vi(m) +n filename
will open filename at line n, for both vi and vim, so I'm not sure why that plugin is needed, unless it does other stuff too.

And:

vi(m) +/pattern filename will open filename at the first occurrence of pattern in filename.

Re:Vim Anti-Patterns (2012) by yuubi on Sunday March 17, 2019 @09:35PM (#19418050)
It seems to be more a function of the vi-like in use. Old-school vi behaved that way, but (at least some) vim interprets ESC [ A close together as a movement command.
Re:Vim Anti-Patterns (2012) by aboutruby on Sunday March 17, 2019 @05:21PM (#19416706)
Not sure if you are directing this comment at me, but I know most of these already. Didn't know about the older terminal emulator issues with arrow keys though.
Re:Vim Anti-Patterns (2012) by vram22 on Sunday March 17, 2019 @05:35PM (#19416789)
It was partly for you and partly for other readers. It seemed to me that, based on your comment, you may not have known about some of the points I mentioned, like use of G with number modifiers instead of the "colon then <number> then Enter" method. Maybe I should have been more specific, and put the more general points in a separate comment. Also, I guess you may prefer to use the colon method even though the G method is one key less. I know I do at times, too :)
Re:Vim Anti-Patterns (2012) by vram22 on Sunday March 17, 2019 @05:41PM (#19416821)
>Didn't know about the older terminal emulator issues with arrow keys though.

NP. Yes, I've found that some people do not know about those issues, which is why I mention them (and also, like others, recommend the use of the hjkl keys) in my quickstart tutorial that I mentioned elsewhere in this thread:

https://gumroad.com/l/vi_quick