Showing posts with label Delete. Show all posts
Showing posts with label Delete. Show all posts

23 May 2022

How to delete all the lines which contain a pattern in vim?

https://vim.fandom.com/wiki/Delete_all_lines_containing_a_pattern



The ex command g is very useful for acting on lines that match a pattern. You can use it with the d command, to delete all lines that contain a particular pattern, or all lines that do not contain a pattern.

For example, to delete all lines containing "profile" (remove the /d to show the lines that the command will delete):

:g/profile/d

More complex patterns can be used, such as deleting all lines that are empty or that contain only whitespace:

:g/^\s*$/d

To delete all lines that do not contain a pattern, use g!, like this command to delete all lines that are not comment lines in a Vim script:

:g!/^\s*"/d

Note that g! is equivalent to v, so you could also do the above with:

:v/^\s*"/d

The next example shows use of \| ("or") to delete all lines except those that contain "error" or "warn" or "fail" (:help pattern):

:v/error\|warn\|fail/d

05 September 2021

How to Delete Lines in Vim / Vi

How to Delete Lines in Vim / Vi 

 https://linuxize.com/post/vim-delete-line/

 

 Deleting a Line

The command to delete a line in Vim is
  dd .

Below are step-by-step instructions to delete a line:

    Press the Esc key to go to normal mode.
    Place the cursor on the line you want to delete.
    Type 
d and hit Enter to remove the line.

Pressing dd multiple times will delete multiple lines.
Deleting Multiple Lines

To delete multiple lines at once, prepend the dd command with the number of lines to be deleted. For example, to delete five lines you would do the following:

    Press the Esc key to go to normal mode.
    Place the cursor on the first line you want to delete.
    Type 
5dd  and hit Enter to delete the next five lines.

Delete a range of lines

The syntax for deleting a range of lines is as follows:

  :[start],[end]d 

For example, to delete lines starting from 3 to 5 you would do the following:

    Press the Esc key to go to normal mode.
    Type 
:3,5d  and hit Enter to delete the lines.

You can also use the following characters to specify the range:

    . (dot) - The current line.
    $ - The last line.
    % - All lines.

Here are a few examples:

    :.,$d - From the current line to the end of the file.
    :.,1d - From the current line to the beginning of the file.
    :10,$d - From the 10th line to the end of the file.

Delete All Lines

To delete all line you can use either the % symbol that represents all lines or the 1,$ range:

    Press the Esc key to go to normal mode.
    Type  
:%d  and hit Enter to delete all the lines.

Deleting Lines Containing a Pattern

The syntax for deleting multiple lines based on a specific pattern is as follows:


 :g/<pattern>/d 

The global command (g) tells the delete command (d) to delete all lines containing the <pattern>.

To match the lines not matching the pattern, add an exclamation mark (!) before the pattern:

 :g!/<pattern>/d

The pattern can be a literal match or regular expression . Below are some examples:

     :g/foo/d  - Delete all lines containing the string “foo”. It also removes line where “foo” is embedded in larger words, such as “football”.
    :g!/foo/d - Delete all lines not containing the string “foo”.
    :g/^#/d - Remove all comments from a Bash script. The pattern ^# means each line beginning with #.
    :g/^$/d - Remove all blank lines. The pattern ^$ matches all empty lines.
    :g/^\s*$/d - Remove all blank lines. Unlike the previous command, this also removes the blank lines that have zero or more whitespace characters (\s*).



19 September 2017

Can not delete profile

Can not delete profile

Solution:

Restart computer, and go to Safe Mode. The greyed-out Delete button would be usable.

29 August 2017

Fonts can not be deleted

Problem:

Fonts can not be deleted because it is in use

Solution:

When in the Fonts folder (or Control Panel Fonts) click:

Organize > Layout > Untick 'Details pane' > Now try deleting the font.

28 April 2015

How to create a Recycle Bin in Linux?

How to create a Recycle Bin in Linux?

Try This At first create a folder named as MyTrash under /root ie: /root/MyTrash
Then open .bashrc file and write the below line at the bottom of the file.
alias rm='mv -t /root/MyTrash/'
Here -t means
-t, --target-directory=DIRECTORY
       move all SOURCE arguments into DIRECTORY
update .bashrc file by running this command source .bashrc
Now if you delete any file using rm command that file will be moved to /root/MyTrash directory

29 August 2012