Posts

Showing posts from November, 2010

Display hidden and control character in Vi / Vim

Turn on using  :set list Turn off using :set nolist

Oct Dec Hex Control Character Values

Oct Dec Hex Control Character Values Oct Dec Hex Name 000 0 0x00 NUL 001 1 0x01 SOH, Control-A 002 2 0x02 STX, Control-B 003 3 0x03 ETX, Control-C 004 4 0x04 EOT, Control-D 005 5 0x05 ENQ, Control-E 006 6 0x06 ACK, Control-F 007 7 0x07 BEL, Control-G 010 8 0x08 BS, backspace, Control-H 011 9 0x09 HT, tab, Control-I 012 10 0x0a LF, line feed, newline, Control-J 013 11 0x0b VT, Control-K 014 12 0x0c FF, form feed, NP, Control-L 015 13 0x0d CR, carriage return, Control-M 016 14 0x0e SO, Control-N 017 15 0x0f SI, Control-O 020 16 0x10 DLE, Control-P 021 17 0x11 DC1, XON, Control-Q 022 18 0x12 DC2, Control-R 023 19 0x13 DC3, XOFF, Control-S 024 20 0x14 DC4, Control-T 025 21 0x15 NAK, Control-U 026 22 0x16 SYN, Control-V 027 23 0x17 ETB, Control-W 030 24 0x18 CAN, Control-X 031 25 0x19 EM, Control-Y 032 26 0x1a SUB, Control-Z http://www.asciitable.com

How to edit hex values in Vi

Image
Editing binary files   Edit Use the  -b  option to set binary mode before editing a binary file, for example: vim -b myfile.bin If wanted, you can display nonprintable characters in hex, and you can wrap lines: :setlocal display=uhex :setlocal wrap In normal mode, type  g  then Ctrl-G to display the byte number at the cursor, or type a byte number then  go  to jump to that byte (for example,  123go  will jump to byte number 123). The first byte in the file has byte number 1. The following command replaces the buffer with a hex dump: :%!xxd You can edit the hex bytes, then convert the file back to binary with the command: :%!xxd -r The above command reverses the hex dump by converting the hex bytes to binary (the printable text in the right column is ignored). http://vim.wikia.com/wiki/Hex_dump

How to enter in any character in Vi / Vim

Image
By character value   Edit It is also possible to enter any character (which can be displayed in your current 'encoding'), even a character for which no digraph is defined, if you know the character value, as follows (where ^V means "hit Ctrl-V, except if you use Ctrl-V to paste, in which case you should hit Ctrl-Q instead): By decimal value:  ^Vnnn  (with 000 <= nnn <= 255) By octal value:  ^VOnnn  or  ^Vonnn  (with 000 <= nnn <= 377) By hex value:  ^VXnn  or  ^Vxnn  (with 00 <= nn <= FF) By hex value for BMP Unicode codepoints:  ^Vunnnn  (with 0000 <= nnnn <= FFFF) By hex value for any Unicode codepoint:  ^VUnnnnnnnn  (with 00000000 <= nnnnnnnn <= 7FFFFFFF) http://vim.wikia.com/wiki/Entering_special_characters

Vi search and pattern reference

A guide to searching for anything in Vi / Vim, super complete and concise http://vimdoc.sourceforge.net/htmldoc/pattern.html

The complete vi quick reference

This doc literally has every vi command! http://vimdoc.sourceforge.net/htmldoc/quickref.html

Vi search with / for decimal character value

You search for a decimal character with the normal search /\%d{decimal number} E.g search for a space character /\%d32 To tell what a character is in command mode type :ga http://vim.wikia.com/wiki/Searching

Vi search with / for hex character value

To search with a hex value is a normal vi search with  /\%x{hex number} E.g. search for a space /\%x20 To tell what a character is in command mode type :ga http://vim.wikia.com/wiki/Searching

Vi search and replace tricks, double spacing etc

Double spacing: :%s/$/{ctrl-V}{CR}/g This command applies an extra carriage return at the end of all lines Strip blanks at end of line: :%s/{TAB}*$// Delete all lines beginning with or matching a pattern: :1,$ /^#/d Delete all (first to last line: 1,$ or g) comments lines in file. Delete all lines beginning (^) with "#" (specify text pattern). :g/#/d Delete all lines (g) containing comments (comments follow "#") in file. Delete all lines containing "#". :g!/^#/d Delete all lines except (g! or v) comment lines beginning (^) with "#". Strip DOS ctrl-M's: :1,$ s/{ctrl-V}{ctrl-M}//

Vi how to see control characters

This is a good explination http://vim.1045645.n5.nabble.com/How-to-show-all-the-control-characters-td1172632.html

Vi see character decimal value and character info

This shows you the file information what line column CTRL+g This shows you character info ga This shows you UTF-8 character info and it's decimal value g8

How to goto a vi character position

How to goto a vi character position. This will go to byte 21490 :goto 21490 While the following with go to the 200 character on a line(won't pass a new line) :200| 

bash move forward or backwards a word on command line

To move forward a word on the command line escape then f To move backwards a word on the command line escape then b forwards a word: ESC f backwards a word: ESC b

Textmate Ruby Macro - Remove Line Numbers

Textmate Ruby Macro - Remove Line Numbers #!/usr/bin/env ruby -wKU STDIN.readlines.each {|e| print e.gsub(/\A\d+/,"")  } #Set Save "Nothing" #Set Input "Selected Text" or "Character" # and #Set Output "Replace Selected Text"