Article 5DBEE Giving vim commands from a script

Giving vim commands from a script

by
salmanahmed
from LinuxQuestions.org on (#5DBEE)
Hi
I am using 'qmv' for renaming multiple files. 'qmv' opens the directory listing in "nano" so that one can make necessary changes and after exiting, the changes are applied. However, 'qmv' can be made to open 'vim' as text editor for advance editing with the help of following command:
Code:qmv -e vim -f doAfter opening the directory listing in 'vim', I give following commands to 'vim':
Code:1) :%s/^.\{0,5\}// ## To Delete First 5 characters
2) :%s/\%13c/BLA/g ## To insert BLA at 13th character place
3) :g/BLA/norm nD ## To delete BLA till end of line/file name
4) :%s/\%13c/.docx/g ## To insert .docx at the end of line/file nameAfter giving these commands, when I close 'vim' (:wq), it applies all these changes to my files, and I get the desired results.
However, I am trying to create a script which can do all this by itself. In this respect, I created following script:
Code:#!/bin/bash
(
## Remove Fist 5 characters
:%s/^.\{0,5\}//

## Adding BLA at 13th place
:%s/\%13c/BLA/g

## Removing BLA till end
:g/BLA/norm nD

## Add .docx at 13th place
:%s/\%13c/.docx/g

## Quit qmv
:wq
) | qmv -e vim -f doBut the script is now working and giving errors like:
Code:/fixnames: line 5: :%s/^.{0,5}//: No such file or directory
./fixnames: line 8: :%s/%13c/BLA/g: No such file or directory
./fixnames: line 11: :g/BLA/norm: No such file or directory
./fixnames: line 14: :%s/%13c/.docx/g: No such file or directory
./fixnames: line 17: :wq: command not found
Vim: Warning: Input is not from a terminal
Plan is empty (no changes made).What mistake I am doing here? Is it possible to give commands to 'vim' like this? Kindly help me to fix this.latest?d=yIl2AUoC8zA latest?i=G7QtPqy9SD8:VUpenf9k8PU:F7zBnMy latest?i=G7QtPqy9SD8:VUpenf9k8PU:V_sGLiP latest?d=qj6IDK7rITs latest?i=G7QtPqy9SD8:VUpenf9k8PU:gIN9vFwG7QtPqy9SD8
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments