4

First, you are running Vim, not Vi, because the latter does not offer the retab command. Assuming the file should be modified (that is what x does below), you can pipe the commands to Ex improved mode this way: printf '%s\n' 'retab' '%s/ /, /' 'x' | vim -E file1.txt Now, bear in mind that Ex will skip your .vimrc, so retab will not take tabstop and ...


3

Check out :help global. It basically filters out the lines that don't match the pattern. So you can do :'<,'>global/<pattern to select lines based on>/substitute/pool: MANAGED_POOL_CTS/<etc.>/. Or :g/MANAGED_POOL_CTS/normal! opubsub_topic: "projects/foo/topics/bar". (Edited with @statox's example) Or, you could execute a macro. ...


3

It can be done with a substitution with a sub-replace-expression: :%s/\ze\(\s*\)private \w\+ \(\w\+\)/\=submatch(1).'@Column(name="'.substitute(submatch(2), '\u', '_\l&', 'g').'");'."\r" For more help see: :h :s :h sub-replace-expression :h \zs :h submatch() :h substitute() :h /\u :h sub-replace-special :h s/\l


2

If you have tpope's vim-repeat, you can do something like the following: nnoremap S :call Stamp()<CR> function Stamp() abort normal! "_diwP silent! call repeat#set("S", -1) endfunction You can do it without the function, but this is a bit clearer in my opinion.


2

You can use 3Rf0<Esc>. The R command is similar to r, but it replaces multiple characters and not just a single one. It takes an <Esc> to leave Insert (Replace) mode. You can also use . to repeat a Replace action, and you can repeat it with a count. For example, you can use Rf0<Esc> to replace the first instance, followed by l2. if you ...


2

One great way to have access to multiple commands in your history is to use the command-line window, which you can access with the q: normal-mode command, or by pressing Ctrl+F from the Ex : command-line prompt. From that window, you can yank the sequence of commands you're interested on (e.g. using a motion or visual mode), then quit the command window (...


2

FWIW, I have a similar mapping on C-o. Extracted as a standalone script, it should give something like this: cno <expr> <c-o> <sid>operate_and_get_next() augroup operate_and_get_next au! au CmdlineEnter : call timer_start(0, {-> s:operate_and_get_next_remember('on_leave')}) augroup END let s:HISTORY_MAX_SIZE = 10 fu s:...


2

If you're using the command line, like so: nnoremap <LEADER>t :!echo "Yay"<CR> (just an example) You can add <C-u> after the : to erase all undesired characters: nnoremap <LEADER>t :<C-u>!echo "Yay"<CR> " Also works with `<CMD>` in neovim: nnoremap <LEADER>t <CMD>!echo "Yay"<CR> What happens ...


2

Yet another solution g/^\s*private/copy. | normal! -2dwdw"_C@Column(name = "^R=substitute(@-, '\(\l\)\(\u\)', '\1_\l\2', 'g')^M") An explanation: g/^\s*private/... for all lines starting with "<spaces>private" copy. | normal! ... make a copy of the current line then enter normal mode command -2dwdw"_C up one line ...


2

Using a macro or a :s command is probably the easiest way to get this task done... But if you'd like to explore an alternative, then the gn command is a good fit. This commands selects the next search match in a visual selection. You can use it as a text object, so you can have your ys command act on the gn block, which you can then simply repeat with a ., ...


2

With a macro: 0qqysiW'W and then 3@q. The issue is that :normal with a range is line-wise; that is, it repeats the normal command on each line in the range. You could do normal ysiW'<C-r>=repeat('W.', 3)<CR> But at that point you're doing more work than the original, I think. Quasímodo points out in the comments that substitute/\w\+/'&'/g ...


2

You can use the -c argument in the command-line to run commands in Vim after opening a file. You can pass it multiple times to run the several separate commands. Once you run the editing commands, you'll probably want to include a :wq to have Vim save your changes and quit. $ vim -c 'retab' -c '%s/ /, /' -c 'wq' file1.txt You can of course use that inside a ...


1

Once again, I suggest to work with https://github.com/mg979/vim-visual-multi I would have clicked each word with the mouse then <c-n> When all selected type S' The S' surrounds it with apostrophe. You can also select with keyboard, by doing \\/\< which searches beginnings of words. Type <c-n> until all are selected, then esc and sw (selects ...


1

I would combine it with the :g command: :g/^\s*check\>/s/=/VS/ This selects all lines that has a "check" as the first word and then executes s/=/VS/ on this line. This will replace the first = with VS. You can also use the substitution flags gc if you like to replase all equal signs and want to confirm every substitution: :g/^\s*check\>/s/=/...


1

If you'd accept a solution that requires a Vim plug-in (specifically for the snake case coercion), then I could recommend one that involves recording a macro to process each line. In particular, you would have to install plug-in vim-abolish, which includes a cr operation to do case coersion, in particular crs (or equivalently cr_) for snake_case. So you ...


1

You can use system() instead of :!. As the question is specific to Neovim, it makes sense to pass command as a List (not supported in Vim!) to execute the application directly (w/o shell): au BufWritePost *.sh,*.zsh,.zshrc \ silent call system(['ctags', '--language-force=sh', fnameescape(expand('%'))]) Also note that shell quoting rules won't apply ...


1

Do note that vim's documentation says :{range}![!]{filter} [!][arg] *:range!* Filter {range} lines through the external program {filter}. Vim replaces the optional bangs with the latest given command and appends the optional [arg]. So :!! should reuse the latest-given command. It's unclear which of the two ...


1

Like so: :%s/".*$/ This will substitute everything from the quote to the end of the line with nothing, hence deleting it. Note that '%' will apply the operation to the whole file. Use a range instead of % to change a specific sequence of lines: :1,17s/".*$/ to change lines 1 thru 17, or: :.,+3s/".*$/ to change the current line and the following 3. ...


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