6

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 String (non-zero-arg), then special items such as "!", "%", and "<cword>" will be preceded by a backslash. This backslash will be removed again by the :! ...


5

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>) let s:dictionary = {} function! MyFunction(...) for arg in a:000 let myList = split(arg, '=') let s:dictionary[myList[0]] = myList[1] endfor ...


5

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 fzf#vim#ag function passing it exactly two arguments: <q-args>: This is all the arguments that were passed to the command, passed as a single argument. (...


5

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 Helpers directory which is located below any directory underneath the tests directory.


4

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 modified, it will abort the changes (without the '!' attribute, the argdo will then simply fail). This means that after your :argdo command, only the third buffer ...


4

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-special. This also includes the two possible ways to prevent this: Prefix it with a backslash: :execute ":read !echo " . shellescape('C\#') Use the ...


4

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 this by going to :help function-list and searching for arg :-) I find :help function-list to be one of the most useful Vim pages when writing VimScript. Tattoo ...


4

: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 confuse this with the buffer list, which you can see with the |:buffers| command. The argument list was already present in Vi, the buffer list is new ...


4

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 your quickfix list. Which you can navigate with :cnext and the like. So how does this work at a high level? The vim command :grep invokes a command specified by ...


4

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 list meaning :[N]argument [N] :[N]buffer [N] to arg/buf N :[N]next [file ..] :[N]bnext [N] to Nth next arg/buf :[N]Next [N] :[N]...


4

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 enough and I have enough to say that I'm going to (try to) write an answer. Your questions first: Does this mean that at this point in time, argo and bufdo ...


3

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 list, which you can see with the |:buffers| command. The argument list was already present in Vi, the buffer list is new in Vim. Every file name in the ...


3

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 though it's just the first step of some more extensive changes that allow you to use the number to manipulate the lists in use. This code has already been written (...


3

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/withthis/g' {} + (or perl -i.bak -pe if your pattern is more complex than sed can accommodate). If you are determined to do this in vim, I would probably use ...


3

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" +"xall" $ cat * a b c a b c a b c set hidden tells vim you can switch buffer without saving them. If you still want to use your loop, you can do the same: for ...


3

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 chances are that you are actually using Vim. Indeed, arguments and buffers have a special relationship. Adding elements to the argument list also adds them to ...


2

$ 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', '') :exe "args ".substitute(current_args, '[\n\r[\]]', '', 'g') First you can use :args to retrieve the current list of arguments, and :redir to capture it ...


2

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 to your vimrc should allow you to avoid the c step: let g:netrw_keepdir = 0


2

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 pattern match, execute undo on them is a mistake, it will undo changes made by older argdo. An error occurs during your last argdo, when an error occurs, argdo ...


2

: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("\<C-\><C-N>") For your specific case, jamming a feedkeys() call immediately after the :execute doesn't seem to work (could be that "typeahead" is ...


2

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's a Vim plug-in that implements precisely that: lervag/file-line. It recognizes common separators such as colons or also parens (first/foo.py(123)), and it can ...


2

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' ascii "$@" } The issue here is I’m not sure if vim is ok with options/flags that come after the first file argument.


1

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! autocmd! BufReadPost ascii_img setlocal readonly augroup END See :h autocmd and :h 'readonly'


1

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!


1

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 nothing more than that: an incomplete experiment: lh#command#Fargs2String()


1

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/misc1.c @@ -10171,8 +10171,18 @@ unix_expandpath( char_u *path, int wildoff, int flags, /* EW_* flags */ - int didstar)...


1

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 text I can use the several :argdo commands separated by |, this way I do not need to rely on :set hidden: $ vim -u NONE -c 'argdo set ff=dos | w' -c 'q' * $ ...


1

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! RB call RemoveAllBreakPoints() function! RemoveAllBreakPoints() tabnew " Don't clobber the current tab for file in g:eddited_python_files exe "edit ...


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