8

If any of the globs has no match, in zsh, the command will be aborted. This means you need to escape your globs. I suggest you use shellescape() to build your 'grepprg' command. let &grepprg='grep -n -R --exclude=' . shellescape(&wildignore) . ' $*' For more help see: :h 'grepprg' :h shellescape() man zshexpn Alternatives to grep Have you ...


7

From :help todo: Substitute with hex/unicode number "\%xff" and "\%uabcd". Just like "\%uabcd" in search pattern. In other words, this isn't implemented yet. You can do it interactively, in Vim. See :help 24.8. Type :%s/ /, then type Ctrl-V, then x19, then press Enter.


7

There is a better way of accomplishing the task you showed in ex mode, which is by using the :delete command and a basic cmdline-range. To delete all lines between and including the beginning of the file and the search match, you can do this: 1,/dd/delete If you don't want to include the matched line in the deletion, you can do this 1,/dd/-1delete The ...


6

If you want bulletproof, you probably want something a little more portable than the complicated options above. I would stick to POSIX features of ex and make it stupid-simple: Just remove the line if it's there (regardless of how many times it's there), add it to the end of the file, then save and exit: ex -sc 'g/^export PATH=\~\/\.composer\/vendor\/bin:\$...


5

The commands are executed serially, which means that before the 4pu_ command is executed, a newline has already been added and your previous line 4 is now line 5. There are at least three ways to solve this: Start from the back. This way, previous changes do not affect later changes. As suggested by Christian Brabrandt, you can add newlines based on a ...


5

:help E30 states The command-line is only stored in this register when at least one character of it was typed. Thus it remains unchanged if the command was completed from a mapping. It seems like Vim is not considering commands specified via + (or -c) to be typed, so ": isn't updated. I'm not sure if that's expected behavior or just an oversight.


5

Update: The easiest portable way to do this is: printf '%s\n' %s/e//g x | ex file This avoids error conditions discussed below. Original Answer One of the advantages of ex as opposed to Vim is that ex is guaranteed by POSIX. If you're in the sysadmin world and you need to script automated edits to text files (e.g. configuration files to be edited ...


5

You can use :v, e.g. something like this should work: :v/^Foo/s/.*=\zs\d$/0/g


5

You can use <C-b> to go to the beginning of the line; from :help c_CTRL-B: CTRL-B or <Home> c_CTRL-B c_<Home> c_Home cursor to beginning of command-line If you want, you can use this to map it to <C-a>: :cnoremap <C-a> <C-b> Related: How can I use Readline shortcuts in the ...


4

An "ex command" means anything that you type in the commandline after the :, such as :write, it doesn't really have anything to do with "ex mode", as such. ex mode is a "mode" where you only have the commandline, and not the graphical editor ("vi" stands for "visual ex mode"). So it's really as simple as: vim -c ':%s/e//g' -c ':wq' file.txt There's no ...


3

Here is a solution which comes from here. Note that might not be exactly what you're looking for since it's implies to use a visual (or normal) mode mapping instead of just an ex command. The idea is to create the following mapping which will allow you to keep in your buffer only the visually selected lines: vnoremap <key> :<C-U>1,'<-1:...


3

You don't need a plugin for that, the functionality is built into Vim: function! RemoveAllBreakPoints() let view = winsaveview() write g/\v^\s+(import pdb|pdb.set_trace)/d call winrestview(view) endfunction Reference: :help winsaveview() :help winrestview()


3

There are some problems here. First ex is made for interactive use. You can't use several -c commands. Second, and this is a specialty of the :g command, you can't separate several commands using the '|'. A :g/127/d|wq command would write and quit after the first match) This makes it effectively useless to add another command after the -c command. What works ...


3

I imagine there must be an easier way. Since @: is accessing a special register, you can use registers yourself: $ vim -Nesc ":let @a = '/_exclude/s///p'" +@a +@a +wq foo features[rules_config][] = rule1 features[rules_config][] = rule2


3

Vim In Vim you can match any character including newline with \_.. You can use this to construct a pattern that matches a whole line, any amount of stuff, and then that same line: /\(^.*$\)\_.*\n\1$/ Now you want to delete all lines in a file that match the first, not including the first. The substitution to delete the last line that matches the first is: ...


2

A sequence of normal mode commands aborts as soon as one command (e.g. a search) fails. So, if the n jump to the next match fails (with Pattern not found: <h1>), the following vitd isn't executed. That's your condition, and it works for me that way (using Vim in Ex mode via vim -e). Note that you have another bug in your script: By first searching for ...


2

A possible solution is to create a function to do that: function! AddLine() let l:res = 0 g/export PATH=\~\/.composer\/vendor\/bin:\\\$PATH/let l:res = l:res+1 if (l:res == 0) normal G normal oexport PATH=~/.composer/vendor/bin:\$PATH endif endfunction First we create a local variable l:res which will be used to count the ...


2

Try: ex ~/.bashrc -c "if search('export PATH=\~\/.composer\/vendor\/bin:\$PATH')>0 | norm quit | endif | norm Aexport PATH=~/.composer/vendor/bin:$PATH" Note that :append won't work inside if endif-block with Ex mode (see VimDoc) so I have to put norm A... outside.


2

It would appear that the only POSIX way to do this is to use an external filter, such as sed. For example, to delete the 17th line of your file only if it is exactly identical to the 5th line, and otherwise leave it unchanged, you can do the following: :1,17!sed '5h;17{G;/^\(.*\)\n\1$/d;s/\n.*$//;}' (You could run sed on the entire buffer here, or you ...


2

Depending on your configuration you can achieve the desired result with: gq If you want to use this as a ex command you can use: normal! gqq to format the current line. Aslo, it's worth adding the flags a and c to your 'formatoption' configuration: set fo+=ac This will try to preserve the current comment formatting as well as automatically formatting ...


2

In the following range, the offset is calculated from "the current line" which may or may not be a match for /foo: :/foo/,+23# You can use ; to make the first line matching foo the first line specifier of your range: :/foo/;.,+23# which gives you three line specifiers. You can use more semicolons to refine your range: :/foo/;/bar/;/baz/#


2

Almost right below your quote from documentation it also says: When separated with ';' the cursor position will be set to that line before interpreting the next line specifier. So while there seems to be no commands that are able to accept more than two specifiers, they still can be useful to adjust starting position of other specifiers. Example ...


1

You need to enable line numbering by calling :set nu $ printf '%s\n' 'set nu' '%s/Quux/Foo/g' %p 'q!' | ex file.txt 1 Foo Bar 2 Foo Foo Bar Bar 4 Bar Bar Bar 5 Foo Foo


1

Yes you can do this easily. You just have to use an expression in the replacement part (see the help at :h sub-replace-expression link). So you would do it like this: ex -sc '%s/ /\="\x19"/g|x' hello.txt od -c hello.txt 0000000 h e l l o 031 w o r l d \n See the help at :h expr-quote link


1

If it works with the Vim Ex mode but fails with Ex v4.0 (gritter) them it is probably an issue with the latter application. I would suggest reporting on the project bug tracker, but it seems that it isn't supported anymore. If the command works with vim -e, wouldn't it be better to just stick with it?


1

For full POSIX compatibility (i.e. portability), try: ex -sc 'g/^127/d x' file I improved your regex slightly because it appeared to me that your intent was to only delete lines beginning with "127"; if that was incorrect, remove the ^ carat. The -s command causes ex to run silently. The global command must be terminated by a newline. +cmd is not ...


Only top voted, non community-wiki answers of a minimum length are eligible