Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div id="content" class="mw-body" role="main">
- <a id="top"></a>
- <div id="mw-js-message" style="display:none;"></div>
- <h1 id="firstHeading" class="firstHeading" lang="en"><span dir="auto">Vim</span></h1>
- <div id="bodyContent">
- <div id="siteSub">From Mewiki</div>
- <div id="contentSub"></div>
- <div id="jump-to-nav" class="mw-jump">
- Jump to: <a href="#mw-navigation">navigation</a>, <a href="#p-search">search</a>
- </div>
- <div id="mw-content-text" lang="en" dir="ltr" class="mw-content-ltr"><div id="toc" class="toc"><div id="toctitle"><h2>Contents</h2><span class="toctoggle"> [<a href="#" class="internal" id="togglelink">hide</a>] </span></div>
- <ul>
- <li class="toclevel-1 tocsection-1"><a href="#General"><span class="tocnumber">1</span> <span class="toctext">General</span></a></li>
- <li class="toclevel-1 tocsection-2"><a href="#Sessions"><span class="tocnumber">2</span> <span class="toctext">Sessions</span></a></li>
- <li class="toclevel-1 tocsection-3"><a href="#Working_with_files"><span class="tocnumber">3</span> <span class="toctext">Working with files</span></a></li>
- <li class="toclevel-1 tocsection-4"><a href="#History"><span class="tocnumber">4</span> <span class="toctext">History</span></a></li>
- <li class="toclevel-1 tocsection-5"><a href="#Navigation"><span class="tocnumber">5</span> <span class="toctext">Navigation</span></a>
- <ul>
- <li class="toclevel-2 tocsection-6"><a href="#Declaration_navigation"><span class="tocnumber">5.1</span> <span class="toctext">Declaration navigation</span></a></li>
- <li class="toclevel-2 tocsection-7"><a href="#Navigation_history"><span class="tocnumber">5.2</span> <span class="toctext">Navigation history</span></a>
- <ul>
- <li class="toclevel-3 tocsection-8"><a href="#Tags"><span class="tocnumber">5.2.1</span> <span class="toctext">Tags</span></a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li class="toclevel-1 tocsection-9"><a href="#Marks"><span class="tocnumber">6</span> <span class="toctext">Marks</span></a></li>
- <li class="toclevel-1 tocsection-10"><a href="#Search.2C_replace"><span class="tocnumber">7</span> <span class="toctext">Search, replace</span></a></li>
- <li class="toclevel-1 tocsection-11"><a href="#Buffers"><span class="tocnumber">8</span> <span class="toctext">Buffers</span></a></li>
- <li class="toclevel-1 tocsection-12"><a href="#Windows"><span class="tocnumber">9</span> <span class="toctext">Windows</span></a></li>
- <li class="toclevel-1 tocsection-13"><a href="#Tabs"><span class="tocnumber">10</span> <span class="toctext">Tabs</span></a></li>
- <li class="toclevel-1 tocsection-14"><a href="#Selection"><span class="tocnumber">11</span> <span class="toctext">Selection</span></a></li>
- <li class="toclevel-1 tocsection-15"><a href="#Insert_mode_variations"><span class="tocnumber">12</span> <span class="toctext">Insert mode variations</span></a></li>
- <li class="toclevel-1 tocsection-16"><a href="#Edition"><span class="tocnumber">13</span> <span class="toctext">Edition</span></a>
- <ul>
- <li class="toclevel-2 tocsection-17"><a href="#Commenting_a_block"><span class="tocnumber">13.1</span> <span class="toctext">Commenting a block</span></a></li>
- <li class="toclevel-2 tocsection-18"><a href="#Un-commenting_a_block"><span class="tocnumber">13.2</span> <span class="toctext">Un-commenting a block</span></a></li>
- <li class="toclevel-2 tocsection-19"><a href="#Indentation"><span class="tocnumber">13.3</span> <span class="toctext">Indentation</span></a></li>
- <li class="toclevel-2 tocsection-20"><a href="#Copy_.2F_paste_.2F_delete"><span class="tocnumber">13.4</span> <span class="toctext">Copy / paste / delete</span></a></li>
- <li class="toclevel-2 tocsection-21"><a href="#Numbers"><span class="tocnumber">13.5</span> <span class="toctext">Numbers</span></a></li>
- </ul>
- </li>
- <li class="toclevel-1 tocsection-22"><a href="#Extra_tools"><span class="tocnumber">14</span> <span class="toctext">Extra tools</span></a></li>
- <li class="toclevel-1 tocsection-23"><a href="#Fugitive"><span class="tocnumber">15</span> <span class="toctext">Fugitive</span></a></li>
- <li class="toclevel-1 tocsection-24"><a href="#More_of_these.2C_please"><span class="tocnumber">16</span> <span class="toctext">More of these, please</span></a></li>
- </ul>
- </div>
- <h2><span class="mw-headline" id="General">General</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=1" title="Edit section: General">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b><start position><command><end position></b> - Most commands are under the form
- </p><p><b>.</b> - Repeat last command
- </p><p><b>N<command></b> - Repeat command N times
- </p><p><b>q:</b> - Show history
- </p><p><b>:! <command></b> - Execute external command
- </p><p><b>:.! <command></b> - Execute external command and paste in file on current line for instance <b>:.! date</b>
- </p><p><b>:r!</b> - Execute external command and paste on new line
- </p><p><b>:!./%</b> - Execute current .sh script
- </p><p><b>:!chmod +x %</b> - Set execution flag to current script ;)
- </p><p><b>:set paste</b> - De-activate autoindent when pasting from external source
- </p><p><b>:set nopaste</b> - Revert back to normal mode
- </p><p><b>:cd %:h</b> - Change working directory to current file
- </p><p><b><C-z></b> - Suspend vim
- </p><p><b>fg</b> - Come back in vim
- </p><p><b>:setlocal textwidth=80</b> - Set temporarily max legnth to 80
- </p><p><b>gqip</b> - Format current paragraph to length set above
- </p>
- <h2><span class="mw-headline" id="Sessions">Sessions</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=2" title="Edit section: Sessions">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:mksession session.vim</b> - Save current session
- </p><p><b>vim -S session.vim</b> - Open session or <b>:so session.vim</b> from within vim
- </p>
- <h2><span class="mw-headline" id="Working_with_files">Working with files</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=3" title="Edit section: Working with files">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:e newfile.txt</b> - Create new file
- </p><p><b>:e ~/file.html</b> - Open file
- </p><p><b>:w !sudo tee %</b> - Re-open same file via sudo
- </p><p><b>:e!</b> - Re-open same file without saving
- </p><p><b>:qa!</b> - Quit without saving all files
- </p><p><b>:w new.txt</b> - Save as
- </p><p><b>:sav new.txt</b> - Save as and open new.txt
- </p>
- <h2><span class="mw-headline" id="History">History</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=4" title="Edit section: History">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:earlier {count}</b> - Go to older text state {count} times.
- </p><p><b>:earlier {N}s</b> - Go to older text state about {N} seconds before.
- </p><p><b>:earlier {N}m</b> - Go to older text state about {N} minutes before.
- </p><p><b>:earlier {N}h</b> - Go to older text state about {N} hours before.
- </p><p><b>:earlier {N}d</b> - Go to older text state about {N} days before.
- </p><p><b>:later</b> - Comes back
- </p><p><b>g-</b> - Undo
- </p><p><b>g+</b> - Redo
- </p><p>Also with the form:
- </p><p><b>u</b> - Undo
- </p><p><b><C-r></b> - Redo
- </p>
- <h2><span class="mw-headline" id="Navigation">Navigation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=5" title="Edit section: Navigation">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b><C-g></b> - See where you are in a file
- </p><p>'<b>.</b> - Go to last modified line
- </p><p>'<b>0</b> - Go to where the cursor was when the file was last edited
- </p><p><b><N>G</b> - Go to line N
- </p><p><b>gg</b> - go to top of the file
- </p><p><b>G</b> - go to last line of the file
- </p><p><b>:<n></b> - Go to line n
- </p><p><b>:<n>%</b> - Go to n % of the file
- </p><p><b>0</b> - Go to first char on line
- </p><p><b>^^</b> - Go to first non whitespace char on line
- </p><p><b>$</b> - Go to end of line
- </p><p><b>fa</b> - Go to next occurrence of a
- </p><p><b>3fa</b> - Go to 3rd occurrence of a
- </p><p><b>3Fa</b> - Go to 3rd occurrence of a, backwards
- </p><p><b>;</b> - Repeat last 'go to' (always stays on the same line)
- </p><p><b>,</b> - Repeat last 'go to' in opposite direction
- </p><p><b>zz</b> - Center to current line
- </p><p><b>zt</b> - Place current line at the top
- </p><p><b>zb</b> - Place current line at the bottom
- </p><p><b><C-u></b> / <b><C-d></b> - Move half page up / down
- </p><p><b><C-e></b> / <b><C-y></b> - Scroll half page up / down
- </p><p><b>e</b> / <b>b</b> - Move by words
- </p><p><b>E</b> / <b>B</b> - Move by words with whitespace as delimiter
- </p><p><b>%</b> - Jump to corresponding { or ( or [
- </p><p><b>*</b> / <b>#</b> Jump to next / previous occurrence of the word
- </p>
- <h3><span class="mw-headline" id="Declaration_navigation">Declaration navigation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=6" title="Edit section: Declaration navigation">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
- <p><b>gd</b> - Go to local declaration
- </p><p><b>gD</b> - Go to global declaration
- </p><p><b>g*</b> - Search for string under cursos
- </p>
- <h3><span class="mw-headline" id="Navigation_history">Navigation history</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=7" title="Edit section: Navigation history">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
- <p><b><C-o></b> - Jump to older position
- </p><p><b><C-i></b> - Jump back to newer position
- </p><p><b>:jumps</b> - List all jumps
- </p>
- <h4><span class="mw-headline" id="Tags">Tags</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=8" title="Edit section: Tags">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
- <p><b><C-$></b> - Click 'hyperlink' in documentation
- </p>
- <h2><span class="mw-headline" id="Marks">Marks</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=9" title="Edit section: Marks">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>ma</b> - Place mark 'a' (26 a-z marks possible)
- </p><p>'<b>a</b> - Jump to mark 'a'
- </p><p><b>:marks</b> - List current marks
- </p><p><b>:delm! | delm A-Z0-9</b> - Delete all alpha-numeric marks
- </p>
- <h2><span class="mw-headline" id="Search.2C_replace">Search, replace</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=10" title="Edit section: Search, replace">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>/pattern</b> - search for 'pattern'
- </p><p><b>n</b> - search for next occurence
- </p><p><b>?<up-arrow></b> - Search for next occurence upwards
- </p><p><b>/<down-arrow></b> - Search for next occurence downwards
- </p>
- <h2><span class="mw-headline" id="Buffers">Buffers</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=11" title="Edit section: Buffers">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:ls</b> - List all open buffers
- </p><p><b>:b<n></b> - Switch to buffer with id <n>
- </p><p><b>:bd</b> - Close current buffer
- </p><p><b>:vsp</b> - Vertical split
- </p><p><b>:bwipeout</b> - Cleans all buffer (removes deleted files for instance)
- </p>
- <h2><span class="mw-headline" id="Windows">Windows</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=12" title="Edit section: Windows">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b><C-w>, r</b> - Rotate windows (Ctrl-w then r)
- </p><p><b><C-w>, x</b> - Swap the current window with the next one
- </p><p><b><C-w>, <S-h></b> - Move this window to the far left
- </p><p><b><C-w>, <S-k></b> - Move this window to the top
- </p><p><b>:help window-moving</b> - More of these, please!
- </p>
- <h2><span class="mw-headline" id="Tabs">Tabs</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=13" title="Edit section: Tabs">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:tabe</b> - Open new tab
- </p><p><b>gt</b> - Switch to next tab
- </p><p><b>gT</b> - Switch to previous tab
- </p><p><b>:tabc</b> - Close current tab
- </p>
- <h2><span class="mw-headline" id="Selection">Selection</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=14" title="Edit section: Selection">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>gv</b> - Select previously selected block
- </p><p><b>vi{</b> - Select all text in {}
- </p><p><b>va{</b> - Sellect all text in {} including {}s
- </p><p><b>vi(p</b> - Highlight everything inside the ()s and replace with the pasted text
- </p>
- <h2><span class="mw-headline" id="Insert_mode_variations">Insert mode variations</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=15" title="Edit section: Insert mode variations">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <ul>
- <li> <b>a</b> - insert after the cursor
- </li>
- <li> <b>o</b> - insert a new line after the current one
- </li>
- <li> <b>O</b> - insert a new line before the current one
- </li>
- <li> <b>cw</b> - replace from the cursor to the end of the word
- </li>
- </ul>
- <h2><span class="mw-headline" id="Edition">Edition</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=16" title="Edit section: Edition">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <h4><span class="mw-headline" id="Commenting_a_block">Commenting a block</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=17" title="Edit section: Commenting a block">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
- <ul>
- <li> <b>V</b> - Enter visual mode
- </li>
- <li> <b>:norm i#</b> - Comment the block
- </li>
- </ul>
- <h4><span class="mw-headline" id="Un-commenting_a_block">Un-commenting a block</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=18" title="Edit section: Un-commenting a block">edit</a><span class="mw-editsection-bracket">]</span></span></h4>
- <p><b>V</b> - Enter visual mode
- </p><p><b>:norm x</b> - Move around to select block
- </p><p><b>ci"</b> - Cut the text in current ""
- </p><p><b>ci'</b> - Cut the text in current \'\'
- </p><p><b>ciw</b> - Cut current word
- </p><p><b>C</b> - Cut the rest of line and go to insert mode
- </p><p><b>ddp</b> - Move current line one line below
- </p><p><b>ZZ</b> - Save and close current file
- </p>
- <h3><span class="mw-headline" id="Indentation">Indentation</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=19" title="Edit section: Indentation">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
- <p><b>gg=G</b> - Re-indent everything
- </p><p><b><</b> - Indent left
- </p><p><b>></b> - Indent right
- </p><p><b>=</b> - Auto-indent
- </p>
- <h3><span class="mw-headline" id="Copy_.2F_paste_.2F_delete">Copy / paste / delete</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=20" title="Edit section: Copy / paste / delete">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
- <p><b>dgg</b> - Delete all lines above current line
- </p><p><b>dG</b> - Delete all lines below current line
- </p><p><b>dd</b> - Delete current line
- </p><p><b>r</b> - Replace character under cursor
- </p><p><b>J</b> - Join 2 lines (remove CR on current line and join the one below)
- </p><p><b>d$</b> - Deletes the rest of the line to the right of the cursor
- </p><p><b>Shift + d</b> - Same
- </p><p><b>c$</b> - Deletes the rest of the line and puts you in insert mode
- </p><p><b>de</b> - Delete from cursor to the end of the word
- </p><p><b>dE</b> - Delete until next space
- </p><p><b>dt.</b> - Delete until next dot
- </p><p><b>:g/<text>/y A</b> - Yank all lines containing <text>
- </p><p><b>:g/<text>/d A</b> - Delete all lines containing <text>
- </p><p><b>:g!/<text>/normal dd</b> - Delete all lines that don't contain <text>
- </p><p><b>ce</b> - Cut through the end of the word
- </p><p><b>bye</b> - Copy current word
- </p><p><b>yy</b> - Copy current line
- </p><p><b>0y$</b> - Copy whole line
- </p><p><b>cc</b> - Delete current and goes to insert mode (keeps indentation)
- </p><p><b>cb</b> - Deletes previous word and goes to insert mode
- </p><p><b>P</b> - Paste! (before current position)
- </p><p><b>p</b> - Paste! (after current position)
- </p><p><b>viwU</b> - Uppercase whole word
- </p><p><b>viw~</b> - Alternate case on whole word
- </p>
- <h3><span class="mw-headline" id="Numbers">Numbers</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=21" title="Edit section: Numbers">edit</a><span class="mw-editsection-bracket">]</span></span></h3>
- <p><b><C-a></b> - Increment number
- </p><p><b><C-x></b> - Decrement number
- </p>
- <h2><span class="mw-headline" id="Extra_tools">Extra tools</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=22" title="Edit section: Extra tools">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:so %</b> - Reload current .vimrc
- </p><p><b>:%TOhtml</b> - Export current file to html buffer
- </p>
- <h2><span class="mw-headline" id="Fugitive">Fugitive</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=23" title="Edit section: Fugitive">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><b>:Git</b> - Yeah, right
- </p><p><b>:Gremove</b> - Remove file and update index, refresh buffer
- </p><p><b>:Gmove target_path</b> - Actual moving, relative to current file (":Gmove /path" will move from root of repo)
- </p><p><b>:Gwrite</b> - Add file to index
- </p><p><b>:Gread</b> - Checkout file
- </p><p><b>:Gblame</b> - Git blame
- </p>
- <h2><span class="mw-headline" id="More_of_these.2C_please">More of these, please</span><span class="mw-editsection"><span class="mw-editsection-bracket">[</span><a href="/index.php?title=Vim&action=edit&section=24" title="Edit section: More of these, please">edit</a><span class="mw-editsection-bracket">]</span></span></h2>
- <p><a rel="nofollow" class="external free" href="http://vimawesome.com/">http://vimawesome.com/</a>
- </p><p><a rel="nofollow" class="external free" href="http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about?rq=1">http://stackoverflow.com/questions/726894/what-are-the-dark-corners-of-vim-your-mom-never-told-you-about?rq=1</a>
- </p><p><a rel="nofollow" class="external free" href="http://rayninfo.co.uk/vimtips.html">http://rayninfo.co.uk/vimtips.html</a>
- </p><p><a rel="nofollow" class="external free" href="http://vim.wikia.com/wiki/Vim_Tips_Wiki">http://vim.wikia.com/wiki/Vim_Tips_Wiki</a>
- </p><p><b>:help <command></b>
- </p>
- <!--
- NewPP limit report
- CPU time usage: 0.016 seconds
- Real time usage: 0.017 seconds
- Preprocessor visited node count: 94/1000000
- Preprocessor generated node count: 100/1000000
- Postβexpand include size: 0/2097152 bytes
- Template argument size: 0/2097152 bytes
- Highest expansion depth: 2/40
- Expensive parser function count: 0/100
- -->
- <!-- Saved in parser cache with key wiki:pcache:idhash:20-0!*!*!!en!*!* and timestamp 20141210153325 and revision id 349
- -->
- </div> <div class="printfooter">
- Retrieved from "<a href="http://wiki.xxx.com/index.php?title=Vim&oldid=349">http://wiki.xxx.com/index.php?title=Vim&oldid=349</a>" </div>
- <div id="catlinks" class="catlinks catlinks-allhidden"></div> <div class="visualClear"></div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment