/vía: https://www.catswhocode.com/blog/vim-cheat-sheet-for-2016
/vía:http://www.catswhocode.com/blog/130-essential-vim-commands
~/.vim/autoload (ubicación vim-pathogen.vim) y ~/.vim/bundle (home_directory de los plugins)execute pathogen#infect()cd ~/.vim/bundle git clone https://github.com/millermedeiros/vim-statline.git
# cambiar editor por defecto $ sudo update-alternatives --config editor
:e filename : Open filename for edition:w : Save file:q : Exit Vim:q! : Quit without saving:x : Write file (if changes has been made) and exit:sav filename : Saves file as filename. : Repeats the last change made in normal mode5. : Repeats 5 times the last change made in normal mode0 : move the cursor to the begining of the lineG o $ : move the cursor to the end of the filegg : move the cursor to the begining of the file:59 : move cursor to line 59. Replace 59 by the desired line number.k or Up Arrow : move the cursor up one linej or Down Arrow : move the cursor down one linee : move the cursor to the end of the wordb : move the cursor to the begining of the wordL : move the cursor to the bottom of the screen20| : move cursor to column 20.% : Move cursor to matching parenthesis[[ : Jump to function start[{ : Jump to block starty : Copy the selected text to clipboardp : Paste clipboard contentsdd : Cut current lineyy : Copy current liney$ : Copy to end of lineD : Cut to end of line/word : Search word from top to bottom?word : Search word from bottom to top* : Search the word under cursor/\cstring : Search STRING or string, case insensitive/jo[ha]n : Search john or joan/\< the Search the, theatre or then/the\> : Search the or breathe/\< the\> : Search the/\< ¦.\> : Search all words of 4 letters/\/ : Search fred but not alfred or frederick/fred\|joe : Search fred or joe/\<\d\d\d\d\> : Search exactly 4 digits/^\n\{3} : Find 3 empty lines:bufdo /searchstr/ : Search in all open filesbufdo %s/something/somethingelse/g : Search something in all the open buffers and replace it with somethingelse:[rango]s[ubstitute]/{pattern}/{string}/[flags] [count]
% : de la primera a la última línea1,3 : de la línea 1 a 33,$ : de la línea 3 al final de ficherog : global (en el ámbito, todas las sustituciones posibles)i : case insensitivec : confirmaciónstring : busca la cadena^ : principio de línea$ : final de línea:s/Bill/Steve/ : Replace the first occurence of Bill by Steve in current line:s/Bill/Steve/g : Replace Bill by Steve in current line:2,35s/old/new/g : Replace all occurences between lines 2 and 35:5,$s/old/new/g : Replace all occurences from line 5 to EOF:%s/old/new/g : Replace all occurences of old by new in file:%s/onward/forward/gi : Replace onward by forward, case unsensitive:%s/old/new/gc : Replace all occurences with confirmation:%s/^/hello/g : Replace the begining of each line by hello:%s/$/Harry/g : Replace the end of each line by Harry:%s/onward/forward/gi : Replace onward by forward, case unsensitive:%s/ *$/ /g : Delete all white spaces:%s/Bill/Steve/g : Replace Bill by Steve in all the file:%s/^M/ /g : Delete DOS carriage returns (^M):%s#\s#\r#g : cambia espacios (\s) por saltos de línea (\r) en todo el texto. Usamos # como separador:%s/\r/\r/g : Transform DOS carriage returns in returns:%s#<[^>]\+>##g : Delete HTML tags but keeps text:%s/^\(.*\)\n\1$/\1/ : Delete lines which appears twice:g/string/d : Delete all lines containing stringg/^$/d : borra líneas en blanco → v/./dg/^\s*$/d : borra líneas en blanco o con espacios/tabuladores:v/string/d : Delete all lines containing which didn’t contain stringCtrl+a : Increment number under the cursorCtrl+x : Decrement number under cursorggVGg? : Change text to Rot13Vu : Lowercase lineVU : Uppercase lineg~~ : Invert casevEU : Switch word to uppercasevE~ : Modify word caseggguG : Set all text to lowercasegggUG : Set all text to uppercase:%s/\<./\u&/g : Sets first letter of each word to uppercase:%s/\<./\l&/g : Sets first letter of each word to lowercase:%s/.*/\u& : Sets first letter of each line to uppercase:%s/.*/\l& : Sets first letter of each line to lowercase:1,10 w outfile : Saves lines 1 to 10 in outfile:1,10 w >> outfile : Appends lines 1 to 10 to outfile:r infile : Insert the content of infile:23r infile : Insert the content of infile under line 23:e . : Open integrated file explorer:Sex : Split window and open integrated file explorer:Sex! : Same as Sex but split window vertically:browse e : Graphical file explorer:ls : List buffers:cd .. : Move to parent directory:args : List files:args *.php : Open file list:grep expression *.php : Returns a list of .php files contening expressiongf : Open file name under cursor:!pwd : Execute the pwd unix command, then returns to Vi!!pwd : Execute the pwd unix command and insert output in file:sh : Temporary returns to Unix$exit : Returns to Vi:%!fmt : Align all lines!}fmt : Align all lines at the current position5!!fmt : Align the next 5 linesvim -p <archivo1> <archivo2>:tabnew : Creates a new tab:tabe[dit] <file> : abre <file> en nuevo tab:tabf[ind] <file>: abre <file> en nuevo tab buscando por el path:set path=.,,** : busca en la ubicación del archivo, en el directorio actual y en los subidrectorios:tabclose:tabonly : cierra todos los tabs menos el actual:tab split: duplica el tab actual:tabdo %s/foo/bar/g : Execute a command in all tabs:tab ball : Puts all open files in tabs:new abc.txt : Edit abc.txt in new window:qa o wqa : salir de todas las pestañasgt : Show next tab:tabn^PgUpgT : Show previus tab:tabp : Show previus tab^PgDw:tabs : muestra todos los tabs:tabfirst : Show first tab:tablast : Show last tab:tabm n : reorganizar tabs0 : mover actual a la primera posición : mover actual a la última posiciónn : mover actual a la posición n:e filename : Edit filename in current window:split filename : Split the window and open filenamectrl-w up arrow : Puts cursor in top windowctrl-w ctrl-w : Puts cursor in next windowctrl-w_ : Maximize current window verticallyctrl-w| : Maximize current window horizontallyctrl-w= : Gives the same size to all windows10 ctrl-w+ : Add 10 lines to current window:vsplit file : Split window vertically:sview file : Same as :split in readonly mode:hide : Close current window:nly : Close all windows, excepted current:b 2 : Open #2 in this windowCtrl+n Ctrl+p (in insert mode) : Complete wordCtrl+x Ctrl+l : Complete line:set dictionary=dict : Define dict as a dictionnaryCtrl+x Ctrl+k : Complete with dictionnarym {a-z} : Marks current position as {a-z} ' {a-z} : Move to position {a-z} ' ' : Move to previous position:ab mail mail@provider.org : Define mail as abbreviation of mail@provider.orgctrl-t, ctrl-d : Indent/un-indent in insert mode» : Indent« : Un-indent=% : Indent the code between parenthesis1GVG= : Indent the whole file:X : pregunta por contraseña para cifrar el fichero a la hora de guardar:setlocal cm? : show encryption method for the current file (cm abreviación de cryptmethod:setlocal cm=zip : weak (default for backwards-compatibility):setlocal cm=blowfish : better:setlocal cm=blowfish2 : best (requires Vim version 7.4.399 or higher)permite modificar el comportamiento del editor (emacs o vim - u otros?) con líneas con estructura
por defecto (y razones de seguridad) viene desactivado. Se han de cumplir estas condiciones:
set modeline está activo (y no set nomodeline)modelines ≠ 0
:verbose set modeline? modelines?: mirar si está activo
:e $MYVIMRC set modeline set modeline=5
set (no)ignorecase [ic]set (no)hlsearch [hls] : marca la búsquedaset (no)incsearch [is]set (no)showmatch [sm]set (no)ignorecase [ic]set (no)incsearch [is]:set (no)autoindent [ai] : Turn on auto-indent:set smartindent [si] : Turn on intelligent auto-indent:set shiftwidth=4 : Defines 4 spaces as indent size:syntax on : Turn on syntax highlighting:syntax off : Turn off syntax highlighting:set syntax=perl : Force syntax highlightingset (no)cursorline [cul]: línea del cursor «subrayada»" \c para activar/desactivar :hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white :hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white :nnoremap <Leader>c :set cursorline! cursorcolumn!<CR>
set (no)number [nu]: numeración de líneasset (no)ruler [ru]: muestra información de posición del cursor y % de la páginaset (no)invlist : muestra caracteres especialesset (no)paste : evita autoindentación de código «pegado»set pastetoggle=<F2>set (no)list : visualiza caracteres «ocultos» según establecido: set listchars=space:·,eol:$,tab:>-,trail:~,extends:>,precedes:< [lcs]: help listchars [lcs]set pastetoggle=<F2> set showmode</code
:set smartcase Ignore case in searches excepted if an uppercase letter is used:set key=<password> : otra manera de establecer contraseña (se ve la pass, se puede poner en fichero .vimrc)