Key | Action |
---|---|
j | Move down one line |
k | Move up one line |
l | Move to the left on character |
h | Move to the right one character |
- normal − This is the mode vim uses when a file is first opened, and allows for entering commands
- insert − The insert mode is used to actually edit text in a file.
Command | Action |
---|---|
G | Go to the end of the file |
gg | Go to the beginning of the file |
x | Delete the selected character |
u | Undo the last modifications |
Enter | Jump forward by lines |
dd | Delete the entire line |
? | Search for a string |
/ | Proceed to the next search occurrence |
Xml Opener Download
- Search for the string 'test', then first 5 occurrences
- Move to the beginning of the document after finding the first 5 occurrences of 'test'
- Go to line 100 using enter
- Delete the entire word using 'x'
- Undo the deletions using 'u'
- Delete the entire line using 'dd'
- Reconstruct the line using 'u'
- Step 1 − Press the escape key
- Step 2 − Press shift+:
- Step 3 − type w myfile.txt:w and hit Enter
- Step 4 − Press shift+:
- Step 5 − Type q! and hit Enter
Linux File Input/Output Redirection
STDOUT
STDIN
Number | File Descriptor | Character |
---|---|---|
0 | standard input | < |
1 | standard output | > |
2 | standard error | |
append stdout | >> | |
assign redirection | & | |
pipe stdout | | |
^M
at the end of almost every line. <CR><LF>
as a Unix carriage return. In case it matters, I typically open files with either1 Answer
Not the answer you're looking for? Browse other questions tagged gvim or ask your own question.
- rpm -ivh vim-common-..rpm vim-minimal-..rpm vim-enhanced-..rpm vim-X11-..rpm
- yum install vim-common vim-minimal vim-enhanced vim-X11
- apt-get install vim vim-common vim-gnome vim-gui-common vim-runtime
- Download vim source from http://vim.org
- tar xzf vim-7.0.tar.gz
- cd vim70
- ./configure --prefix=/opt --enable-cscope
- make
- make install
Arguments | Description |
---|---|
+[num] | Open editor with cursor on line 'num'. If 'num' is not specified, the cursor will be on the last line of the file. |
+/{pat} | Open editor with cursor on the first occurrence of {pat}. |
-c {command} --cmd {command} | A 'ex' command in dowble quotes will be processed against the file specified. |
-b | Binary file mode. |
-C -v | VI compatibility mode. Loses the more advanced vim features. |
-d | Diff file mode. Must list all files to perform a diff upon (list 2, 3 or 4 files). Same as vimdiff. |
-g | GUI gvim mode (if compiled in and available). |
-h --help | Print help messages. Also see vimtutor |
-i filename | Specify viminfo file. Default is ~/.viminfo |
-r -L | Recovery mode. Used after a crash. The '.swp' file is used. See ':help recovery'. |
-M -R | File modifications and write not allowed. |
-n | Prohibit '.swp' file generation. Required for special devices of limited space. |
-x | Use encryption when writing files. Will prompt for a crypt key. |
--noplugin | Skip loading plugins. |
--version | Print vim version. |
- Command mode: letters or sequence of letters interactively command vi. Commands are case sensitive. The ESC key can end a command.
- Insert mode: Text is inserted. The ESC key ends insert mode and returns you to command mode. One can enter insert mode with the 'i' (insert), 'a' (insert after), 'A' (insert at end of line), 'o' (open new line after current line) or 'O' (Open line above current line) commands.
- Command line mode: One enters this mode by typing ':' which puts the command line entry at the foot of the screen.
Keystrokes | Action |
---|---|
h/j/k/l | Move cursor left/down/up/right |
spacebar | Move cursor right one space |
-/+ | Move cursor down/up in first column |
ctrl-d n ctrl-d | Scroll down one half of a screen. Set scroll to 'n' lines. New default set for half screen. |
ctrl-u n ctrl-u | Scroll up one half of a screen Set scroll to 'n' lines. New default set for half screen. |
ctrl-f n ctrl-f | Scroll forward one screen Scroll forward 'n' screen |
ctrl-b n ctrl-b | Scroll back one screen Scroll back 'n' screen |
ctrl-y n ctrl-y | Scroll forward one line Scroll forward 'n' lines |
ctrl-e n ctrl-e | Scroll back one line Scroll back 'n' lines |
M (shift-m) | Move cursor to middle of page |
H (shift-h) | Move cursor to top of page |
L (shift-l) | Move cursor to bottom of page |
W w 5w | Move cursor a word at a time (white space delimited) Move cursor a word at a time (first non-alphanumeric) Move cursor ahead 5 words |
B b 5b | Move cursor back a word at a time (white space delimited) Move cursor back a word at a time (first non-alphanumeric) Move cursor back 5 words |
E e 5e | Move cursor to end of word (white space delimited) Move cursor to end of word (first non-alphanumeric) Move cursor ahead to the end of the 5th word |
0 (zero) | Move cursor to beginning of line |
:30 | Move cursor to line thirty |
$ | Move cursor to end of line |
) | Move cursor to beginning of next sentence (delimeted by '.', '?' or '!') |
( | Move cursor to beginning of current sentence |
} | Move cursor to beginning of next paragraph (delimeted by blank line or nroff macros: .IP, .LP, .PP, .QP, .P, .LI and .bp) Also see 'set paragraphs' to define a paragraph. |
{ | Move cursor to beginning of current paragraph |
]] | Move cursor to beginning of next section (delimeted by nroff macros: .NH, .SH, .H, .HU). Also see 'set sections' to define a section. |
[[ | Move cursor to beginning of current section |
G | Move cursor to end of file |
% | Move cursor to the matching bracket. Place cursor on {}[]() and type '%'. Use the matchit or xmledit plug-in to extend this capability to XML/XHTML tags. |
'. | Move cursor to previously modified line. |
m ma | Mark the line on which the cursor resides. Marking requires an identifier. Mark the line as identified by the letter 'a' by marking with keystroke 'ma' |
'a | Move cursor to line mark 'a' generated by marking with keystroke 'ma' |
'A | Move cursor to line mark 'A' (global between buffers) generated by marking with keystroke 'mA' |
]' | Move cursor to next lower case mark. |
[' | Move cursor to previous lower case mark. |
Keystrokes | Action |
---|---|
i | Insert at cursor. Puts you in insert mode. Must use esc key to terminate insert mode. |
I | Insert before the cursor. Puts you in insert mode. Must use esc key to terminate insert mode. |
a | Append after cursor. Puts you in insert mode. Must use esc key to terminate insert mode. |
A | Append at end of line. Puts you in insert mode. Must use esc key to terminate insert mode. |
o | Open a new line below the current cursor position. Also puts you in insert mode. Must use esc key to terminate insert mode. |
O | Open a new line above the current line. Also puts you in insert mode. Must use esc key to terminate insert mode. |
ESC | Terminate insert mode. Terminates most other modes as well. |
u | Undo last change |
U | Undo all changes to entire line |
dd 3dd | Delete line (stored in local buffer) Delete 3 lines (stored in local buffer). |
D | Delete contents of line after cursor |
C | Delete contents of line after cursor and insert new text. Press esc key to end insertion. |
dw 4dw d) d$ d- dfx d'x 'ad'b d/cat | Delete word Delete 4 words Delete to end of sentence Delete all characters from cursor to end of line Delete current and previous line Delete from cursor to first occurance of the letter 'x' Delete from the current line to the line marked with the identifier 'x' Delete from the line of mark 'a' to the line marked 'b'. Delete all characters from the cursor to the next occurance of (but not including) 'cat' |
cw c) c$ | Change word Change sentence Change from cursor to end of line (See 'd' delete above for other variations) |
x | Delete character at cursor |
X | Delete character before cursor |
Y or yy | Yank (copy) current line into 'unnamed' storage buffer. |
p | Paste unnamed storage buffer after current line. |
P | Paste unnamed storage buffer before current line. |
r | Replace character |
R | Overwrite characters from cursor onward |
s | Substitute one character under cursor continue to insert |
S | Substitute entire line and begin to insert at beginning of line |
J | Join current and following line into one line |
~ | Change case of individual character |
ctrl-a ctrl-x | Increment number under the cursor. Decrement number under the cursor. |
. | repeat last command action. |
Keystrokes | Action |
---|---|
/search_string{CR} | Search for search_string |
?search_string{CR} | Search backwards (up in file) for search_string |
/<search_string>{CR} | Search for search_word Ex: /<s> Search for variable 's' but ignore declaration 'string' or words containing 's'. This will find 'string s;', 's = fn(x);', 'x = fn(s);', etc |
n | Find next occurrence of search_word |
N | Find previous occurrence of search_word |
fx nfx ; | Move cursor to first occurance of letter 'x' after the cursor but in the same line Move cursor to 'n'th occurance of letter 'x' in line Go to next occurance in line |
Fx nFx ; | Move cursor backwards to next occurance of letter 'x' in line Move cursor backwards to 'n'th occurance of letter 'x' in line Go to previous occurance in line |
tx ntx ; | Move cursor to one char before the next occurance of letter 'x' in line Move cursor to one char before the 'n'th occurance of letter 'x' in line. Go to one char before the next occurance in line |
Tx nTx ; | Move cursor backwards to one char before the next occurance of letter 'x' Move cursor backwards to one char before the 'n'th occurance of letter 'x' Go to one char before previous occurance in line |
Pattern | Description |
---|---|
. | A period matches any single character |
^ | Finds the beginning of a line |
^A | Finds the beginning of a line where the first character is the letter 'A' |
$ | Matches the end of a line |
[abc] | Matches a string which contains any of the letters (a, b or c) between the brackets |
Turn off the special meaning of a character. Example '.' does not match the period to any character but to the period character specifically | |
d | Match any single digit (0 to 9) |
* | A search expression followed by a '*' matches zero or more of the search expression. For example 'A*' will match A, AA and AAA |
+ | Same as '*' above except that it matches one or more of the search expression. |
? | Same as '*' and '+' except that it matches zero or one occurances |
string1|string2 | Match any either string 1 or string 2 |
a.b | Matches a string beginning with the letter 'a' followed by any character, again followed by the letter 'c' |
^.$ | Matches an entire line containing only a single character |
a(b*|c*)d | Matches a string beginning with the letter 'a' followed by zero or more of the letter 'b', followed by zero or more of the letter 'c' and then followed by the letter 'd' |
Linux.*Linux | Finds a line containing two instances of the string 'Linux' |
.* [a-z]+ .* | Finds a line containing a word comprised of all lower case letters with a single blank on either side of the word |
Keystrokes | Action |
---|---|
ctrl-g or :f | List file info: fine name, number of lines in file, position of cursor in file. |
:set list :set nolist | Show tabs and end of line markers Turn of tab and eol markings |
:args | Show command line arguments used |
- Use command: ZZ
Save changes to current file and quit. - Use command line: ':wq'
Save (write) changes to current file and quit. - Use command line: ':w'
Save (write) changes to current file without quitting. - Use command line: ':w!'
Save (write) changes to current file overriding the file permissions if the user has the privileges to change the file permissions. For example this will save a file with read only privileges if the user is the owner or has the ability to modify the privileges to allow a write. This will not permanently modify the file privileges. Note that there is no space between the two characters. A space will infer that the output is streamed to a Unix command following the '!'. - Use command line: ':w filename'
Save (write) changes to a new file of name 'filename' without quitting. - Use command line: ':q!'
Ignore changes and quit. No changes from last write will be saved. - Use command line: ':qa'
Quit all files opened.
- Use command: ':e filename'
Start new edit session on specified file name without closing current vi / vim editor process.
:set termcap - display terminal settings of your editing session.
Default is changed from noignorecase to ignorecase. (ic is a short form otherwise type set ignorecase)
Full 'set' Command | Short form | Description |
---|---|---|
:set autoindent :set noautoindent | :set ai :set noai | {CR} returns to indent of previous line. Turn on autoindent: :set ai Turn off autoindent: :set noai Set indent width: set shiftwidth=4 Intelligent auto-indent: set smartindent Toggle autoindent on/off when pasting text (press F2 key to toggle mode after one is in 'insert' mode): set pastetoggle=<F2> or add the following to your ~/.vimrc file: |
:set autowrite :set noautowrite | :set aw :set noaw | This tells vim to automatically write the file when switching to edit another file. See tags, editing multiple files (next, rewind) |
:set backspace=indent,eol,start :set backspace | :set bs=indent,eol,start :set bs | Allow backspacing over an indent, line break (end of line) or start of an insert |
:set backup=on :set backup=off | :set bk=on :set bk=off | Create backup file of file changes while editing. To automatically remove the backup file after the file being edited is written, use the option :set writebackup=on/off File backup mode settings: :set backupcopy=yes/no/auto |
:set cryptmethod=zip :set cryptmethod=blowfish | Set file encryption for file save of buffer contents.
Vim 7.3+ | |
:set errorbells :set noerrorbells | :set eb :set noeb | Silence error beep |
:set flash :set noflash | :set fl :set nofl | Screen flashes upon error (for deaf people or when noerrorbells is set) |
:set tabstop=8 | :set ts | Tab key displays 8 spaces |
:set ignorecase :set noignorecase | :set ic :set noic | Case sensitive searches |
:set number :set nonumber | :set nu :set nonu | Display line numbers |
:set showmatch :set noshowmatch | no abbreviations | Cursor shows matching ')' and '}' |
:set showmode :set noshowmode | no abbreviations | Editor mode is displayed on bottom of screen |
:set showmatch :set noshowmatch | no abbreviations | Cursor shows matching ')' and '}' |
:set syntax on :set syntax off | no abbreviations | Set syntax highlighting and color highlighting for a file type (eg XML, HTML, C++, Java, etc). Also cursor shows matching ')' and '}' Also can set syntax highlighting explicitly: :set syntax=html Syntax definition files: /usr/share/vim/vim73/syntax/ |
:set taglength | :set tl | Default=0. Set significant characters |
:set closepunct='.,;)]} | % key shows matching symbol. Also see showmatch | |
:set linelimit=1048560 | Maximum file size to edit | |
:set wrapscan :set nowrapscan | :set ws :set nows | Breaks line if too long |
:set wrapmargin=0 :set wrapmargin=8 :set nowrapmargin | :set wm :set nowm | Define right margin for line wrapping. Wrap when past 8 characters from the edge of column display (often default 80). |
:set list :set nolist | Display all Tabs and Ends of lines (Dislays these hidden characters). | |
:set bg=dark :set bg=light | VIM: choose color scheme for 'dark' or 'light' console background. |
Interactive Command Examples:
- Marking a line:
Any line can be 'Book Marked' for a quick cursor return.- Type the letter 'm' and any other letter to identify the line.
- This 'marked' line can be referenced by the keystroke sequence ''' and the identifying letter.
Example: 'mt' will mark a line by the identifier 't'.
''t' will return the cursor to this line at any time.
A block of text may be referred to by its marked lines. i.e.'t,'b - Write a marked block to a new file: 't,'bw newfile
- vi line buffers:
To capture lines into the buffer:- Single line: 'yy' - yanks a single line (defined by current cursor position) into the buffer
- Multiple lines: 'y't' - yanks from current cursor position to the line marked 't'
- Multiple lines: '3yy' - yank 3 lines. Current line and two lines below it.
- 'p' - place contents of latest entry to the buffer after current line defined by current cursor position. The buffer can be referenced by its number as well. The latest entry to the buffer is entry '1'. Recall with the keystroke '1p
- Each deleted line will end up in the vim line buffer. To recall the prior entry to the buffer use the keystroke: '2p. The prior entries to the buffer can all be referenced by its number. Each time an entry to the buffer is made, its position in the stack is incremented. Typically vim has nine (1-9) default 'numbered' buffers.
- vi named line buffers:
Storage buffers can be named with letters of the alphabet: a-z.
To capture lines into the buffer:- Single 'yanked' line stored in buffer 'a': 'ayy - yanks a single line (defined by current cursor position) into the buffer named 'a'
- Deleted line stored in buffer 'b': 'bdd - deletes a single line (defined by current cursor position) into the buffer named 'a'
- Deletes 4 lines and stores in buffer 't': 't4dd - deletes four lines (defined by current cursor position) into the buffer named 'a'
To paste lines from a named buffer:- Single line stored in buffer 'a': 'ap - paste contents of the buffer named 'a' after the current line (defined by current cursor position)
- vim: Shift a block of code left or right:
- Enter into visual mode by typing the letter 'v' at the top (or bottom) of the block of text to be shifted.
- Move the cursor to the bottom (or top) of the block of text using 'j', 'k' or the arrow keys.
Tip: Select from the first collumn of the top line and the last character of the line on the bottom line.
Zero ('0') will move the cursor to the first character of a line and '$' will move the cursor to the last character of the line. - Type >> to shift the block to the right.
Type << to shift the block to the left.
This can be placed in your $HOME/.vimrc file. - vim: Shift a block of code left or right (method #2):
- :20,40>
Shift text from row 20 to 30, to the right - :20,40<
Shift text from row 20 to 30, to the left
- :20,40>
Command Line Examples:
- command options:
The vi command line interface is available bytyping ':'. Terminate with a carriagereturn.
Example commands:- :help topic
If the exact name is unknown, TAB completion will cycle through the various options given the first few letters. Ctrl-d will print the complete list of possibilites.
- :help topic
- Executing Unix commands in vi:
Any UNIX command can be executed from the vi command line by typing an '!' before the UNIX command.
Examples:- :!pwd - shows your current working directory.
- :!ls - shows files in your current working directory.
- :sh - open a new Bash shell. Editing session is suspended until you exit the shell. Execute all the commands you want and then return to the vim session.
- Reading and merging/including external text:
- :r filename - include the contents of an external file
- :r !date - reads the results from the date command into a new line following the cursor.
- :r !ls -1 - Place after the cursor, the current directory listing displayed as a single column.
- Line numbers:
Lines may be referenced by their line numbers. The last line in the file can be referenced by the '$' sign.
The entire file may be referenced by the block '1,$' or '%'
The current line is referred to as '.'
A block of text may be referred to by its line numbers or its marked lines. i.e. 5,38 or 't,'b
Write out a block of text denoted by line numbers :5,38 w newfile
Append a marked block to an existing file: 't,'bw >> filename - Find/Replace:
Example:- :%s/fff/rrrrr/ - For all lines in a file, find string 'fff' and replace with string 'rrrrr' for the first instance on a line.
- :%s/fff/rrrrr/g - For all lines in a file, find string 'fff' and replace with string 'rrrrr' for each instance on a line.
- :%s/fff/rrrrr/gc - For all lines in a file, find string 'fff' and replace with string 'rrrrr' for each instance on a line. Ask for confirmation
- :%s/fff/rrrrr/gi - For all lines in a file, find string 'fff' and replace with string 'rrrrr' for each instance on a line. Case insensitive.
- :'a,'bs/fff/rrrrr/gi - For all lines between line marked 'a' (ma) and line marked 'b' (mb), find string 'fff' and replace with string 'rrrrr' for each instance on a line. Case insensitive.
- :5,20s/fff/rrrrr/gc - For all lines between line 2 and line 20, find string 'fff' and replace with string 'rrrrr' for each instance on a line. Confirm each change with y/n.
- :1,$s/$/XXX/ - For all lines in the file, append a tripple X (XXX)
- :1,$s/XXX$// - For all lines in the file, remove the tripple X (XXX)
- :%s/ *$/ - For all lines in a file, delete blank spaces at end of line (there is a single space before the asterisk). Repeat with a tab instead of a space to delete trailing tabs.
- :%s/(.*):(.*)/2:1/g - For all lines in a file, move last field delimited by ':' to the first field. Swap fields if only two.
- :%s#<[^>]+>##g - Find and remove all HTML tags but keep the text contents.
- :%s/^(.*)n1$/1/ - Find and remove all duplicate lines
- :help substitute
- :help pattern
- :help gdefault
- :help cmdline-ranges
- Sorting:
Example:- Mark a block of text at the top line and bottom line of the block of text. i.e. 'mt' and 'mb' on two separate lines. This text block is then referenced as 't,'b.
- Sort lines in block: (man page: sort)
:'t,'b !sort - Reverse order of lines in block: (man page: tac)
:'t,'b !tac - Sort lines of text in a paragraph. Block of lines defining the paragraph are identified by the cursor as the top and the first blank line as the end of the paragraph. Place curson on the line 'Blue chair' and type the following:
!}sort
File to edit: Becomes Note that lines below the blank line delimeter are not sorted. - Sort lines of text in a paragraph by the second collumn:
!}sort -f -k2
option '-f' : ignore case
option '-k' : list collumn number to sort by
For a list of all options, see the sort man page
File in previous example becomes: - Sort lines of text in a paragraph and arrange into four collumns:
!}sort | pr -4t
option -4 : four collumns
option -t : omit page headers and trailer
pr man page
File to edit: Becomes Note that lines below the blank line delimeter are not sorted.
- Moving columns, manipulating fields and awk:
:'t,. !awk '{print $3 ' ' $2 ' ' $1}' - This will reverse the order of the columns in the block of text. The block of text is defined here as from the line marked with the keystroke 'bt' and the current line ('.'). This text block is referenced as ''t,.' (man page: awk) - Source Code Formatting: C++/Java
- Use vim visual text selection to mark the lines to format (beautify):
- eg. Whole file:
- Go to first line in file: shift-v
- Go to last line in file: shift-g
- Select the key equals: =
- eg. Whole file:
- Use vim visual text selection to mark the lines to format (beautify):
- Text Formatting:
- Mark a block of text at the top line and bottom line of the block. i.e. 'mt' and 'mb' on two separate lines.
- Example: ':'t,'b !nroff'
- You can insert nroff commands i.e.:
Example:.ce 3 Center the next three lines .fi Fill text - left and right justify (default) .nf No Fill .ls 2 Double line spacing .sp Single line space .sv 1.0i Vertical space at top of page space .ns Turn off spacing mode .rs Restore spacing mode .ll 6.0i Line length = 6 inches .in 1.0i Indent one inch .ti 1.0i Temporarily one time only indent one inch .pl 8.0i Page length = 8 inches .bp Page break Becomes:
- nroff - text formatter (emulate nroff command with groff)
- troff - troff processor of the groff text formatting system
- tbl - table formatter (for troff)
- Text Width Formatting:
- Mark a block of text or reference a block by their line numbers and pipe them through fmt, a text formatter which splits lines on word boundaries.
- :20,30 !fmt -80 will re-format the lines from line 20 to line 30 to wrap at an 80 collumn margin. Any line longer than 80 characters (eg a long URL), will not get split. A line split occurs at word delimiters such as a blank space.
- Spell Checking:
- Mark a block of text by marking the top line and bottom line of the block. i.e. 'mt' and 'mb' on two separate lines.
- :'t,'b !spell will cause the block to be replaced with misspelled words.
- Press 'u' to undo.
- Proceed to correct words misspelled.
- Vim/Vi Macros::map letter commands_strung_together
:map - lists current key mappings
Example - :map g n cwNEW_WORD{ctrl-v}{esc}i{ctrl-v}{CR}
This example would find the next search occurrence, change the word and insert a line feed after the word. The macro is invoked by typing the letter 'g'.- Control/Escape/Carriage control characters must be prefixed with ctrl-V.
- Choose a letter which is not used or important. (i.e. a poor choice would be 'i' as this is used for insert)
- Double spacing:
- :%s/$/{ctrl-V}{CR}/g
This command applies an extra carriage return at the end of all lines
- :%s/$/{ctrl-V}{CR}/g
- 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 '#'.
- :1,$ /^#/d
- Strip DOS ctrl-M's:
- :1,$ s/{ctrl-V}{ctrl-M}//
Note: In order to enter a control character, one muust first enter ctrl-v. This is true throughout vi. For example, if searching for a control character (i.e. ctrl-m): /ctrl-v ctrl-M If generating a macro and you need to enter esc without exiting the vi command line the esc must be prefixed with a ctrl-v: ctrl-v esc.
- :1,$ s/{ctrl-V}{ctrl-M}//
- Convert tabs to spaces:
- :% !expand -t4
convert tabs to four blank spaces for the whole file (%). - :20,30 !expand -t4
convert tabs to four blank spaces for lines 20 through 30.
- :% !expand -t4
- Editing multiple files:
- vi file1 file2 file3
- :n Edit next file (file2)
- :n Edit next file (file3)
- :rewind Rewind to the first file (file1)
or shift-ctrl-~ - :rewind! Rewind to the first file (file1) without saving changes
- Line folding:Many times one may encounter a file with folded lines or may wish to fold lines. The following image is of a file with folded lines where each '+' represents a set of lines not viewed but a marker line prefixed with a '+' is shown stating how many lines have been folded and out of view. Folding helps manage large files which are more easily managed when text lines are grouped into 'folds'.Example: vim /usr/share/vim/vim63/plugin/netrw.vimKeystrokes:
Keystroke Description zR Unfold all folded lines in file. za Open/close (toggle) a folded group of lines. zA Open a closed fold or close an open fold recursively. zc Close a folded group of lines. zC Close all folded lines recursively. zd Delete a folded line. zD Delete all folded lines recursively. zE Eliminate all folded lines in file. zF Create 'N' folded lines. - Hyper-Linking to include files:
- Place cursor over the file name (i.e. #include 'fileABC.h')
- Enter the letter combination: gf
(go to file)
- Batch execution of vi from a command file:
Command file to change HTML file to lower case and XHTML compliance: Execute: vi -e file-name.html < ViCommands-HtmlUpdate.txt[Potential Pitfall]: This must be performed while vim has none of the files open which are to be affected. If it does, vim will error due to conflicts with the vim swap file.
- ctags *.h *.c This creates a file names 'tags'.
- Unix command line: vi -t subroutine_name This will find the correct file to edit.
OR - Vi command line: :tag subroutine_name This will jump from your current file to the file containing the subroutine. (short form :ta subroutine_name )
OR - By cursor position: ctrl-] Place cursor on the first character of the subroutine name and press ctrl-] This will jump to the file containing the subroutine.
Note: The key combination ctrl-] is also the default telnet connection interrupt. To avoid this problem when using telnet block this telnet escape key by specifying NULL or a new escape key:- telnet -E file-name
- telnet -e ' file-name
If it is not working properly look at the 'tags' file created by ctags. Also the tag name (first column) may be abbreviated for convenience. One may shorten the significant characters using :set taglength=number
- A project may have a tags file which can be added and referred to by: :set tags=tags /ad/src/project1.tags
A ' must separate the file names. - :set autowrite will automatically save changes when jumping from file to file, otherwise you need to use the :w command.
- Autowrite can be intentionally avoided by using '!' to avoid the save when switching files. Changes will be lost: :ta! next-tag
Tag Command | Description |
---|---|
:tag start-of-tag-name_TAB | Vim supports tag name completion. Start the typing the tag name and then type the TAB key and name completion will complete the tag name for you. |
:tag /search-string | Jump to a tag name found by a search. |
ctrl-] | The vim editor will jump into the tag to follow it to a new position in the file or to a new file. |
ctrl-t | The vim editor will allow the user to jump back a level. (or :pop) |
:tselect <function-name> | When multiple entries exist in the tags file, such as a function declaration in a header file and a function definition (the function itself), the operator can choose by issuing this command. The user will be presented with all the references to the function and the user will be prompted to enter the number associated with the appropriate one. |
:tnext | When multiple answers are available you can go to the next answer. |
:set ignorecase (or :set ic) | The ignore case directive affects tagging. |
:tags | Show tag stack (history) |
:4pop | Jump to a particular position in the tag stack (history). (jump to the 4th from bottom of tag stack (history). The command ':pop' will move by default '1' backwards in the stack (history).) or :4tag (jump to the 4th from top of tag stack) |
:tnext | Jump to next matching tag. (Also short form :tn and jump two :2tnext) |
:tprevious | Jump to previous matching tag. (Also short form :tp and jump two :2tp) |
:tfirst | Jump to first matching tag. (Also short form :tf, :trewind, :tr) |
:tlast | Jump to last matching tag. (Also short form :tl) |
Using multiple tag files (one in each directory). Allows one to specify all tags files in directory tree: set tags=src/**/tags Use Makefile to generate tags files as well as compile in each directory. |
- Man page: ctags
- ctags version 5.5.4:
- ctags version 5.0.1:
- ~/.vimrc
- ~/.gvimrc
- ~/.vim/ (directory of vim config files.)
- Look in /usr/share/vim/vim61/colors/ for available colorschemes.
(I also like 'colorscheme desert') - Alternate use of autoindent: set ai sw=3
Compiling Vim from source:
- Download vim source from http://vim.org
- tar xzf vim-7.0.tar.gz
- cd vim70
- ./configure --prefix=/opt --enable-cscope
- make
- make install
Using Cscope with vim:
The Cscope database (cscope.out) is generated the first time it is invoked. Subsequent use will update the database based on file changes.The database can be generated manually using the command i.e.: cscope -b *.cpp *.h
Vim Default Xml Opener Key
or cscope -b -R .Search Type | Type short form | Description |
---|---|---|
symbol | s | Find all references to a symbol |
global | g | Find global definition |
calls | c | Find calls of this function |
called | d | Find functions that the specified function calls |
text | t | Find specified text string |
file | f | Open file |
include | i | Find files that '#include' the specified file |
- To jump to a result type the results number (+ enter)
- Use tags commands to return after a jump to a result: ctrl-t
To return to same spot as departure, use ctrl-o - To use 'tags' navigation to search for words under the cursor (ctrl- or ctrl-]) instead of using the vim command line ':cscope' (and 'ctrl-spaceBar' instead of ':scscope'), use the vim plugin, cscope_maps.vim [cache]
When using this plugin, overlapping ctags navigation will not be available. This should not be a problem since cscope plugin navigation is the same but with superior indexing and cross referenceing.
Place this plugin in your directory '$HOME/.vim/plugin'
Plugin required for vim 5 and 6. This feature is compiled in with vim 7.0 on Red Hat Enterprise Linux 5 and CentOS 5 and newer Linux OS's. Attempts to use the plugin when not required will result in the following error:E568: duplicate cscope database not added - Cycle through results:
- Next result: :tnext
- Previous result: :tprevious
- Create a split screen for Cscope results: :scscope find search-type search-string
(Short form: :scs f search-type search-string) - Use command line argument ':cscope -R': Scan subdirectories recursively
- Use Cscope ncurses based GUI without vim: cscope
- ctrl-d: Exit Cscope GUI
Cscope command line arguments:
Argument | Description |
---|---|
-R | Scan subdirectories recursively |
-b | Build the cross-reference only. |
-C | Ignore letter case when searching. |
-fFileName | Specify Cscope database file name instead of default 'cscope.out'. |
-Iinclude-directories | Look in 'include-directories' for any #include files whose names do not begin with '/'. |
-iFiles | Scan specified files listed in 'Files'. File names are separated by linefeed. Cscope uses the default file name 'cscope.files'. |
-k | Kernel mode ignores /usr/include. Typical: cscope -b -q -k |
-q | create inverted index database for quick search for large projects. |
-sDirectoryName | Use specified directory for source code. Ignored if specified by '-i'. |
-u | Unconditionally build a new cross-reference file. |
-v | Verbose mode. |
file1 file2 .. | List files to cross reference on the command line. |
Cscope environment variable:
Environment Variable | Description |
---|---|
CSCOPE_EDITOR | Editor to use: /usr/bin/vim |
EDITOR | Default: /usr/bin/vim |
INCLUDEDIRS | Colon-separated list of directories to search for #include files. |
SOURCEDIRS | Colon-separated list of directories to search for additional source files. |
VPATH | Colon-separated list of directories to search. If not set, cscope searches only in the current directory. |
- Red Hat / CentOS / Fedora:
- RHEL4/5: /usr/share/vim/vim70/autoload/
- Fedora 3:/usr/share/vim/vim63/plugin/
- Ubuntu / Debian:
- Ubuntu 18.04: /usr/share/vim/vim80/autoload/
- Ubuntu 6.06: /usr/share/vim/vim64/plugin/
- Vim.org: List of all plugins
File Explorer / List Files: explorer.vim
Command | Description |
---|---|
:Explore | List files in your current directory |
:Explore directory-name | List files in specified directory |
:Vexplore | Split with a new vertical window and then list files in your current directory |
:Sexplore | Split with a new horizontal window and then list files in your current directory |
CScope: cscope_maps.vim
See cscope and vim description and use in this tutorial above.Tabbed pages: minibufexpl.vim
This plugin allows you to open multiple text files and accessed by their tabs displayed at the top of the frame.Keystroke | Description |
---|---|
:bn | New buffer |
:bd | Buffer delete |
:b3 | Go to buffer number 3 |
ctrl-w followed by 'k' | New buffer. Puts curson in upper tabbed portion of window. Navigate with arrow keys or 'h'/'l'. |
:qa | Quit vim out of all buffers |
tab | The 'tab' key jumps between tabbed buffers. |
Alternate between the commensurate include and source file: a.vim
Most usefull when used with the vim plugin 'minibufexpl.vim'Command | Description |
---|---|
:A | switches to the header file corresponding to the current file being edited (or vise versa) |
:AS | splits and switches |
:AV | vertical splits and switches |
:AT | new tab and switches |
:AN | cycles through matches |
:IH | switches to file under cursor |
:IHS | splits and switches |
:IHV | vertical splits and switches |
:IHT | new tab and switches |
:IHN | cycles through matches |
Plug-in Installation:
Example of installation of a.vim and minibufexpl.vim plug-ins:- mkdir -p ~/.vim/plugin
- cd ~/.vim/plugin
- wget -O a.vim http://www.vim.org/scripts/download_script.php?src_id=7218
- wget -O minibufexpl.vim http://www.vim.org/scripts/download_script.php?src_id=3640
Vim Default Editor
- ed - line editor (works on one file at a time)
- red - restricted shell version of ed
- tr - translate or delete characters
- ex - line oriented version of vi. Works on multiple files.
- sed - stream editor
- view - read only version of vi
- rview - restricted view
- gvim - GUI version of VIM
- rvim - restricted vim
- Linux Text Editors - overview and list
'The Ultimate Guide to VI and EX Text Editors' Hewlet Packard Corporation ISBN #0-8053-4460-8, Addison-Wesley Pub Co., Benjamin/Cummings Publishing Company | |
'Learning the vi and vim Editors (7th edition) by Arnold Robbins, Elbert Hannah, Linda Lamb ISBN #059652983X, O'Reilly | |
'Vi iMproved (VIM) by Steve Oualline ISBN #0735710015, Sams (1st edition) |
Starting with the 2007 Microsoft Office system, Microsoft Office uses the XML-based file formats, such as .docx, .xlsx, and .pptx. These formats and file name extensions apply to Microsoft Word, Microsoft Excel, and Microsoft PowerPoint. This article discusses key benefits of the format, describes the file name extensions and discusses how you can share Office files with people who are using earlier versions of Office.
In this article
What are the benefits of Open XML Formats?
The Open XML Formats include many benefits — not only for developers and the solutions that they build, but also for individual people and organizations of all sizes:
- Compact files Files are automatically compressed and can be up to 75 percent smaller in some cases. The Open XML Format uses zip compression technology to store documents, offering potential cost savings as it reduces the disk space required to store files and decreases the bandwidth needed to send files via e-mail, over networks, and across the Internet. When you open a file, it is automatically unzipped. When you save a file, it is automatically zipped again. You do not have to install any special zip utilities to open and close files in Office.
- Improved damaged-file recovery Files are structured in a modular fashion that keeps different data components in the file separate from each other. This allows files to be opened even if a component within the file (for example, a chart or table) is damaged or corrupted.
- Support for advanced features Many of the advanced features of Office 365 require the document to be stored in the Open XML format. Things like AutoSaveand the Accessibility Checker, for two examples, can only work on files that are stored in the modern Open XML format.
- Better privacy and more control over personal information Documents can be shared confidentially, because personally identifiable information and business-sensitive information, such as author names, comments, tracked changes, and file paths can be easily identified and removed by using Document Inspector.
- Better integration and interoperability of business data Using Open XML Formats as the data interoperability framework for the Office set of products means that documents, worksheets, presentations, and forms can be saved in an XML file format that is freely available for anyone to use and to license, royalty free. Office also supports customer-defined XML Schemas that enhance the existing Office document types. This means that customers can easily unlock information in existing systems and act upon it in familiar Office programs. Information that is created within Office can be easily used by other business applications. All you need to open and edit an Office file is a ZIP utility and an XML editor.
- Easier detection of documents that contain macros Files that are saved by using the default 'x' suffix (such as .docx, .xlsx, and .pptx) cannot contain Visual Basic for Applications (VBA) macros and XLM macros. Only files whose file name extension ends with an 'm' (such as .docm, .xlsm, and .pptm) can contain macros.
Before you decide to save the file in a binary format, read Can different versions of Office share the same files?
How do I convert my file from the old binary format to the modern Open XML format?
With the file open in your Office app, click File > Save as (or Save a copy, if the file is stored on OneDrive or SharePoint) and make sure the Save as type is set to the modern format.
This will create a new copy of your file, in the Open XML format.
What are the XML file name extensions?
By default, documents, worksheets, and presentations that you create in Office are saved in XML format with file name extensions that add an 'x' or an 'm' to the file name extensions that you are already familiar with. The 'x' signifies an XML file that has no macros, and the 'm' signifies an XML file that does contain macros. For example, when you save a document in Word, the file now uses the .docx file name extension by default, instead of the .doc file name extension.
When you save a file as a template, you see the same kind of change. The template extension used in earlier versions is there, but it now has an 'x' or an 'm' on the end. If the file contains code or macros, you must save it by using the new macro-enabled XML file format, which adds an 'm' for macro to the file extension.
The following tables list all the default file name extensions in Word, Excel, and PowerPoint.