I've used vim for years and feel fairly proficient with it. However, recently, I've been working on a server with a 520ms ping time (Sydney to South Africa). This greatly increases my need to use vim more effectively. What can I do to help learn the shortcuts which thus far I've never learned?
To use vim more effectively, I would concentrate on learning more of the specialized movement commands (parens to move by sentence, braces to move by paragraphs). They can be combined with the editing commands (delete, change, etc.) once you are familiar with them. Also, learn the ‘a’ and ‘i’ combinations for selecting (and applying commands to) objects around the cursor (e.g.
das to delete the sentence that the cursor is in: compare to
(d), which has three Shift toggles). Learn to apply counts for larger movements (e.g.
c2w to change the next two words,
d2as to delete the sentence the cursor is in and the next one). Use marks to jump to frequently used spots.
I forgot one of my favorite movement commands:
T move forward or backwards (lowercase or uppercase, respectively) to the next or just before the next (f or t, respectively) character you type:
f* moves to to the next
* to the right,
T( moves just to the right of the next open parenthesis to the left (swap left and right for right-to-left configurations).
For repetitive edits, use the macro recording function
q to record and
@ to playback sequences of the same commands.
Use registers instead of copy and paste, it will save a round-trip (since macros are stored in registers, you can use the register store/retrieve commands to fixup errors in the macro without re-recording).
:%s/…/…/g command to make global replacements/deletions.
And if you still can not get it to feel comfortable, you might be able to make edits via the netrw plugin:
As akira notes below, this lets you run Vim on your local machine where latency is not a problem. When you edit a remote file, Vim copies it to your local machine. When you save, Vim copies it back to the remote machine. It supports many protocols (WebDAV, HTTP (read-only), FTP, SSH (scp, sftp), rsync).
Well, Vi was written for slow modem links, so Vi/Vim are possibly the best tools to use in this situation.
What I would suggest is to consider anything that you find yourself repeating, and write macros to avoid the repetition.
Use :map liberally, and (because it's Vim), the 'q' macro recording feature (
Make use of repeat counts (as you have identified) and use motions to navigate (like searching and going directly to line numbers) rather than banging on h/j/k/l.
So things like
5d to go down 5 lines,
} to reach the next empty line, Ctrl-I and Ctrl-O to go back/forward through recently-used positions in the text (
Also consider downloading the file(s) and editing locally, then uploading back to the server.
as others already wrote, vim was designed specifically with slow connections in mind, so you just need to learn to use it more effectively. you need to learn ( and know the difference between) a/A, f/t F/T, i/I, ^, $, o/O, p/P, d/D etc. they are all important and can save you quite a lot of movements.
But the biggest problem from my experience is psychological. you known that eventually it will be faster, but right now its faster (and more importantly easier on the brain :) just to use the cursor keys :).
What I did to learn effective vim is to "punish myself" every time I catch myself doing something inefficiently, by going back and re-doing it the right way anyway.
so for example if you just "caught" yourself moving 10 lines down with the cursor keys go back and then use smth like "10". or more importantly almost never using the horizontal arrow keys, use T,t,F,f,/,? instead. and "punish" yourself by redoing it again. you will start to do the right thing in no time.
oh, and another thing to watch is the visual selection mode. 99% its not needed as the same can be done differently.
Have you gone over the vim introductory tutorial? After that I highly suggest grabbing a vim cheat-sheet and making sure you at least know what each item in the cheat-sheet is referring to. Learn about using regular expressions in search and replace. Learn about recording and executing macros. Learn about visual mode and how you can "pipe" your selection into external commands and read data in from external command.
There is also an option called 'scrolljump' that controls how many lines to scroll when your cursor moves off screen. This can help reduce how much of the screen needs to be redrawn.
But the netrw plugin as mentioned by Chris Johnsen is an excellent solution, I used it many times to do development over incredibly slow and unreliable connections.