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 from sorted by
Terminal - Commands tagged vim - 141 results
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
1

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
1

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.

hi! link Comment Ignore
cmdfu(){ local t=~/cmdfu;echo -e "\n# $1 {{{1">>$t;curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext"|sed '1,2d;s/^#.*/& {{{2/g'>$t;vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;rm $t; }
2012-02-21 05:43:16
User: AskApache
Functions: echo rm sed vim
6

Here is the full function (got trunctated), which is much better and works for multiple queries.

function cmdfu () {

local t=~/cmdfu;

until [[ -z $1 ]]; do

echo -e "\n# $1 {{{1" >> $t;

curl -s "commandlinefu.com/commands/matching/$1/`echo -n $1|base64`/plaintext" | sed '1,2d;s/^#.*/& {{{2/g' | tee -a $t > $t.c;

sed -i "s/^# $1 {/# $1 - `grep -c '^#' $t.c` {/" $t;

shift;

done;

vim -u /dev/null -c "set ft=sh fdm=marker fdl=1 noswf" -M $t;

rm $t $t.c

}

Searches commandlinefu for single/multiple queries and displays syntax-highlighted, folded, and numbered results in vim.

ls | view -
2012-01-04 07:18:44
User: lefada
Functions: ls
Tags: vim
0

view does not enable the buffer because it opens in read-only, so it does the same

ls | vim +'set bt=nowrite' -
cmdfu(){ local TCF="/var/tmp/cmdfu"; echo " Searching..."; curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" --silent > "$TCF"; vim -c "set filetype=sh" -RM "$TCF"; rm "$TCF"; }
:w !diff -u % -
:w!
vim -c'highlight Comment ctermfg=white' my.conf
2011-10-21 00:53:03
User: kev
Functions: vim
Tags: vim
-1

you should choose proper color to make comments invisible.

alias busy='rnd_file=$(find /usr/include -type f -size +5k | sort -R | head -n 1) && vim +$((RANDOM%$(wc -l $rnd_file | cut -f1 -d" "))) $rnd_file'
2011-10-16 00:05:59
User: frntn
Functions: alias cut find head sort vim wc
0

Enhancement for the 'busy' command originally posted by busybee : less chars, no escape issue, and most important it exclude small files ( opening a 5 lines file isn't that persuasive I think ;) )

This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim.

:Sex
2011-10-12 17:47:58
User: miguelcnf
5

Open a CLI file explorer by splitting up your screen inside your vim session.

Besides, you probably are never going to forget this one.

command W :execute ':silent w !sudo tee % > /dev/null' | :edit!
2011-10-06 20:37:54
Functions: command tee
Tags: vim sudo tee
7

Calls sudo tee like all the other lines, but also automatically reloads the file.

Optionally you can add

command Wq :execute ':W' | :q

and

command WQ :Wq

to make quitting easier

vim -p `grep -r PATTERN TARGET_DIR | cut -f1 -d: | sort | uniq | xargs echo -n`
:%!sudo tee %
2011-06-17 07:16:23
User: antone
Functions: tee
Tags: vim sudo tee
1

probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)

gvim -u NONE -U NONE