alias to close terminal with :q
$ alias ':q'='exit' 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. View this command to comment, vote or...
View ArticleMake vim open in tabs by default (save to .profile)
$ alias vim="vim -p" I always add this to my .profile rc so I can do things like: "vim *.c" and the files are opened in tabs. View this command to comment, vote or add to favourites View all commands...
View Articlethe same as [Esc] in vim
$ Ctrl + [ Faster and more convinent than [Esc] View this command to comment, vote or add to favourites View all commands by light13 Diff your entire server config at ScriptRock.com
View Articleopen two files side by side in vim (one window, two panes)
$ vim -O file1 file2 View this command to comment, vote or add to favourites View all commands by bossNova Diff your entire server config at ScriptRock.com
View Articlediff current vi buffer edits against original file
$ :w !diff -u % - View this command to comment, vote or add to favourites View all commands by jclulow Diff your entire server config at ScriptRock.com
View Articleview hex mode in vim
$ :%!xxd View this command to comment, vote or add to favourites View all commands by light13 Diff your entire server config at ScriptRock.com
View ArticleEmptying a text file in one shot
$ :%d % = buffer d = delete View this command to comment, vote or add to favourites View all commands by Vilemirth Diff your entire server config at ScriptRock.com
View ArticleVIM: Replace a string with an incrementing number between marks 'a and 'b...
$ :let i=0 | 'a,'bg/ZZZZ/s/ZZZZ/\=i/ | let i=i+1 View this command to comment, vote or add to favourites View all commands by res0nat0r Diff your entire server config at ScriptRock.com
View Articleadd the result of a command into vi
$ !!command 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). View this command to...
View ArticleDelete DOS Characters via VIM (^M)
$ :set ff=unix And in case you want to migrate back to, err.. MS-DOS: ":set ff=dos" does the opposite. View this command to comment, vote or add to favourites View all commands by Matejunkie Diff your...
View ArticleRead the output of a command into the buffer in vim
$ :r !command This will append the output of "command" to whatever file you're currently editing in vim. Who else has good vim tricks? :) View this command to comment, vote or add to favourites View...
View ArticleColored SVN diff
$ svn diff <file> | vim -R - Simple way to achieve a colored SVN diff View this command to comment, vote or add to favourites View all commands by caiosba Diff your entire server config at...
View ArticleDelete all empty lines from a file with vim
$ :g!/\S/d 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 View this command to...
View ArticleQuickly share code or text from vim to others.
$ :w !curl -F "sprunge=<-" http://sprunge.us | xclip 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...
View ArticleColored diff ( via vim ) on 2 remotes files on your local computer.
$ vimdiff scp://root@server-foo.com//etc/snmp/snmpd.conf scp://root@server-bar.com//etc/snmp/snmpd.conf You can use vim scp://root@example.com//file too in a simple case. View this command to comment,...
View ArticlePipe STDOUT to vim
$ tail -1000 /some/file | vim - The hyphen tells vim to open from STDOUT - saves having to create temporary files. View this command to comment, vote or add to favourites View all commands by root Diff...
View ArticleVI config to save files with +x when a shebang is found on line 1
$ au BufWritePost * if getline(1) =~ "^#!" | if getline(1) =~ "/bin/" | silent !chmod +x <afile> | endif | endif Add this to .vimrc to automatically give scripts with a shebang (e.g.,...
View ArticleDelete all empty lines from a file with vim
$ :g/^$/d View this command to comment, vote or add to favourites View all commands by acumon Diff your entire server config at ScriptRock.com
View ArticleMakes you look busy
$ alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file' This makes an alias...
View Articleuse vim to get colorful diff output
$ svn diff | view - :q to quit View this command to comment, vote or add to favourites View all commands by freestyler Diff your entire server config at ScriptRock.com
View ArticleOpens vi/vim at pattern in file
$ vi +/pattern [file] 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...
View ArticleSave your sessions in vim to resume later
$ :mksession! <filename> 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...
View ArticleSave a file you edited in vim without the needed permissions (no echo)
$ :w !sudo tee > /dev/null % 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...
View ArticleBring the word under the cursor on the :ex line in Vim
$ :<C-R><C-W> 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 View this command to...
View ArticleAdd Password Protection to a file your editing in vim.
$ vim -x <FILENAME> 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...
View Article