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
vim anything.tar
vim -R /etc/passwd
vim +143 filename.txt
vim sftp://[user@]host.domain.tld:[port]/[path/][file]
2013-03-24 01:31:20
User: khayyam
Functions: vim
Tags: vim
0

vim can open ssh/sftp and ftp connections for file editing using 'netrw'. If no path or file is provided vim opens the directory as a filelist.

See: :help netrw.

vim -O file1 file2
:%!xxd
2013-01-11 21:09:47
User: b1067606
Tags: vim
1

return to normal mode from hex mode

:%!xxd -r

. (in NORMAL MODE)
2013-01-08 18:32:57
User: Zulu
Tags: vim
-3

Paste what you previously wrote in INSERT MODE, for example:

1. Write 'foo' in INSERT MODE

2. Return to NORMAL MODE

3. Press "." and it will paste 'foo'

:vimgrep pattern %
2012-12-30 06:51:10
User: Sebasg
Tags: vim grep
1

Will search for the given pattern and build a list of occurrences.

Then you can use :copen and :cclose to toggle the list.

When browsing the list, ENTER will take you to that line in the file.

vim `git status --porcelain | sed -ne 's/^ M //p'`
2012-11-21 06:31:46
User: sandre
Functions: sed vim
Tags: vim git
1

The option --porcelain makes the output of git easier to parse.

This one-liner may not work if there is a space in the modified file name.

vim `git status | grep modified | awk '{print $3}'`
2012-11-19 09:48:46
User: TetsuyO
Functions: awk grep vim
Tags: vim git
0

This oneliner gets all the 'modified' files in your git repository, and opens all of them in vim.

Very handy when you're starting to work in the morning and you simply want to review your modified files before committing them.

Maybe there are better ways to do that (and maybe integrated in vim and/or git, who knows), but I found quicker to do this oneliner.

vim $(grep [REGULAR_EXPRESSION] -R * | cut -d":" -f1 | uniq)
CTRL + A ( in normal mode )
vim -o file1 file2
vim -O file1 file2
vim file1 file2
vim -O file1 file2
vim -d '+diffoff!' file1 file2
2012-08-30 07:51:41
User: greggster
Functions: vim
2

Use vim's diff mode to edit two or more files in one window. The '+diffoff!' turns off diff highlighting when the session is started.

Use ctrl+w + ctrl+w to switch between windows.

vimdiff file1 file2
:!bash
2012-08-13 17:13:53
User: CLIxBOBxBOM
Tags: bash vim vi
2

Helps when I'm editing a script and want to double check some commands without having to exit out of vi multiple times or having to use another terminal session.

alias ':q'='exit'; alias ':e'='vim';
2012-08-12 12:35:10
User: expelledboy
Functions: alias
Tags: vim alias
-2

This was me just succumbing to the habits, but now I rarely use quit or vim directly, so beware! :)

d%
2012-07-12 18:13:43
Tags: vim
0

Put the cursor on either curly braces ( {, } ). Then press d%

The d is delete command, and % is movement command that move the cursor to another matching parentheses (or curly braces in this case). This action will delete every character that was on the way of the movement (from the first curly braces to the second).

d + %
2012-07-12 01:04:40
User: Zulu
Tags: vim
2

We have for example :

func () {

echo FOO

echo BAR

}

Place the cursor under a bracket and press d + %.

It will cut everything inside and the brackets.

It let : func ()

You can copy text with y + %

''
2012-04-28 18:44:34
User: philluminati
Tags: vim movement
0

You're perhaps editing a line, or reading a certain line of code, you use page up and down or move through the file and now you wish to return to the last position the cursor was at. '' will get you there.

vim some-archive.tar.gz
2012-04-20 02:37:28
User: ktonga
Functions: vim
5

If you vim a compressed file it will list all archive content, then you can pickup any of them for editing and saving. There you have the modified archive without any extra step. It supports many file types such as tar.gz, tgz, zip, etc.