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.

Universal configuration monitoring and system of record for IT.

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 using vim from sorted by
Terminal - Commands using vim - 78 results
vim `git diff --name-only`
2015-02-25 11:12:49
User: mbudde
Functions: diff vim
Tags: vim git

For editing files added to the index:

vim `git diff --name-only --cached`

To edit all changed files:

vim `git diff --name-only HEAD`

To edit changed files matching glob:

vim `git diff --name-only -- '*.html'`

If the commands needs to support filenames with whitespace, it gets a bit hacky (see http://superuser.com/questions/336016/invoking-vi-through-find-xargs-breaks-my-terminal-why for the reason):

git diff --name-only -z | xargs -0 bash -c '</dev/tty vim "$@"' x

The last part can be put in a script named e.g. vimargs, and used with any command outputting NUL separated filenames:

git grep -lz foobar | vimargs
vim +"bufdo norm gg=G" +wa +qa FILES
2013-12-06 22:15:24
User: pjump
Functions: vim

The equivalent of opening each file in vim and doing

gg=G:wq . Bufdo makes it faster by obviating the need to start vim for each file separately.

vim test.c && gcc -x c -o a.out test.c && ./a.out && rm a.out test.c
vim $(git diff origin/master --name-only)
vimhtml() { [[ -f "$1" ]] || return 1; vim +'syn on | run! syntax/2html.vim | wq | q' "$1";}
2013-05-12 19:30:51
User: RanyAlbeg
Functions: return vim

``vimhtml somefile.txt`` will open vim for the HTML convertion and close it immediately after its done, leaving you with somefile.html which you can later use in your website or whatever.

vim -R /etc/passwd
vim +143 filename.txt
vim -p `git --porcelain | awk {print $2}`
2013-04-29 21:52:23
User: cnelsonsic
Functions: awk vim
Tags: vim git

Opens all files in the index (modified plus not added yet) in tabs in vim.

vim ~/.inputrc
2013-04-23 02:50:11
User: ekinertac
Functions: vim
Tags: bash search

This allows you to search through your history using the up and down arrows ? i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /".

function :h { vim +":h $1" +'wincmd o' +'nnoremap q :q!<CR>' ;}
2013-04-04 08:12:28
User: Bonster
Functions: vim

simple function i found somewhere to open vim help page from the shell

use :h like you would in vim

vim sftp://[user@]host.domain.tld:[port]/[path/][file]
2013-03-24 01:31:20
User: khayyam
Functions: vim
Tags: vim

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
sudo find / -type f -name config.inc.php -exec vim -p {} +
2013-02-12 11:00:02
User: sinevar
Functions: find sudo vim

Opening several files at once in Vim can be very easy in connection with find command.

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

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 rev-parse --show-toplevel)/.gitignore
2012-11-20 15:22:35
Functions: vim
Tags: git

A little used command, but one I find very useful when needed.

Note: It only works on gitignores in the top level directory.

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

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)
grep -rl string_to_find public_html/css/ | xargs -I '{}' vim +/string_to_find {} -c ":s/string_to_find/string_replaced"
2012-11-07 14:44:51
User: algol
Functions: grep vim xargs

Open all files which have some string go directly to the first line where that string is and run command on it.

Other examples:

Run vim only once with multiple files (and just go to string in the first one):

grep -rl string_to_find public_html/css/ | xargs vim +/string_to_find

Run vim for each file, go to string in every one and run command (to delete line):

grep -rl string_to_find public_html/css/ | xargs -I '{}' vim +/string_to_find {} -c ":delete"
vim -p $(complicated command to list the files you want)
2012-09-28 10:18:30
Functions: command vim
Tags: vim,xargs

see: https://groups.google.com/forum/?fromgroups=#!topic/vim_use/e3Er8x_P8jg

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

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.

file=<filename>;vim ${file} -e -s -c 'runtime! syntax/syntax.vim' -c 'runtime! syntax/2html.vim' -c "w ${file}.html" -c 'q!' -c 'q!' > /dev/null