2022 Developer Survey is open! Take survey.
6 votes

Passing a # character to the shell in vimscript?

shellescape({string}[, {special}]) has an extra, optional argument {special} which exists exactly for this purpose. When the {special} argument is present and it's a non-zero Number or a non-empty ...
user avatar
  • 10.3k
6 votes
Accepted

Handling Complex Arguments in a Vim Command

You should be able to do this simply by splitting the arg on an = and going through a for loop. Something like the following should work. command! -nargs=+ MyCommand :call MyFunction(<f-args>) ...
user avatar
  • 7,406
5 votes
Accepted

How to call the fzf Ag command with multiple arguments?

TL;DR: You can't pass ag options into that command. (But jump to the bottom for a different one.) Note the distinction between the :Ag command and the fzf#vim#ag function. The :Ag command calls the ...
user avatar
  • 27.4k
5 votes

How does double star work in vim?

You can check with echo glob2regpat('tests/**/Helpers/**/*.php') to what regular expression this will be translated. This returns: ^tests[\/].*[\/]Helpers[\/].*[\/].*\.php$, so it will look only for a ...
user avatar
4 votes
Accepted

Why argdo applies changes only to the last file?

When using :argdo Vim executes the command and then loads the next buffer. By default, it will therefore unload the current buffer before moving to the next buffer and if the current buffer is ...
user avatar
4 votes
Accepted

Passing a # character to the shell in vimscript?

The problem is that some characters are considered special by the Vim commandline. In your case, # refers to the alternate file name. You can find the documentation with a full list at :help cmdline-...
user avatar
4 votes
Accepted

How can i get the arglist count?

You can use the argv() function: $ vim a b c :echo argv() ['a', 'b', 'c'] There is also the argc() function to get the length of the argument list (which is the same as len(argv())). Note: I found ...
user avatar
4 votes
Accepted

How to add files to argument list without adding them to buffer list?

:h args has the following lines: `If you give more than one file name when starting Vim, this list is remembered as the argument list. You can jump to each file in this list. Do not ...
user avatar
  • 825
4 votes

How to pre-process command line arguments provided to vim?

This doesn't answer your question, but it does answer your use-case. If you do :let &grepprg = "git grep --line-number" then running :grep <keyword> inside of vim will populate ...
user avatar
4 votes
Accepted

Use cases of ":rewind"? How does it differ from ":b1"?

As I was told in the comments, the fundamental difference is that :b1 targets the buffer list and :rewind targets the argument list. :help buffer-list is a nice summary: args list buffer ...
user avatar
  • 2,143
4 votes
Accepted

argdo vs bufdo for project-wide search and replace in specific folders

Meta This question is long (4 questions), and we normally prefer to keep questions to 1 question per question. The 4th is also opinion-based enough to be off-topic. However, the questions are related ...
user avatar
  • 20.6k
3 votes
Accepted

argument list shows wrong current file

From :help arglist: If you give more than one file name when starting Vim, this list is remembered as the argument list. You can jump to each file in this list. Do not confuse this with the buffer ...
user avatar
  • 20.6k
3 votes
Accepted

how to use the number returned by arglistid()

Great question! The only existing use I can determine from the docs is that it allows you to find out whether a window is currently using a local arglist or the global one. However, it looks as ...
user avatar
  • 27.4k
3 votes

Use the arglist without opening the files

I would imagine, as D. Ben Knoble suggests, that if you don't anticipate a lot of interaction with the files, a different tool would be the way to go. find . -name \*.html -exec sed -i.bak 's/replace/...
user avatar
  • 171
3 votes
Accepted

Can I run -c in batch mode (without opening the curses display)?

You can use the following, it is nearly what you have done (using another example to see difference), you need to add the hidden option: $ touch a b c $ cat * $ vi * +"set hidden" +"argdo r\!ls" +"...
user avatar
  • 15k
3 votes
Accepted

navigating multiple files - arguments and buffers

The only system I know of that comes with the real vi by default is Arch Linux. In all the others, the vi command is some kind of "alias" that points to a more advanced vi clone like nvi or vim. So ...
user avatar
  • 32.6k
2 votes
Accepted

Is is possible to change the order of the argument list?

$ touch {A,B,C,D,E,F}.md $ vim *.md :redir => current_args :silent args :redir END :let current_args = substitute(current_args, 'F', 'B', '') :let current_args = substitute(current_args, 'B', 'F',...
user avatar
  • 6,370
2 votes
Accepted

Is it possible to add a file to the argument list with in netrw?

You can do the following: c make the current netrw directory the current vim directory :arge <C-r><C-f><CR> edit the file under the cursor Adding this line ...
user avatar
  • 32.6k
2 votes
Accepted

Plugin to edit whole datasets/projects

I use argdo in this answer, same rule applies to bufdo, windo , ... . Don't use argdo undo argdo undo failes in these conditions: Some buffers remain unchanged after last argdo, might caused by 0 ...
user avatar
  • 5,868
2 votes
Accepted

Exiting back to normal mode in terminal buffer from Vimscript

:normal cannot be used while in terminal-mode (AKA "insert-mode in a terminal buffer"). Instead feedkeys() can be used (the second \ is not escaped--yet another Vimscript quirk): :call feedkeys("\<...
user avatar
2 votes
Accepted

How to pre-process command line arguments provided to vim?

I wonder if there is a way to automatically make this conversion so that in command line this statement: vim first/foo.py:123: would have the same result as this command: vim first/foo.py +123. There'...
user avatar
  • 25.5k
2 votes
Accepted

How to set read only for only one buffer

An alternate method is to modify your alias (I prefer functions, so I’ll show both): # alias alias vim='vim +"setlocal readonly" ascii' # function vim () { command vim +'setlocal readonly'...
user avatar
  • 20.6k
1 vote

How to set read only for only one buffer

You will need to add to your vimrc an autocommand which will be executed every time you read the file and will be used to set the 'readonly' option on the file: augroup readonly autocmd! ...
user avatar
  • 45.9k
1 vote

Plugin to edit whole datasets/projects

I think building on your logic @dedowsdi one could then do argdo if &modified | earlier | endif I can see how one could have several wrapper functions written around this, that's great!
user avatar
  • 33
1 vote

Handling Complex Arguments in a Vim Command

Merging back parameters like --foo="foo bar" requires manual work. Vim doesn't provide us anything to solve this issue. I remember having started an experiment on the subject. Unfortunately, this is ...
user avatar
1 vote
Accepted

How does double star work in vim?

tl;dr a bug in vim how to reproduce/inspect Build vim from sources with the following patch: diff --git a/src/misc1.c b/src/misc1.c index 2d635d677..44ccf4a7a 100644 --- a/src/misc1.c +++ b/src/...
user avatar
  • 339
1 vote

Can I run -c in batch mode (without opening the curses display)?

I already accepted an answer but I found a simpler way to perform this. Given a couple of files: $ echo yay > a $ echo yay > b $ echo yay > c $ file * a: ASCII text b: ASCII text c: ASCII ...
user avatar
  • 1,596
1 vote

How to remove lines matching pattern in all files changed in one editing session?

Give this a shot: let g:eddited_python_files = [] autocmd BufWritePost *.py if (count(g:eddited_python_files, expand('%:p')) == 0) | call add(g:eddited_python_files, expand('%:p')) | endif command! ...
user avatar
  • 7,406

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