{"id":287,"date":"2018-10-17T07:04:04","date_gmt":"2018-10-17T07:04:04","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-line-in-vim\/"},"modified":"2018-10-17T07:04:04","modified_gmt":"2018-10-17T07:04:04","slug":"how-to-delete-line-in-vim","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-line-in-vim\/","title":{"rendered":"How to Delete Line in VIM"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" alt=\"delete lines vim editor linux\" height=\"341\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/10\/delete-lines-vim-editor-linux.png\" width=\"713\" \/><\/p>\n<p>How to delete lines from Vim? How to delete ranges of lines? How to delete lines by a given pattern? Let&#8217;s cover in this article different ways to delete lines in Vim editor.<\/p>\n<ol>\n<li>\n<ol>\n<li><a href=\"#1\">Delete a single line<\/a><\/li>\n<li><a href=\"#2\">Delete all lines<\/a><\/li>\n<li><a href=\"#3\">Delete multiple lines<\/a><\/li>\n<li><a href=\"#4\">Delete a range of lines<\/a><\/li>\n<li><a href=\"#5\">Delete lines by a given pattern<\/a><\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<h3>Install Vim in Ubuntu\/Debian distributions<\/h3>\n<p># sudo apt install vim<\/p>\n<h3>Install Vim in RHEL\/CentOS distributions<\/h3>\n<p># yum install vim<\/p>\n<h2>1) Delete a single line<br \/><\/h2>\n<p>To delete a single line in Vim editor, follow the steps below<\/p>\n<ol>\n<li>Place the cursor to the beginning of the line<\/li>\n<li>Press the ESC key.<\/li>\n<li>Next, press dd i.e quick press letter &#8216; d &#8216; twice in quick succession.<\/li>\n<\/ol>\n<p>In the example below, pressing dd at the beginning of line 6 as shown below will delete the entire line.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"delete lines in vim command\" height=\"387\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/09\/dd-command.png\" width=\"640\" \/><\/p>\n<h2>2) Delete all lines<\/h2>\n<p>Below are the two ways to delete all lines.<\/p>\n<p>:1,$d<\/p>\n<p>or<\/p>\n<p>:%d<\/p>\n<h2>3) Delete multiple lines<\/h2>\n<p>To delete multiple lines<\/p>\n<ol>\n<li>place the cursor at the beginning of a line.<\/li>\n<li>Prefix the dd command with the number of lines you want to delete below it. For example, if you want to delete 3 consecutive lines below line 3 press<br \/># 3dd<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"delete lines in vim\" height=\"386\" src=\"https:\/\/linoxide.com\/wp-content\/uploads\/2018\/09\/3dd-deleting-3-lines-below.png\" width=\"640\" \/><\/p>\n<h2>4) Delete a range of lines<\/h2>\n<p>If you want to delete a range of lines, say from line 3 to line 5, the syntax is as shown below<\/p>\n<p>:[start_line_no],[end_line_no]d<\/p>\n<p>In this case, Press ESC Then type the command below and hit Enter.<\/p>\n<p>:3,5d<\/p>\n<p>To delete the last line<\/p>\n<p>:$d<\/p>\n<p>To delete all lines before the current line<\/p>\n<p>:1,.-1d<\/p>\n<p>To delete all lines after the current line<\/p>\n<p>:.+1,$d<\/p>\n<h2>5) Delete lines by a given pattern<\/h2>\n<p>Finally, you can delete lines following a given pattern.<\/p>\n<p>For instance, to delete lines that contain a certain word, press ESC and run<\/p>\n<p>:g \/word\/d<\/p>\n<p>In our case, to delete lines that contain the word &#8220;lazy&#8221;<\/p>\n<p>:g \/lazy\/d<\/p>\n<p>To delete every line that doesn&#8217;t contain the word &#8220;lazy&#8221;<\/p>\n<p>:%g!\/lazy\/d<br \/>\nor<br \/>:v\/lazy\/d<\/p>\n<p>To delete lines that begin with a certain letter, say &#8216;A&#8217;<\/p>\n<p>:g\/^A\/d<\/p>\n<p>If you want to delete lines that begin with a special character like $ sign, prefix the character with a backslash as shown<\/p>\n<p>:g\/^$\/d<\/p>\n<p>To get rid of all blank lines<\/p>\n<p>:g\/^$\/d<\/p>\n<p>Do you have any tips to delete vim lines? Hope this article helped you and please leave your comments.<\/p>\n<h3>Read Also:<\/h3>\n<ul>\n<li><a href=\"https:\/\/linoxide.com\/tools\/amp-text-editor-linux-terminal\/\" target=\"_blank\">AMP &#8211; Fully Featured Text Editor for Linux Terminal<\/a><\/li>\n<li><a href=\"https:\/\/linoxide.com\/linux-how-to\/install-atom-text-editor-linux\/\" target=\"_blank\">How to Install Atom Text Editor in Linux<\/a><\/li>\n<li><a href=\"https:\/\/linoxide.com\/tools\/suplemon-cli-text-editor-multi-cursor\/\" target=\"_blank\">Suplemon &#8211; Modern CLI Text Editor with Multi Cursor Support<\/a><\/li>\n<li><a href=\"https:\/\/linoxide.com\/linux-how-to\/best-html-editors-linux\/\" target=\"_blank\">Top Best HTML Editors in the World of Linux<\/a><\/li>\n<\/ul>\n<p> <a href=\"https:\/\/linoxide.com\/linux-how-to\/how-to-delete-line-vim-linux\/\" target=\"_blank\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to delete lines from Vim? How to delete ranges of lines? How to delete lines by a given pattern? Let&#8217;s cover in this article different ways to delete lines in Vim editor. Delete a single line Delete all lines Delete multiple lines Delete a range of lines Delete lines by a given pattern Install &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/17\/how-to-delete-line-in-vim\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Delete Line in VIM&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-287","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/287","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=287"}],"version-history":[{"count":0,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/287\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=287"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=287"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=287"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}