Results 1 to 9 of 9
Hi, I am completely new to this. I have been looking around for a, "start new thread" button but cant seem to find it (which is my first question). My ...
- 01-12-2011 #1Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
how do I delete a word in a vim file
Hi, I am completely new to this. I have been looking around for a, "start new thread" button but cant seem to find it (which is my first question). My real question is, how do I delete a word in a vim file from the editor command? What I want to do is go to a specific line (36) and delete 3 words after my cursor
i.e :36 | 3dw
error: "3dw" is not a command. Ive tried ":d" this deletes teh whole line which is not what I want. Thanks
- 01-12-2011 #2forum.guy
- Join Date
- May 2004
- Location
- arch linux
- Posts
- 18,078
Hello and welcome to the forums!

I've moved your post and started a new thread with it.
You can find the answer to that and other questions about how the forums work by checking this thread:
http://www.linuxforums.org/forum/fee...ng-forums.htmloz
→ new members/users: read this first | new member faq
→ no private messages requesting computer support - post them on the forums!
→ please use the "report post" button to alert our forum admins to problematic posts rather than responding to them yourself.
- 01-12-2011 #3
Welcome to the forums!
I could of course say you want to type d3w, but better is to point you to the command `vimtutor` which will allow you to learn and practise these and other vim commands
Can't tell an OS by it's GUI
- 01-12-2011 #4Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
Thanks guys I really appreciate it.
- 01-12-2011 #5Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
Found the command I was looking for.
:%norm dw
(allows u to input command as if you were to type it).
i.e :36norm 3dw
- 01-12-2011 #6Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
ok I'm running into more problems, so i'll explain the full scope of what I am trying to do.
I have multiple documents (lets call them creation.in) and want to edit a line quickly throughout multiple directories (pathnames... /eg1/creation.in /eg2/creation.in /eg3/creation.in etc). However, I cannot search froa similar pattern as all of these will contain different values in each line but will have the same line number format. I want to be able quickly alter values between all the creation.in files. I was thinking of something like this vim */creation.in then type this in the command line "argdo: 2norm 3cw "user input here" | w
input:
0.001 D_min
0.002 D_max
0.003 D_avg
desired output:
0.001 D_min
0.004 D_max
0.003 D_avg
I want to replace the 2nd line with an input I would like to type in or a list of inputs and it can loop through and replace.
- 01-12-2011 #7Just Joined!
- Join Date
- Jan 2011
- Posts
- 4
OK, I learned something new in vi, great! But why would you want to delete words from the command mode ':' ?Found the command I was looking for.
:%norm dw
(allows u to input command as if you were to type it).
i.e :36norm 3dw
I've never had the need or desire to do that.
Edit: Just seen you were posting near the same time I was. So if your trying search and modify multiple files, why are you using vi? Just use sed.
- 01-13-2011 #8Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
I could use sed (sed -r 's/(^[[:digit:]]+\b) (that was a copy n paste from another post) but I dont know how to replace the digits with a user input or an input from an array of values so that it is pretty much recursive with argdo:
I'm trying to alter multiple files on line 36 with a user input replacement by using a 1 line type command. I want it to ask me what value I need, I type that in and it proceeds to the next file. Its very hard as there are alot of commands that produce "trailing characters" errors from the command line. I havn't really learnt the syntax to write scripts to do this yet. A 1 line recursive command would benefit me heaps (timewise). Writing the script would take too long for the things I want to do.
- 01-13-2011 #9Just Joined!
- Join Date
- Jan 2011
- Posts
- 7
This is the code I have so far in a bash file
#!/bin/bash
for f in $( ls /cs/data/arm129/BREAKAGE/breakages/resolutions/force_resolutions_cor4/ ); do
cd /cs/data/arm129/BREAKAGE/breakages/resolutions/force_resolutions_cor4/$f
echo "$f"
vim -c 36 creation.in;
echo -e "what is the new digit you want to replace the old digit with"
read new_digit
vim -c 36 creation.in
sed s//$new_digit/c
done
everything works up until the sed command. I want the new_digit to replace the digit on line 36. It enters creation.in, goes to line 36 but does not execute the sed command (or the sed command doesnt work). Does anyone have any ideas of how I can get this to work?


Reply With Quote

