Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged vim from sorted by
Terminal - Commands tagged vim - 140 results
info --vi-keys
2009-04-11 22:10:08
User: kFiddle
Functions: info
8

Info has some of the worst keybindings I've ever seen. Being a vim user, I attribute that to emacs influence. Use the --vi-keys option to use some of the vi keybindings, although this won't change all the keybindings. Use the "infokey" program to have more control over info keybindings.

:<C-R><C-W>
2009-04-08 21:25:06
User: pyrho
Tags: vim
31

Very handy to bring the word currently under the cursor into a :s command in Vim.

Example:

If the cursor was on the word "eggs":

:s/ ==> :s/eggs

sudo vi /etc/fstab; Go//smb-share/gino /mnt/place smbfs defaults,username=gino,password=pass 0 0<esc>:wq; mount //smb-share/gino
2009-04-02 16:04:35
User: GinoMan2440
Functions: mount sudo vi
4

the middle command between the ; and ; is the vi commands that insert that line into the last line of the file, the esc with the carets is literally hitting the escape key, you have to have the smbfs package installed to do it, I use it to access my iTunes music on my mac from my linux PC's with amarok so I can play the music anywhere in the house. among other things, it allows you to access the files on that share from your computer anytime you're on that network.

:1,$d
2009-03-28 02:28:19
User: acirulli
Tags: vim vi
3

Within vi allow to empty a text file in one shot

vimdiff foo.c <(bzr cat -r revno:-2 foo.c)
vifind() { vi `find . -name "$1"` }
vi -R filename
2009-03-04 06:56:40
User: haivu
Functions: vi
Tags: vim
-3

The -R flag prevents you from making changes to a file, useful when you only want to view the file. This command is nicer than the 'more' or 'less' commands because for source codes, vi shows syntax highlight.

:g!/\S/d
2009-03-02 23:58:45
User: leonza99
Tags: vim
16

This command delete all the empty lines (include the lines with space) from a file.

g = global command

\S = non-whitespace character; !\S the opposite

d = delete a range

:n,m w newfile.txt
2009-03-02 19:40:34
User: milmazz
Tags: vim perl
8

On command mode in Vim you can save parts of the current buffer in another file.

* The 'n' value represents the first line of the new file.

* The 'm' value represents the last line of the new file.

* newfile.txt is the newfile.

The results are similar to this command in perl:

perl -ne 'print if n..m' in.sql > out.sql
:%s/old/new/g
2009-03-02 03:01:13
User: leonza99
Tags: vim
2

Replace all ocurrences in the file.

The g option is to replace more than one occurrence in the same line. Whitout the g option, it only replace the first occurrence in the line.

vim -p file1 file2 ...
2009-02-27 16:43:59
User: haivu
Functions: vim
Tags: vim
8

Edit the files, each in a separate tab. use gT and gt to move to the left- and right-tab, respectively. to add another tab while editing, type ':tabe filename'

:mksession! <filename>
2009-02-26 05:03:07
User: neutral
Tags: vim
26

Creates a full snapshot of your current vim session, including tabs, open buffers, cursor positions, everything. Can be resumed with vim -S . Useful for those times when you HAVE to close vim, but you don't want to lose all your hard-opened buffers and windows. The ! will cause vim to overwrite the file if it already exists. It is not necessary, but useful if you frequently save to the same file (like session.vim or something).

:split <file>
2009-02-25 23:41:22
User: raphink
4

You can then switch from a file to another with ^W^W

:r !command
2009-02-25 15:49:08
User: sud0er
Tags: vim
13

This will append the output of "command" to whatever file you're currently editing in vim. Who else has good vim tricks? :)

tail -1000 /some/file | vim -
2009-02-25 11:43:27
User: root
Functions: tail vim
17

The hyphen tells vim to open from STDOUT - saves having to create temporary files.