This is pretty nice! My wish for these types of things - can you just put out a big list key combos to browse through? I know the basic concepts of vim but I just want to see how the commands can be strung together. Something like:
- ggVG: highlight the whole file
- jj: escape (this is in my .vimrc, not standard)
- xp: swap letters
- vab: highlight an s-exp (inluding the parens)
- gt: go to the next tab to the right
- gT: go to the next tab to the left
- :tabnew: open a new tab (you can also add a file after that)
- daw: delete a word
- das: deletes the sentence under the cursor
- dap: deletes the paragraph under the cursor
- vas: selects the sentence under the cursor
- ci(: deletes the inner content of a parens, puts you in insert mode
True. People often underestimate the comprehensiveness of vim's :help. Maybe (and this is conjecture) it's because other utilities lack thorough help documentation.
I've collected some of my favorites at http://vimtweets.com, pushed through http://twitter.com/vimtips Monday through Friday. I would judge most of them as "more advanced", for lack of a less judgmental-sounding term, but I hope you'll find them useful, anyway.
thanks a lot. i've just subscribed via RSS. I've been using vi/vim for 21 years, but good tips for intermediate/advanced users are _always_ helpful. Please keep updating your tips.
Before I made a brief foray in the land emacs, I used tabs in VIM rather than leveraging the buffer system (I came from a Windows world, so I was used to tabs in other editors). Then emacs opened my eyes to magic of buffers, and when I returned to VIM (for various reasons), I found buffers to be better than tabs, especially once I first learned the commands, and then updated my .vimrc with a few useful shortcuts, particularly for split views.
I checked out buffers - it's not clear to me why they are better than tabs. It seems like a different UI treatment for basically the same thing. Can you clue me in?
Tabs are all about layout. Look into the windows (and how they fit in with buffers) and you'll start to notice the difference.
Basically, the only case where you should be using tabs is when you have several different arrangements of windows that you want to switch back and forth between.
Please tell me the difference. All I see is that it's more difficult to switch when using buffers instead of tabs (have to press :, have to add ! if it's not saved).
There are multiple plugins to cosmetically improve interaction with buffers, my favourite is minibufexplorer. Using tabs like you might in other editors is fine for a beginner, but once you begin to learn and use more advanced vim features you'll very quickly realize they don't scale.
Also, you should always make sure 'set hidden' is in your '~/.vimrc'. It's a crime that it's not default in my opinion. Takes care of the dumb "have to add ! if it's not saved)." thing.
You only need to know a few basic pure motions, mostly for moving around: h/j/k/l, gg, G, <count>G, 0/^, $, <C-o>/<C-i>, <c-d>/<c-u>
The more important motions are %, f/t and the text-objects (:help for a full description). These are the vim power tools and honestly what I use ~80% of the time.
The f<char> motion moves forward on the same line up through <char>. The t<char> motion (mnemonic: 'til) works the same but doesn't include <char>. Capitalize to go backwards. You can string this together to get all sorts of useful behavior: change startFoo to stopFoo (ctF), work with TSV (ct<tab>), not have to remember W (ct<space>), etc. I tend to overuse it for things like deleting everything but the semicolon on a line so I don't have to retype the semicolon...but you get the point.
The % motion jumps between match pairs (parens, braces, etc), but the important trick with it is that if you're not on a pair, it searches forward till it finds one. This is mostly useful for manipulating function calls and email addresses, e.g. d% deletes a call if you're at the beginning of the function name. Pretty specific use but common use case.
Then there's text objects. You mentioned a couple use cases, but they're more general. There's two transitions, i (diw "delete inner word") and a (daw "delete a word"). Most text objects are marked by delimiters (e.g. parens, xml tags) a includes these i excludes them. There's a lot of ways to put these together, a few:
- ci[ : replace contents of an array access
- da[ : delete the array access
- ci" : replace contents of a string
- dat : delete an XML tag
- =i{ : realign the current block
- zfab : fold sexpr
- gqap : wrap paragraph
What makes the motions I mention here particularly great is that they tend to generalize well when you repeat them with period and don't rely on you pre-counting a certain number of words, lines, or whatnot.
If you're consistently using these motions, you're most of the way there to being a vim expert. The rest is all tricks. You can find your own tricks by noticing when you're repeating yourself or using too many keystrokes. In general, if you're using more than 5-6 keystrokes to do something, there's a shorter way to do it. The shorter way isn't necessarily worth the conceptual overhead, but you'll learn a bit more. You never really stop learning them, but it gets hard to remember once you've been using Vim daily for 5+ years (I'm 10 years in).
The most important plugin for tricks is surround.vim. You should immediately install it and add the following mappings:
nmap s ysi
nmap S ysa
nmap s$ ys$
nmap sv gvs
This lets you operate in 'surround' motions around text objects. E.g. sw( will surround the current word with parens, sp" surrounds the paragraph with quotes. You can change single quotes to double quotes: cs'" and so on. The sv map here surrounds the previous visual selection, I use it when I'm doing multiple wraps: sw'sv[sv(
Random useful tricks (there are thousands of these):
gv selects the previous visual selection. You can V select a number of lines, type colon and replace only in the selected area, then gv to do a < or :retab! or :g/^$/d or something.
Check out :help iskeyword, doing a :set iskeyword+=- is useful in CSS, XML, lisp.
The vim regex engine is screwy. Pretty much everybody knows this (sigh \+), but it's screwy in useful ways too. When you're doing a replacement, \zs and \ze mark the start/end of the match. If, for example you want to insert something at the end of all strings, :%s/"[^"]\+?\zs\ze"/ foo/g. Saves you from having to do capture groups/backrefs and whatnot. Also, the \k character class matches "keywords" (identifiers) for your current language and it's smart \<\k\+\> will not match numbers, for example.
If you have incsearch and hls turned on and are working on a tricky regex replace, it's useful to drop out and start oa normal search with / to see your matches highlighted. When you g...
Haven't looked into it much, yet. On a Windows machine, today, where I did notice that it seems to bork tab-based autocompletion when specifying a filename while saving (^I doesn't trigger autocompletion).
27 comments
[ 3.6 ms ] story [ 77.9 ms ] thread- ggVG: highlight the whole file
- jj: escape (this is in my .vimrc, not standard)
- xp: swap letters
- vab: highlight an s-exp (inluding the parens)
- gt: go to the next tab to the right
- gT: go to the next tab to the left
- :tabnew: open a new tab (you can also add a file after that)
- daw: delete a word
- das: deletes the sentence under the cursor
- dap: deletes the paragraph under the cursor
- vas: selects the sentence under the cursor
- ci(: deletes the inner content of a parens, puts you in insert mode
- q[key][whatever]q: records a macro
- @[key]: plays back the macro
- ZZ: save and close the current window
Then go to your nearest vim and do an
:he navigation
and
:he change.txt
to get a fantastic overview.
1. Amazingly the documentation covers that odd topic!
2. Just knowing where to search is a big enough task a whole chatroom has essentially devoted itself to it.
3. No one thinks it odd that vim is a big enough, esoteric enough space that being a fancy search bot doesn't bother people.
:)
http://www.rayninfo.co.uk/vimtips.html
Basically, the only case where you should be using tabs is when you have several different arrangements of windows that you want to switch back and forth between.
Also, you should always make sure 'set hidden' is in your '~/.vimrc'. It's a crime that it's not default in my opinion. Takes care of the dumb "have to add ! if it's not saved)." thing.
Bind it to a key and switching between buffers (or on-disk files that are not even loaded) becomes as simple as typing a few letters of the filename.
No more scanning of abbreviated tab-labels, no more trial and error cycling through buffers. Highly recommended.
http://img200.imageshack.us/img200/9031/windowsv.png
And, in vim you can type:
andThe more important motions are %, f/t and the text-objects (:help for a full description). These are the vim power tools and honestly what I use ~80% of the time.
The f<char> motion moves forward on the same line up through <char>. The t<char> motion (mnemonic: 'til) works the same but doesn't include <char>. Capitalize to go backwards. You can string this together to get all sorts of useful behavior: change startFoo to stopFoo (ctF), work with TSV (ct<tab>), not have to remember W (ct<space>), etc. I tend to overuse it for things like deleting everything but the semicolon on a line so I don't have to retype the semicolon...but you get the point.
The % motion jumps between match pairs (parens, braces, etc), but the important trick with it is that if you're not on a pair, it searches forward till it finds one. This is mostly useful for manipulating function calls and email addresses, e.g. d% deletes a call if you're at the beginning of the function name. Pretty specific use but common use case.
Then there's text objects. You mentioned a couple use cases, but they're more general. There's two transitions, i (diw "delete inner word") and a (daw "delete a word"). Most text objects are marked by delimiters (e.g. parens, xml tags) a includes these i excludes them. There's a lot of ways to put these together, a few:
- ci[ : replace contents of an array access
- da[ : delete the array access
- ci" : replace contents of a string
- dat : delete an XML tag
- =i{ : realign the current block
- zfab : fold sexpr
- gqap : wrap paragraph
What makes the motions I mention here particularly great is that they tend to generalize well when you repeat them with period and don't rely on you pre-counting a certain number of words, lines, or whatnot.
If you're consistently using these motions, you're most of the way there to being a vim expert. The rest is all tricks. You can find your own tricks by noticing when you're repeating yourself or using too many keystrokes. In general, if you're using more than 5-6 keystrokes to do something, there's a shorter way to do it. The shorter way isn't necessarily worth the conceptual overhead, but you'll learn a bit more. You never really stop learning them, but it gets hard to remember once you've been using Vim daily for 5+ years (I'm 10 years in).
The most important plugin for tricks is surround.vim. You should immediately install it and add the following mappings:
nmap s ysi
nmap S ysa
nmap s$ ys$
nmap sv gvs
This lets you operate in 'surround' motions around text objects. E.g. sw( will surround the current word with parens, sp" surrounds the paragraph with quotes. You can change single quotes to double quotes: cs'" and so on. The sv map here surrounds the previous visual selection, I use it when I'm doing multiple wraps: sw'sv[sv(
Random useful tricks (there are thousands of these):
gv selects the previous visual selection. You can V select a number of lines, type colon and replace only in the selected area, then gv to do a < or :retab! or :g/^$/d or something.
Check out :help iskeyword, doing a :set iskeyword+=- is useful in CSS, XML, lisp.
The vim regex engine is screwy. Pretty much everybody knows this (sigh \+), but it's screwy in useful ways too. When you're doing a replacement, \zs and \ze mark the start/end of the match. If, for example you want to insert something at the end of all strings, :%s/"[^"]\+?\zs\ze"/ foo/g. Saves you from having to do capture groups/backrefs and whatnot. Also, the \k character class matches "keywords" (identifiers) for your current language and it's smart \<\k\+\> will not match numbers, for example.
If you have incsearch and hls turned on and are working on a tricky regex replace, it's useful to drop out and start oa normal search with / to see your matches highlighted. When you g...
Vim offers strong file encryption with Blowfish
http://blogs.techrepublic.com.com/security/?p=4870
Haven't looked into it much, yet. On a Windows machine, today, where I did notice that it seems to bork tab-based autocompletion when specifying a filename while saving (^I doesn't trigger autocompletion).
EDIT: Credit due to:
http://www.reddit.com/r/vim/comments/ey0ma/vim_offers_strong...
https://groups.google.com/group/vim_announce/browse_thread/t...
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------●
●------ http://goo.gl/l5v0b ------● ●---------------------------------------● Happy New Year◎,◎appy shopping
Highlights that made me uneasy:
- Often I'd find myself with an accidentally closed gvim, having to open up working projects all over again.
- Overview of source changes with more control: Changes in n files pops up n vimdiff windows.