lunes, marzo 14, 2005

Manual de vim

Teclar ":help user-manual" dentro de vim.

Mi pequeño tutorial de vim



Se ha obtenido con el comando vimtutor.


Salir
:wq
:q!

Borrado
dd -> borrado linea
dw -> borrado palabra (incluyendo espacio)
de -> borrado palabra
d$ -> borrado hasta fin de linea (osea d[number])

Inserción
i -> ponerse en modo de insercion
p -> (pegar a continuacion del cursor; desde modo normal)
o -> Abre una linea por debajo
O -> Abre una linea por encima
A -> Abre al final de la linea (Append)
a -> append (a diferencia de 'i', lo hace tras la letra, i lo hace justo antes

Deshacer
u -> deshace un cambio
U -> deshace todos los cambios de la linea
CRTL-R -> rehace cambio

Ayuda
set mouse=a
Ctrol-]

Repeticion de comandos
Num -> Lo repite Num veces

Moverse
w
e
$
0
h,j,k,l o flechas de cursor

Reemplazo
r -> reemplazo de letra
R
cw -> change word
c$, ... -> osea c[number]

Location and file status
Ctrl-g -> muestra linea de informcion
shift-g -> te lleva a una linea (equivalente a :)

Buscar
/ -> forward
n -> siguiente
shift-N -> anterior
? -> backwards
:set ic -> Ignore Case
:set hls is -> Set the 'hlsearch' and 'incsearch' options
:nohlsearch -> remove the highlighting of matches


Buscar y reemplazar
:s/old/new/g
:#,#s/old/new/g -> Entre lineas (where #,# are the numbers of the two lines.)
:%s/old/new/g -> to change every occurrence in the whole file.

Leer y escribir ficheros
:r / read -> si se hace dentro de un fichero, mete el nuevo en donde este el cursor
situado
:w / write
:#,# w FILENAME -> selective write


Seleccionar
Shift-v

Cambiar Tabs por Espacios
set et
set sw=2
set smarttab

Otros
matching parenthesis or bracket: %
Ejecutar comando externo: :!

Sobre espacios y tabuladores



La configuracion que menciono antes esta sacada del siguiente Tip.
La siguiente pagina es muy interesante, va sobre la Tabs versus Spaces Holly War. De ella:

Here are some details on vi, courtesy of Woody Thrower:

Standard vi interprets the tab key literally, but there are popular vi-derived alternatives that are smarter, like vim. To get vim to interpret tab as an ``indent'' command instead of an insert-a-tab command, do this:

set softtabstop=2

To set the mod-N indentation used when you hit the tab key in vim (what Emacs calls c-basic-offset), do this:

set shiftwidth=2

To cause the TAB file-character to be displayed as mod-N in vi and vim (what Emacs calls tab-width), do this:

set tabstop=4

To cause TAB characters to not be used in the file for compression, and for only spaces to be used (what emacs calls indent-tabs-mode), do this:

set expandtab

In vi (and vim), you can do this stuff on a per-file basis using ``modelines,'' magic comments at the top of the file, similarly to how it works in Emacs:

/* ex: set tabstop=8 expandtab: */

Y finalmente una pagina que defiende los tabs.

No hay comentarios: