While I love gpg and truecrypt there's some times when you just want to edit a file and not worry about keys or having to deal needing extra software on hand. Thus, you can use vim's encrypted file format. For more info on vim's encrypted files visit: http://www.vim.org/htmldoc/editing.html#encryption Show Sample Output
Very handy to bring the word currently under the cursor into a :s command in Vim. Example: If the cursor was on the word "eggs": :s/ ==> :s/eggs
Write a file you edited in Vim but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.
Creates a full snapshot of your current vim session, including tabs, open buffers, cursor positions, everything. Can be resumed with vim -S . Useful for those times when you HAVE to close vim, but you don't want to lose all your hard-opened buffers and windows. The ! will cause vim to overwrite the file if it already exists. It is not necessary, but useful if you frequently save to the same file (like session.vim or something).
Open up vi or vim at the first instance of a pattern in [file]. Useful if you know where you want to be, like "PermitRootLogin" in sshd_config. Also, vi +10 [file] will open up a file at line 10. VERY useful when you get "error at line 10" type of output.
:q to quit
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. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.
Add this to .vimrc to automatically give scripts with a shebang (e.g., #!/usr/bin/perl) executable permissions when saving. Found @ http://stackoverflow.com/questions/817060/creating-executable-files-in-linux/817522#817522
The hyphen tells vim to open from STDOUT - saves having to create temporary files.
Sprunge.us is a code/text sharing site like pastebin, but it is easy to post stuff from the command line.
How it works:
:w !command
In vim, w writes the current tab to a file when a filename is given afterwards, but if !command is given, the output is piped to the stdin of command.
curl -F "sprunge=<-" http://sprunge.us
curl is an HTTP client. The -F option does an HTTP post to the given address. The data in the quotes is passed in the post. The "sprunge=" part sets up a fieldname - the part that follows is what is associated with the name. The "<" tells curl to send data from the file descriptor that follows it. The "-" in bash is a file descriptor that points to stdin instead of an actual file; in this case, stdin is being piped in from vim. After we send the HTTP post to sprunge.us, it will give back a url that points to the data you just sent.
| xclip
xclip is a utility that lets you put stuff in your clipboard or selection buffer. This part uses a bash pipe ( | ) to redirect the stdout of the previous command to the stdin of the next command. So, we're capturing the URL that curl gave us and putting it into the selection buffer, ready to paste into IRC or a forum.
Notes:
Of course, for this to work, you must have curl (which comes by default on most distroes), and xclip installed.
When you share the url, you can append "?lang" to highlight and have line numbers. Check out http://sprunge.us/BZXV?log for line numbers and http://sprunge.us/BZXV?ruby for highlighting.
If you prefer to use ctrl-v (paste from clipboard) instead of middle-click (paste from selection buffer), look up options on xclip - you can do that.
Show Sample Output
You can use
vim scp://root@example.com//file
too in a simple case.
This command delete all the empty lines (include the lines with space) from a file. g = global command \S = non-whitespace character; !\S the opposite d = delete a range
Simple way to achieve a colored SVN diff
This will append the output of "command" to whatever file you're currently editing in vim. Who else has good vim tricks? :)
And in case you want to migrate back to, err.. MS-DOS: ":set ff=dos" does the opposite.
in command mode, navigate your cursor to the line where you want the command output to appear, and hit "!!". No need to enter edit mode or even type a ":" (colon).
% = buffer d = delete
Faster and more convinent than [Esc]
I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs.
Put this in your ~/.bashrc file (or the equivalent) If you use vim a lot, this alias will be immediately obvious. Your brain will thank you.
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: