Mutiple Windows with VIM »

Abreviaciones dentro del Editor Vim ,Search and Replace text

11.12.10

  10:53:00 by admin, Categories: Editores, Vi, Vim, otros.

copiar bloque rapido : marcamos linea por lina shift+v , seleccionamos bloque, pulsamos Y  y Esc pegamos con P

 

para ir a la linea de comandos     Esc + :

para ir a una linea determinada  :#de linea

 

Vi: Search and Replace

Change to normal mode with <ESC>.

Search (Wraped around at end of file):

  Search STRING forward :   / STRING.
Search STRING backward: ? STRING.

Repeat search: n
Repeat search in opposite direction: N (SHIFT-n)


Replace: Same as with sed, Replace OLD with NEW:

 
First occurrence on current line: :s/OLD/NEW

example on centos %s/keysLOGINdsa/mikrotik\/keysLOGINdsa/g --> look as i use the scaping characters \/

Globally (all) on current line: :s/OLD/NEW/g or
:%s/OLD/NEW/g
Between two lines #,#: :#,#s/OLD/NEW/g

Every occurrence in file: :%s/OLD/NEW/g


Vi ---> Search and Replace

The search command is /. To search for polite type /polite. n repeats the search in the same direction, and N repeats the search in the opposite direction.

The search option accepts most of the standard Unix pattern matching language. (See the Wildcard section.) Suppose I had a file that contained the following text:

There was a young man of Milan
Whose poems, they never would scan;
When asked why it was,
He said, `It's because
I always try to get as many words into the last line as I possibly can'.
-anonymous

Here are a few examples (using this text) that you will probably never use but may find inspiring:


/[a-z]as

will search for any lowercase letter followed by as. In this example, it would find was and last but not as or asked.


/[^c]an

will search for any an preceded by any character other than a c. In our text it would find Milan but not scan or can.


/^[A-Z].*\. *$

will search for any line that begins with a capital letter and ends with a period and any number of blanks. Our only match in the example text would be with the last line.

All of these search patterns can be used in the search and replace command that takes on the following structure:


:%s/search_string/replacement_string/g

This command replaces every search_string on the current line with replacement_string. Omitting the g (global) flag at the end of the command will cause only the first occurrence of search_string to be altered. Often you may wish to confirm each replacement. This can be done with the confirm flag c. The confirm flag should be placed after or in place of the g flag. Suppose I had the following line:

Give a skeptic and inch... and he'll take a mile.

and typed


:%s/take a mile/measure it/

I would be left with

Give a skeptic and inch... and he'll measure it.

Any command that begins with a ":" is called a line mode command and performs its duty on the line the cursor is currently on. However, you can override vi's default of operating only on the current line by preceding them with a range of line numbers. For example, if I wanted to replace guy with gal on lines 32 through 56 I would type


:32,56s/guy/gal/g


Omitting the g would cause only the first occurrence of guy in each line to be replaced. The "." and "$" play a special role in this sort of designation. "." indicates the current line, and "$" indicates the last line of the file. Therefore, if I wanted to delete1 from the current line to the end of the file I would enter:2


:.,$d

I could even do something like:


:.,/Edison/d

which would delete from the current line to the next line that contained Edison.

One other shortcut that might be worth mentioning is that 1,$ and % both indicate all the lines in the file. Therefore,


:1,$s/search_string/replacement_string/g

and


:%s/search_string/replacement_string/g

do exactly the same thing.

Please notify owners of webpages with outdated links to these pages

1 This works because :d is a line mode command that deletes the current line.
2 The same could be accomplished by typing dG.


grabar un archivo : w nombre archivo


3) Comandos de edición.

Es hora de empezar a copiar y pegar texto. tenemos multiples formas de hacerlo, os describiré algunas de ellas (todas se lanzan desde el modo comandos).
Copiar:

a) Copiar una linea: Si presionamos dos veces la letra “y” copiaremos la linea sobre la que tenemos el cursor.

b) Copiar linea visual: Seleccionas un conjunto de lineas con MAY+v y acto seguido presionamos “y”. Con ello habremos copiado el conjunto de lineas seleccionadas.

c) Copiar Bloque visual: Seleccionas un bloque de texto con CTRL+v y acto seguido presionamos “y”. Con ello habremos copiado el bloque de caracteres seleccionado.

Cortar:

a) Cortar/Borrar un caracter. Pones el cursor sobre el caracter seleccionado y presionas “x”.

b) Cortar/Borrar una linea. Presionamos dos veces la letra “d” para cortar la linea sobre la que se encuentra el cursor.

c) Cortar linea visual. Seleccionas un conjunto de lineas con MAY+v y acto seguido presionamos “d”. Se habrá cortado el conjunto de lineas seleccionadas.

d) Cortar Bloque Visual. Seleccionas un conjunto de lineas con CTRL+v y acto seguido presionamos “d”. Se habrá cortado el bloque de caracteres seleccionado.

Pegar:

a) Pegar lo que sea: Simplemente con la tecla “p”. Teneis que tener cuidado, pues en función de lo que hayais copiado/cortado así será el comportamiento de “p”.

Si has copiado una linea, “p”, pegará una linea justo despues de la linea en la que te encuentres.

Si has copiado un caracter o conjunto de caracteres, “p”, pegará ese conjunto de caracterés justo despues del caracter en el que te encuentres.. esto es, en la misma linea.



for execute a command in vim editor
:sh then out with command exit


REFERENCIAS :
http://vim.wikia.com/wiki/Main_Page

No feedback yet

Aqui relato cada una de las experiencias con LINUX

Search

Categories

All LinuXnet

Random photo

Image post

  XML Feeds

free blog software