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

Commands tagged vim from sorted by
Terminal - Commands tagged vim - 130 results
g~w
2009-07-25 07:13:40
User: bigeasy
Functions: g++
Tags: vim
5

In edit mode, toggle the case of a single word under the cursor in vim.

vim $(grep test *)
2009-07-15 10:15:04
User: goatboy
Functions: grep test vim
Tags: vim grep
4

I often use "vim -p" to open in tabs rather than buffers.

:let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1
ga
:!start c:\progra~1\Opera\opera.exe http://www.commandlinefu.com
:r! echo %
2009-06-19 12:17:28
User: miccaman
Functions: echo
Tags: vim
1

insert filename

Normal mode: "%p

Insert mode: %

:source ~/.vimrc
:set nomore :argdo %s/foo/bar/g | update
svn diff <file> | vim -R -
2009-06-13 22:00:49
User: caiosba
Functions: diff vim
Tags: svn vim diff color
14

Simple way to achieve a colored SVN diff

%
2009-05-21 15:02:39
User: haivu
Tags: vim vi
6

This is a simple command for jumping to the matching brace, square bracket, or parentheses. For example, it can take you from the beginning of a function to the end with one key stroke. To delete everything between the pairs of {}, [], or (), issue the command:

d%

To replace text between pairs of braces, brackets, or parentheses, issue the command:

c%

You can also use this command to find out if an opening brace has been properly closed.

vim `which <scriptname>`
2009-05-08 17:21:47
User: bunedoggle
Functions: vim
Tags: vim which script
1

Often I need to edit a bash or perl script I've written. I know it's in my path but I don't feel like typing the whole path (or I don't remember the path).

vim -x <FILENAME>
2009-05-05 23:24:17
User: denzuko
Functions: vim
55

While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format.

For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption

vim ~/.purple/pounces.xml
2009-04-28 19:11:39
Functions: vim
Tags: vim pidgin
1

So you keep getting buzzes sounding from pidgin but you can't remember which buddy pounce is causing the beep. Well, cat/edit the ~/.purple/pounces and find out!

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
1

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
6

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
30

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
17

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.