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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands tagged vim from sorted by
Terminal - Commands tagged vim - 141 results
function v { if [ -z $1 ]; then vim; else vim *$1*; fi }
2009-04-11 23:06:43
User: kFiddle
Functions: vim
Tags: vim vi function

Reduce the number of keystrokes it takes to open a file in vim. First of all, you just need to type "v", which is less than half the number of characters (!), and second-of-all, you only need to enter a substring of the file you want to open. For example, if you want to open the file, homework.txt, then type "v hom" to open it. Good tip is to use the lowest unique substring, otherwise you'll open multiple files in different buffers (which is sometimes desirable). Use Ctrl-^ to switch between buffers.

info --vi-keys
2009-04-11 22:10:08
User: kFiddle
Functions: info

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.

2009-04-08 21:25:06
User: pyrho
Tags: vim

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


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

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.

2009-03-28 02:28:19
User: acirulli
Tags: vim vi

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

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.

2009-03-02 23:58:45
User: leonza99
Tags: vim

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

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
2009-03-02 03:01:13
User: leonza99
Tags: vim

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

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

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

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

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

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

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