![]() |
Feel free with Open Source SoftwareAndries Filmer - Internet professional sinds 1996.
|
|
|
|
Vim Cheatsheat - Een geweldige editor met een lange leer curveHet is een editor met een leer curve. Je gaat Vim waarderen als je veel met terminals werkt. Vim is een editor met meerdere modes
Met 'Esc' ga je altijd naar 'command mode'. En met het commando :q! sluit je een bestand zonder wat te doen.
Basicsvim filename " Open filename :E " Open Explorer, o Open in new window, O Open in previous window i " enter insert mode so you can start typing Esc " leave insert mode , back to command mode G " goto end of file :54 " goto line 54 dd " cut current line yy " copy current line u " undo Ctrl+r " redo . " repeat :w " save file :wq " save file and quit :<command> " runs named command: Example :q! :help word " shows help on word: Typing Ctrl+d after word shows all entries containing word
Search / replace
/regexp " searches forwards for regexp, ? reverses direction n " repeat search, N reverses direction * " searches forward for word under cursor, # reverses direction :%s/foo/bar/gc " search for 1 and replace with 2, options are: g = global (entire file), c = confirm change
Search and replace path'sUsing a another separator ":" is useful when doing file path search and replace. This way you don't have to escape every "/" with "\/".
:%s:/dir1/dir2/dir3/file:/dir1/dir4/dir5/file1:gc
Replace spaces
:%s/\s\+$// " Delete all trailing whitespace (at the end of each line) with :%s/^\s\+// " More rarely, you might want to delete whitespace at the beginning of each line
Visual mode
v " select visually, use cursor keys Shift+v " select lines Ctrl+v " select column ~ " Switch case, lower to upper or upper to lower case D " cut selection y " copy selection p " paste (after cursor), P is paste before cursor > " indent section < " unindent section, remember . to repeat and u to undo gq " format lines to 'textwidth' length
Visual block mode
Copy text in column
Insert text in column
Windows:sp " split window horizontal :sv " split window vertical CTRL-W <DOWN> " Move to window down CTRL-W <UP> " Move to window up :q " Quit window, :close Close window :new " Open new window, :vne for new vertical window :help windows " More help for windows
Tabsvim -p file1 file2 file3 " open files in tabs
:tabnew <filename> " Open file in new tab :tabf file* " Findtab :tabn " Nexttab :tabp " previoustab :tabr " Po to the first tab :tabl " Go to the last tab :tabm n " tab move to the position n :tabdo %s/foo/bar/g " Command in all tabs :help tab-page-intro " More help for tabs
Marks
m{a-z} " Mark position as {a-z} E.g. ma
'{a-z} " Move to position {a-z} E.g. 'a
'' " Move to previous position
:marks " Print active marks
Set options:set wrap " Wrapping on :set nowrap " Wrapping off Or make them permanent in ~/.vimrc .vimrcMy default .vimrcset paste " Set paste mode, prevent accumulation of tabs and #'s set incsearch " Set increase search, Search while you type set ignorecase " Set ignore case, Search case insensitive set list " See end of line's set list listchars=tab:»·,trail:· " Make tabs visual: »....... set encoding=utf-8 "set number " Set line numbers, default commented out "set wrap " Wrapping on, default commented out
sudoAls je tijdens het opslaan merkt dat je niet genoeg privileges hebt is er een snelle oplossing door in Vim de volgende one-liner als commando in te geven:
:w !sudo tee % Daarna merkt Vim dat het bestand 'extern' aangepast is, en accepteer je de wijzigingen door op L (voor Load File) te drukken. Plugin's
FavorietenDownload [http://www.vim.org/scripts/download_script.php?src_id=1744 FavEx plugin]
:FF " Add Favorite File :FD " Add Favorite Directory :FE " Favorits Explorer :FS " Favorits Split
SurroundHandig om tags te maken, veranderen of te verwijderen.Verwijder de tag op de regel dst Een tag toevoegen Vs<p> of viws<a href=''> of een tag aanpassen viws<div> http://www.vim.org/scripts/script.php?script_id=1697
MatchitDeze plugin is handig om tussen tags, brackets of haakjes te springen. Ga in een tag, bracket of tussen haakjes staan en druk op "%". http://www.vim.org/scripts/script.php?script_id=39
phpFoldingKlapt classes, funkties dicht en open. http://www.vim.org/scripts/script.php?script_id=1623
Versleutelde bestanden bewerkenAls je versleutelde bestanden wilt bekijken of aanpassen, dan ben je waarschijnlijk geneigd om ze eerst te ontsleutelen en ze daarna te openen in je favoriete editor. Gebruik je als editor Vim en voor het versleutelen GnuPG, dan handelt de GnuPG-plugin dit allemaal transparant af. De installatie van de plugin is eenvoudig: kopieer het bestand gnupg.vim naar de directory $HOME/.vim/plugin. Daarna voeg je de volgende regel toe aan .bashrc.
export GPG_TTY=`tty`
Advanced
Order textShift current line and next 8 lines to right shiftwidth spaces9>> Shift current line and next 8 lines to left shiftwidth spaces 9<<
Numbering lines in a fileA neat filtering trick using the 'nl' linux/unix program.
:%! nl -ba
Macros
qa " starts recording the macro 'a' q " stops recording the macro <num>@a " repeat the macro <num> number of times One way to use this is to create a number list
insert 1 " goto insert mode and write 1 qa yy p CTRL-A " on the new line to convert the 1 to a 2 q 20@a Voila! You have number 1 to 22 pasted in your file So typically the keysequence would be 'i, 1., [esc], qa, yy, p, [CTRL-A], q, 20@a'
Small macro:set abbr netexpo Netexpo Internet Services B.V.
Tabs and Spaces
An endless argument in editors is whether to insert tabs or spaces while
writing code. In order to satisy people on both sides, vim can be set to do
exactly what people want. The 'expandtab' option when unset inserts tabs when
you press the
For people trying to meet the people on the other side, we can do the following steps to..
1 - Convert tabs to spaces
2 - Convert spaces to tabs
In order to visualize the above actions, it is useful to do ':set list'
which turns on invisible characters (spaces, tabs, end of line etc).
Ik zou heel leuk vinden als je laat weten wat je van deze pagina vindt. Plaats gerust commentaar. |
|
Andries Filmer | http://andries.filmer.nl | andries@filmer.nl | © 2011
|