Vim Tips Wiki
m (Delete words in a different way. (For Unix Admins) moved to Delete words in a different way: Page moved by JohnBot to improve title)
m (Reverted edits by 115.114.134.174 (talk | block) to last version by JohnBot)
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1498
 
|id=1498
  +
|previous=1495
|title=Delete words in a different way. (For Unix Admins)
 
  +
|next=1499
|created=February 1, 2007 1:37
+
|created=2007
 
|complexity=basic
 
|complexity=basic
|author=fomit-frame-pointer
+
|author=fomit
 
|version=5.7
 
|version=5.7
 
|rating=44/45
 
|rating=44/45
  +
|category1=
|text=
 
  +
|category2=
Often, you might want to delete a set of arguments within bash scripts in Unix/Linux environments as an admin.
 
 
}}
 
Often, you might want to delete a set of arguments within bash scripts in Unix environments as an admin.
   
So you might think "dw" (delete word) does the job, because it often does it actually. BUT! In Unix/Linux environments
+
So you might think <code>dw</code> (delete word) does the job, because it often does, actually. However, in Unix environments you might also interpret a word in a different way, e.g. a "/path/to/file" can be seen as just one word in terms of the number of arguments. In that case, "dw" will not delete "/path/to/file", instead it will interpret every slash "/" as a separate word, so you have to enter "dw" 6 times.
   
 
Instead, you can dynamically enter your own, currently needed delimiter without changing Vim's global behavior in vimrc by just typing "df " (d f space). That deletes from the cursor position to, and including, the next space.
you might also interpret a word in a different way, e.g. a "/path/to/file" can be seen as just one word in terms of the
 
   
 
You can easily adapt this style of deleting "words" by replacing space by your own character.
number of arguments. In that case, "dw" will not delete "/path/to/file", instead it will interpret every slash "/" as a seperate
 
   
 
Maybe you want to delete a whole sentence, then you want to type "df.". There are many thinkable usages.
word, so you have to enter "dw" 6 times.
 
   
 
==Comments==
 
You can also use dW (capital W) to delete a WORD, which is a number of consecutive characters, such as "/usr/bin/perl". Also check out dt<char>, which deletes up to (not including) <char>.
   
 
----
 
If you need that "f " motion often, you could also map
  +
<pre>
  +
:ono <Space> f<Space>
  +
</pre>
   
 
then delete with "d ", this is one key less.
Instead, you can dynamically enter your own, currently needed delimiter without changing vim's global behavior in .vimrc
 
   
by just typing "df " (d like Donald, f like **** and then just a whitespace). By doing this, you tell vim to interpret its current
 
 
position until the next occurance of " " (whitespace) as a word.
 
 
 
 
You can easily adapt this style of deleting "words" by replacing whitespace by your own character.
 
 
 
 
Maybe you want to delete a whole sentence, then you want to type "df.". There are many thinkable usages.
 
 
 
 
Once you get used to it you can work "yet another bit" more productive. There no limit to productivity.
 
 
 
 
Thank what i like about vi(m). :)
 
}}
 
 
== Comments ==
 
You can also use dW (capital W) to delete a WORD, which is a number of consecutive characters, such as "/usr/bin/perl". Also check out dt&lt;char&gt;.
 
 
'''Anonymous'''
 
, February 1, 2007 3:05
 
 
----
 
----
 
When you use "df ", you simply tell Vim to delete all the chars until (and including) the next space character. This is no magic, and I think it needs to be clarified for novices. The command f<char> puts the cursor on the next occurrence of <char>. This is therefore a movement command. Any movement command, combined with the operator "d" instructs Vim to delete until the new cursor position.
If you need that "f " motion often, you could also map
 
:ono &lt;space&gt; f&lt;space&gt;
 
first, and then delete with "d ", this is one key less :-)
 
 
'''Anonymous'''
 
, February 1, 2007 5:59
 
----
 
&lt;quote&gt;
 
By doing this, you tell vim to interpret its current
 
position until the next occurance of " " (whitespace) as a word.
 
&lt;/quote&gt;
 
 
This is not true. When you do that you simply tell vim to delete all the chars until (and including) the next space character. This is no magic, and I think it needs to be clarified for novices. The command f&lt;char&gt; puts the cursor on the next occurance of &lt;char&gt;. This is therefore a movement command. Any movement command, combined with the operator "d" instructs vim to delete until the new cursor position. As it has been suggested dW seems to be a more elegant way of doing this.
 
   
'''Anonymous'''
 
, February 4, 2007 1:10
 
 
----
 
----
<!-- parsed by vimtips.py in 0.485182 seconds-->
 

Revision as of 19:41, 11 March 2014

Tip 1498 Printable Monobook Previous Next

created 2007 · complexity basic · author fomit · version 5.7


Often, you might want to delete a set of arguments within bash scripts in Unix environments as an admin.

So you might think dw (delete word) does the job, because it often does, actually. However, in Unix environments you might also interpret a word in a different way, e.g. a "/path/to/file" can be seen as just one word in terms of the number of arguments. In that case, "dw" will not delete "/path/to/file", instead it will interpret every slash "/" as a separate word, so you have to enter "dw" 6 times.

Instead, you can dynamically enter your own, currently needed delimiter without changing Vim's global behavior in vimrc by just typing "df " (d f space). That deletes from the cursor position to, and including, the next space.

You can easily adapt this style of deleting "words" by replacing space by your own character.

Maybe you want to delete a whole sentence, then you want to type "df.". There are many thinkable usages.

Comments

You can also use dW (capital W) to delete a WORD, which is a number of consecutive characters, such as "/usr/bin/perl". Also check out dt<char>, which deletes up to (not including) <char>.


If you need that "f " motion often, you could also map

:ono <Space> f<Space>

then delete with "d ", this is one key less.


When you use "df ", you simply tell Vim to delete all the chars until (and including) the next space character. This is no magic, and I think it needs to be clarified for novices. The command f<char> puts the cursor on the next occurrence of <char>. This is therefore a movement command. Any movement command, combined with the operator "d" instructs Vim to delete until the new cursor position.