{"id":25776,"date":"2022-06-29T09:18:10","date_gmt":"2022-06-29T07:18:10","guid":{"rendered":"https:\/\/www.makingscience.com\/?p=25776"},"modified":"2022-06-29T09:18:10","modified_gmt":"2022-06-29T07:18:10","slug":"introduccion-a-vim","status":"publish","type":"post","link":"https:\/\/www.makingscience.com\/es\/blog\/introduccion-a-vim\/","title":{"rendered":"Introducci\u00f3n a VIM"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Si preguntas a la gente por la experiencia\/opini\u00f3n que tienen sobre vim, solo hay dos posibilidades; o lo amas o lo odias, y esto es algo en que todos estamos de acuerdo.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Aprender vim es \u201cduro\u201d y un camino muy largo. Y es que un servidor, <\/span><span style=\"font-weight: 400;\">despu\u00e9s de usarlo durante a\u00f1os, sigue descubriendo bondades de este magn\u00edfico editor, y es por eso que os puedo contar que con un control avanzado se pueden hacer tareas complejas y largas, de manera sencilla y r\u00e1pida.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">En este art\u00edculo quiero har\u00e9 una<strong> introducci\u00f3n sobre vim y algunas de sus funciones m\u00e1s interesantes para que finalmente te animes y hagas de vim tu editor preferido.<\/strong> <\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para que cuando escuches la palabra <\/span><i><span style=\"font-weight: 400;\">nano<\/span><\/i><span style=\"font-weight: 400;\"> \u00fanicamente se te venga a la cabeza el apelativo cari\u00f1oso de Valencia \ud83d\ude00<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>\u00bfC\u00f3mo podemos instalar VIM?<\/strong><\/h3>\n<p><strong>Linux<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Depender\u00e1 de tu SO, pero el paquete a instalar es vim. \u00danicamente explicar\u00e9 los SO basados en DEB y RPM:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Deb<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">$ sudo apt-get update\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">$ sudo apt-get install vi<\/span><span style=\"font-weight: 400;\">m<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Rpm<\/span>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">$ sudo yum install vim<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>Windows<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Para descargar Vim, visita vim.org.<\/span><span style=\"font-weight: 400;\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Haga clic en la opci\u00f3n Descargar del panel izquierdo.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Haga clic en PC: opci\u00f3n MS-DOS y MS-Windows.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Descarga el instalador .exe. (En el momento de escribir este tutorial, el nombre del instalador era <\/span><i><span style=\"font-weight: 400;\">gvim82.exe<\/span><\/i><span style=\"font-weight: 400;\">).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Haga doble clic en el instalador y siga las instrucciones en pantalla para completar la instalaci\u00f3n.<\/span><\/li>\n<\/ul>\n<p><strong>MAC<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Seguramente venga de serie, pero si no, puedes instalarlo con<\/span> <a href=\"https:\/\/brew.sh\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">brew<\/span><\/a><span style=\"font-weight: 400;\">.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Brew install vim<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><strong>Qu\u00e9 significa VIM<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Vi fue el primer editor de texto screen-oriented creado para Unix, fue dise\u00f1ado para ser simple pero poderoso en la manipulaci\u00f3n de texto.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Vim (del <\/span><a href=\"https:\/\/es.wikipedia.org\/wiki\/Idioma_ingl%C3%A9s\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">ingl\u00e9s<\/span><\/a><span style=\"font-weight: 400;\"> Vi IMproved) es la versi\u00f3n moderna y mejorada del editor de texto Vi, presente en todos los sistemas UNIX.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><strong>Por qu\u00e9 usar <\/strong><strong>VIM<\/strong><\/h3>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Es gratuito y open source.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Est\u00e1 disponible en la mayor\u00eda de plataformas.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Navegaci\u00f3n y uso sin rat\u00f3n.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Es muy ligero y r\u00e1pido.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Sin distracciones.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">Extremadamente personalizable.<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><strong>Cu\u00e1les son sus modos<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Podemos hablar de 3 grandes modos disponibles en vim: <\/span><i><span style=\"font-weight: 400;\">modo normal<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">modo insert<\/span><\/i><span style=\"font-weight: 400;\">, <\/span><i><span style=\"font-weight: 400;\">modo command<\/span><\/i><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><strong>Modo normal<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">El modo normal es en el que seguramente pasaremos la mayor parte de nuestro tiempo mientras usamos Vim.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>h<\/b><span style=\"font-weight: 400;\"> mueve el cursor un car\u00e1cter a la izquierda.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>j<\/b><span style=\"font-weight: 400;\"> mueve el cursor una l\u00ednea hacia abajo.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>k<\/b><span style=\"font-weight: 400;\"> mueve el cursor una l\u00ednea hacia arriba.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>l<\/b><span style=\"font-weight: 400;\"> mueve el cursor un car\u00e1cter a la derecha.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>0<\/b><span style=\"font-weight: 400;\"> mueve el cursor al principio de la l\u00ednea.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>$<\/b><span style=\"font-weight: 400;\"> mueve el cursor al final de la l\u00ednea.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>w<\/b><span style=\"font-weight: 400;\"> avanza una palabra.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>b<\/b><span style=\"font-weight: 400;\"> retrocede una palabra.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>G<\/b><span style=\"font-weight: 400;\"> mueve al final del archivo.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>gg<\/b><span style=\"font-weight: 400;\"> mover al principio del archivo.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>^<\/b><span style=\"font-weight: 400;\"> moverse al primer car\u00e1cter que no est\u00e1 en blanco de una l\u00ednea.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H<\/b><span style=\"font-weight: 400;\"> nos movemos a la parte superior de la pantalla.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>M<\/b><span style=\"font-weight: 400;\"> nos movemos al centro de la pantalla.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>L<\/b><span style=\"font-weight: 400;\"> nos movemos a la parte inferior de la pantalla.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Tambi\u00e9n podemos mezclar un n\u00famero con una de estas acciones con el fin de de repetir <\/span><i><span style=\"font-weight: 400;\">n<\/span><\/i><span style=\"font-weight: 400;\"> veces dicha acci\u00f3n (salvo las que te llevan a una posici\u00f3n fija como puede ser ir al final del fichero o ir al principio de una l\u00ednea, por m\u00e1s veces que lo pulses el resultado es siempre el mismo).<\/span><\/p>\n<p><b>Ejemplo:\u00a0<\/b><\/p>\n<p><b>5w<\/b><span style=\"font-weight: 400;\"> -&gt; avanzaremos 5 palabras<\/span><\/p>\n<p><b>12k<\/b><span style=\"font-weight: 400;\">-&gt; subiremos el cursor 12 l\u00edneas hacia arriba.<\/span><\/p>\n<p><b>\ud83d\udca1 Tip: <\/b><span style=\"font-weight: 400;\">Para realizar una operaci\u00f3n de deshacer, presionamos <\/span><b>u<\/b><span style=\"font-weight: 400;\"> en el modo normal. Esto deshace los cambios hasta la \u00faltima vez que estuvo en modo normal. Si desea rehacer (es decir, deshacer su deshacer) presione <\/span><b>Ctrl+r <\/b><span style=\"font-weight: 400;\">en modo normal.<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Modo Insert<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">Este es el segundo modo que m\u00e1s usaremos y ser\u00e1 el que m\u00e1s familiar nos resulte, ya que nos recuerda a un editor de texto est\u00e1ndar. Una vez en el modo de insert, cuando escribamos insertaremos caracteres como un editor de text. Para entrar en modo de inserci\u00f3n tenemos 6 maneras.\u00a0<\/span><\/p>\n<ul>\n<li><b>i<\/b><span style=\"font-weight: 400;\"> entramos en modo insert antes del cursor.<\/span><\/li>\n<li aria-level=\"1\"><b>I<\/b><span style=\"font-weight: 400;\"> entramos en modo insert al comienzo de la l\u00ednea actual.<\/span><\/li>\n<li aria-level=\"1\"><b>a <\/b><span style=\"font-weight: 400;\">entramos en el modo insert a\u00f1adiendo despu\u00e9s del cursor<\/span><\/li>\n<li aria-level=\"1\"><b>A <\/b><span style=\"font-weight: 400;\">entramos en el modo insert al final de la l\u00ednea.<\/span><\/li>\n<li aria-level=\"1\"><b>o <\/b><span style=\"font-weight: 400;\">inserta una nueva l\u00ednea debajo de la l\u00ednea actual y entra en el modo de insert en la nueva l\u00ednea<\/span><\/li>\n<li aria-level=\"1\"><b>O <\/b><span style=\"font-weight: 400;\">inserta una nueva l\u00ednea encima de la actual y entra en el modo de inserci\u00f3n en la nueva l\u00ednea<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>Modo Command<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">En el modo command tenemos una gran diversidad de comandos y podemos hacer cosas que no ser\u00edan tan f\u00e1cil hacer en el modo insert, o incluso directamente otras que directamente no podr\u00edamos.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Para entrar al modo command, pulsamos<\/span><b> &#8216;:&#8217; <\/b><span style=\"font-weight: 400;\">(dos puntos) desde el modo normal y luego escribimos nuestro comando (el cual podemos ver que va apareciendo en la parte inferior de la terminal). Uno de los comandos m\u00e1s pr\u00e1cticos y que m\u00e1s utilizaremos en nuestro d\u00eda a d\u00eda es el de \u201c<\/span><i><span style=\"font-weight: 400;\">buscar y reemplazar<\/span><\/i><span style=\"font-weight: 400;\">\u201d: <\/span><b>:%s\/hola\/adios\/gc<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>: <\/b><span style=\"font-weight: 400;\">Entramos en modo command<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>%<\/b><span style=\"font-weight: 400;\"> Indicamos en todo el fichero (por podemos poner 4,19 y solo aplicar\u00edamos a las l\u00edneas comprendidas entre la n\u00famero 4 y la 19).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>s<\/b><span style=\"font-weight: 400;\"> indicamos que sustituya.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\/hola\/<\/b><span style=\"font-weight: 400;\"> cadena de texto que queremos reemplazar.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\/adios\/<\/b><span style=\"font-weight: 400;\">\u00a0 cadena de texto que dejaremos.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>g<\/b><span style=\"font-weight: 400;\"> significa global, de lo contrario solo se ejecutar\u00eda una vez por l\u00ednea.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>c<\/b><span style=\"font-weight: 400;\"> pide confirmaci\u00f3n antes de realizar la sustituci\u00f3n de cada reemplazo, de lo contrario, har\u00e1 todas de manera y sin preguntar.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Una de las preguntas de <\/span><a href=\"https:\/\/stackoverflow.com\/questions\/11828270\/how-do-i-exit-the-vim-editor\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">stackoverflow<\/span><\/a><span style=\"font-weight: 400;\"> con m\u00e1s audiencia, y por la que todos hemos pasado (y muchos nos hemos quedado \u201catrapados\u201d), es la manera de salir de un fichero una vez abierto con vim.<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>:q<\/b><span style=\"font-weight: 400;\"> salimos del fichero si no se han realizado modificaciones.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>:q!<\/b><span style=\"font-weight: 400;\"> salimos salir sin guardar.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>:wq<\/b><span style=\"font-weight: 400;\"> guardamos y salimos.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>:wq! <\/b><span style=\"font-weight: 400;\">guardamos y salimos incluso si el archivo solo tiene permiso de lectura.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>\ud83d\ude21<\/b><span style=\"font-weight: 400;\"> guardamos y salimos (similar a :wq, pero solo escribe si han realizado cambios).<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Este ha sido un primer acercamiento a vim, pero si te has quedado con ganas de m\u00e1s, no te pierdas nuestra pr\u00f3xima<\/span><span style=\"font-weight: 400;\"> entrada en la que haremos una introducci\u00f3n a un nivel m\u00e1s avanzado, en el que veremos verbos, nombres y modificadores. No te lo puedes perder \ud83d\ude80<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Si preguntas a la gente por la experiencia\/opini\u00f3n que tienen sobre vim, solo hay dos posibilidades; o lo amas o lo odias, y esto es algo en que todos estamos de acuerdo. Aprender vim es \u201cduro\u201d y un camino muy largo. Y es que un servidor, despu\u00e9s de usarlo durante a\u00f1os, sigue descubriendo bondades de [&hellip;]<\/p>\n","protected":false},"author":40,"featured_media":25778,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[328,327],"class_list":["post-25776","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology-ai","tag-editor","tag-vim"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/posts\/25776","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/comments?post=25776"}],"version-history":[{"count":0,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/posts\/25776\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/media\/25778"}],"wp:attachment":[{"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/media?parent=25776"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/categories?post=25776"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.makingscience.com\/es\/wp-json\/wp\/v2\/tags?post=25776"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}