example .vimrc
:highlight to see the highlights
Code indent problem when pasting from system to vim
1. use registers
2. :set paste and :set nopaste
Edit multiple files
use buffers:
:edit filename (:e) to open another file
:ls to list all the buffers
:bn switch to the next buffer
:b# switch to the # buffer, # is the buffer number
:b filename switch to filename
:bd delete current buffer
:bd# delete buffer #
use windows:
Ctrl-W s to split the current window horizontallyCtrl-W v to split the current window vertically.
:split and :vertical split (:sp and :vs)
Ctrl-W w to switch between open windows, and
Ctrl-W h (or j or k or l) to navigate through open windows.
Ctrl-W c to close the current window, and
Ctrl-W o to close all windows except the current one.
use tabs:
:tabe filename to open a filevim -p a/*.php opens the same files in tabs
gt and gT switch tabs back and forth
:q closes only the current tab
:qa closes everything and exits
:tabo closes everything but the current tab
Cursor moving
escshift-A moves cursor to the end of line and change to insert mode
Move cursor left one char in insert mode
I would argue that Control-ol (thats a lowercase L) is faster than escshift-A and the right arrow key. Control-o lets you execute one normal mode keystroke from insert mode.
Case insensitive search
You need to use the \c escape sequence. So:/\ccopyright
To do the inverse (case sensitive matching), use \C instead.
:set ic
case sensitive
case sensitive
:set noic
https://stackoverflow.com/questions/1737163/traversing-text-in-insert-mode
https://stackoverflow.com/questions/1737163/traversing-text-in-insert-mode
The right way is to press Esc, go where you want to do a small correction, fix it, go back and keep editing. It is effective because Vim has much more movements than usual character forward/backward/up/down. After you learn more of them, this will happen to be more productive.
Here's a couple of use-cases:
- you accidentally typed "accifentally". No problem, the sequence EscFfrdA will correct the mistake and bring you back where you've been editing it. Ff movement will bring you back to the first encountered "f" character. Compare with Ctrl+<-->->->->deldEnd, that does virtually the same in a casual editor, but takes more keystrokes, makes you move your hand out of alphanumeric space of the keyboard.
- you accidentally typed "you accidentally typed", but want to correct it to "you intentionally typed". Then Esc2bcw will erase the word you want to fix and bring you to insert mode, so you can immediately retype it. To get back to editing, just press A instead of End, to reach which you should move your hand
- you accidentally typed "mouse" instead of "mice". No problem - the good old Ctrl+W will delete the previous word without going out from insert mode. And it happens to be much faster to erase small word than to fix errors in it. I'm so used to it that I had closed the browser page when I was typing this message...
- repetition count is largely underused. Before making a movement, you can type a number; and the movement will be repeated this number of times. For example, 15h will bring you 15 characters back and 4j will scroll you 4 lines down. Start using them and you'll get used soon and find out that pressing 10 times <- key is less fast than iterative approach to moving cursor, when you type 12h, notice that you made a mistake and immediately correct yourself with ll.
No comments:
Post a Comment