Catches .swp, .swo, .swn, etc. If you have access to lsof, it'll give you more compressed output and show you the associated terminals (e.g., pts/5, which you could then use 'w' to figure out where it's originating from): lsof | grep '\.sw.$' If you have swp files turned off, you can do something like: ps x | grep '[g,v]im', but it won't tell you about files open in buffers, via :e [file]. Show Sample Output
This will skip all initializations. Especially useful when your ~/.vimrc has something wrong.
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.
This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:
svd() { vimdiff <(svn cat "$1") "$1"; }
This command searches the current directory, and all of its subdirs, for files that have the string "foo" in their filename (foo.c, two-foo.txt, index-FOO-bar.php, etc), and opens them in Vim. It ignores any hidden .svn directories. Change -iname to -name if you want to do case-sensitive matches. Files open in buffers by default, so to verify that the correct files were opened, type ":list". You can load all the files in tabs by doing ":tab ball" or use 'vim -p' on the command-line to load files straight to tabs. If you get permission denied errors, do: vim $(find . ! -path \*.svn\* -type -f iname \*foo\* 2>/dev/null) To narrow it down to a single file extension, such as .php files, use \*foo\*.php (or '*foo*.php'. Which ever you prefer)
vix /tmp/script.sh
Open a file directly with execution permission.
Put the function in your .bashrc
You can also put this in your vimrc:
command XX w | set ar | silent exe "!chmod +x %" | redraw!
and open a new file like this:
vi +XX /tmp/script.sh
The above output is for a custom compiled version of Vim on Arch Linux. Just a quick shell one liner, and presents a list of all the enabled and disabled (those prefixed with a '-') features. Show Sample Output
This is assuming that you're editing some file that has not been wrapped at 80 columns, and you want it to be wrapped. While in Vim, enter ex mode, and set the textwidth to 80 columns:
:set textwidth=80
Then, press:
gg
to get to the top of the file, and:
gqG
to wrap every line from the top to the bottom of the file at 80 characters.
Of course, this will lose any indentation blocks you've setup if typing up some source code, or doing type setting. You can make modifications to this command as needed, as 'gq' is the formatting command you want, then you could send the formatting to a specific line in the file, rather than to the end of the file.
gq49G
Will apply the format from your current cursor location to the 49th row. And so on.
probably just like 1204, but uses tee as a filter (+ I actually understand how this one works)
Multi-argument version, but with VIM loveliness :D
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.
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. Show Sample Output
Is this not the same
return to normal mode from hex mode :%!xxd -r
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).
insert filename Normal mode: "%p Insert mode: %
Because entering ':' requires that you press shift, sometimes common command-line / mini-buffer commands will be capitalized by accident. Show Sample Output
Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error.
---- this line ends here but must be concatenated with this one "this line ends here" and should NOT be concatenated with this one
Only under linux. Requires Gvim compiled with "clientserver" functionality and wmctrl command installed on system. Instead of servername can be used the current edited file name. Put it in a function and map it for get rid of "Press a key" after execution.
commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.
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
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: