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 using vim from sorted by
Terminal - Commands using vim - 77 results
vim +"bufdo norm gg=G" +wa +qa FILES
2013-12-06 22:15:24
User: pjump
Functions: vim
0

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
4

``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
0

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
-8

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
-1

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

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
5

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
0

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
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)
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
-1

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
0

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
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.

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
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.