12

It's a latin term meaning "the same". In the quoted context, it just means the listed command does the same thing as the previously listed command, i.e. remove item 3: :let i = remove(list, 3) " remove item 3 :unlet list[3] " idem


10

After you've done your Visual selection run this: y:@"<CR> y copies the selection to the unnamed register (") since we didn't explicitly name a register. Then :@" executes the contents of that register as Ex commands. See help :@ and https://stackoverflow.com/questions/20262519/vim-how-to-source-a-part-of-the-buffer


9

Good question. The keycode format with wider general usability is "\<xxx>". In any expression this will be replaced with the underlying numerical representation of the associated key (i.e. the "key code"). Per :h keycodes the other form, <xxx>, is used in the documentation to represent non-printing keys and, more relevant here, can be used to ...


9

/xx place cursor at xx, it's a :h / . :/xx is a :h :[range] , not :h :range , it's a valid ex command by itself, it's behavior is affected by :h 'startofline' . If 'startofline' is on (default), :/xx place cursor at 1st non-blank of the line that contain xx, it's the leading y in this case. If 'startofline' is off, :/xx move cursor to the matching line ...


8

You’re looking for the isdirectory() function: isdirectory({directory}) *isdirectory()* The result is a Number, which is non-zero when a directory with the name {directory} exists. If {directory} doesn't exist, or isn't a directory, the result is FALSE. {directory} is any expression, which is used as a String....


8

You can surround the word currently under the cursor in quotes with the following normal mode commands: ciw""EscP Replace iw with any other Vim motion/text object to surround other things with quotes*. Or "" with any other pair of characters to surround the object with different things. If you want to surround the object with a longer piece of text, such ...


7

You can use extend(): :let defaults = {'hello': 'world', 'bye': 'jupiter'} :let override = {'hello': 'mars'} :echo extend(defaults, override) {'hello': 'mars', 'bye': 'jupiter'} Keys from the second argument override any existing ones in the first. The defaults dict will be modified in place, which may not be wanted. Use copy() to prevent that: :call ...


7

The simple way is if get(g:, 'myplugin_enable_feature', defaultvalue) do whatever you want endif Now when I need to check a setting in more than one place, I usually prefer to have a dedicated getter in my plugin to be sure I have the same default value everywhere function! s:enable_feature() abort return get(g:, 'myplugin_enable_feature', ...


7

There is the reltime() function to get relative times, and reltimestr() to display that as the number of seconds: :let start = reltime() :echo reltime(start) [65, 11796] :echo reltimestr(reltime(start)) 71.267801 So in your case, you would do something like: function MaFunction() let start = reltime() call Function1() echom printf('Duration = ...


6

Since Vim 8.1.1310 Vim also supports real optional function arguments. However, that means that most vim installation don't support this yet. Also neovim doesn't offer that feature, too. Example from :help optional-function-argument: function Something(key, value = 10) echo a:key .. ": " .. a:value endfunction call Something('empty') "empty: ...


6

Yes, a plug-in for surrounding with quotes exists! vim-surround is what you're looking for. To surround the current word in double quotes, you can use ysiw" once you have the plug-in installed. ys is the command to surround and object (there's also cs to replace one delmiter with another, ds to remove surrounding), then iw is a text-object defining what to ...


6

I though it wasn't possible, but I was wrong. See :h :func-closure You need to patch two things: add closure at the end of the inner of the function declaration respect the usual naming conventions For instance function! s:my_function(dict_arg) let darg = copy(a:dict_arg) func! s:my_inner_func(cond) closure return darg[a:cond] endfunc ...


6

The problem with -reg is that anything that looks like a register is parsed as such, even when there's no separator to the following arguments. So :Delete 30 sets <reg> to 3 (numbered register) and 0 as the argument. Unfortunately, :delete itself seems to use different parsing rules; it doesn't accept a numbered register, so instead of getting E939: ...


6

To quote the help: *gf* *E446* *E447* [count]gf Edit the file whose name is under or after the cursor. Mnemonic: "goto file". Uses the 'isfname' option to find out which characters are supposed to be in a file name. Trailing punctuation characters ".,:;!" are ignored. Escaped ...


6

It resets 'cpo' value to its default value. Some people may be running vim in compatible mode, by choice or not. In those cases, various things would be inhibited, things we usually rely upon when writing plugins -- in particular :h line-continuation. As a consequence, the plugins would emit many error messages. Resetting 'cpo' to its factory setting, ...


5

Mentioned in the comments above, the v:shell_error variable gives the result of the last shell command. So the exit status can be tested as follows: let output = system("my_shell_command") if v:shell_error != 0 echo output endif


5

The most general improvements I can give are to avoid the long ?: and to make use of the get function on dictionaries. For example, I would write return get(g:, 'git_branch', '') For the if, use a plain if let l:is_git_dir = trim(system('git rev-parse --in-inside-work-tree')) if l:is_git_dir is# 'true' let g:git_branch = trim(system('git rev-parse --...


5

This is known as a "literal dict", and is just the same as a regular dictionary, except that you don't need to quote the keys with quotes: It's documented at :help literal-Dict So #{hello: 'x'} is just a slightly more convenient way of writing {'hello': 'x'}: :echo #{hello: 'x'} == {'hello': 'x'} 1 This was added in Vim 8.1.1705 (July 2019) and as of the ...


5

:help list ... :let i = remove(list, 3) " remove item 3 :unlet list[3] " idem :let l = remove(list, 3, -1) " remove items 3 to last item :unlet list[3 : ] " idem ... idem is to say that that line of code does the same as the line above. This could be useful: https://en.wiktionary.org/wiki/idem


5

Using gf, you can go to the file under the cursor. Combined with set suffixesadd+=.md, you can achieve your desired behavior. (suffixesadd asks gf and many other friends to try adding any of the suffixes in its list to the file while searching). Note that you need to have 'path' correctly set (it's default is helpful for C programmers; tpope's apathy ...


5

First, your function can be simplified into let bufnr = term_start(&shell, {"hidden": 1}) Second, it's not a problem to have buftype ==# 'terminal' and set nobuflisted together, as these are two different options. So if bufnr call setbufvar(bufnr, "buflisted", 0) endif is very much okay. However, the real question is: why you create a terminal at ...


5

readtags universal-ctags provide readtags to filter tags: Read all members of a struct: readtags -Q '(and (eq? $kind "member") (eq? $scope-name "struct_name") )' -l (and (...) (...)): (...) and (...) (eq? $kind "member") restrict kind to member (eq? $scope-name "struct_name") restrict scope-name to struct_name, your tag fields must include Z for this to ...


5

Just compare the character you got with a tab, which can be represented with the \t escape sequence. That is, getline(".")[col(".")-1] == "\t" The expression will return 1 if the character is tab, 0 if not.


4

The OP's question is whether there is a good omnifunc for Vimscript itself, such as offering semantically or syntactically are completion suggestions for vimscript functions, variables, etc. A number of answers just note general autocompletion plugins like YCM and snippet plugins like UltiSnips. So to answer the original question: Yes, there's vim-verdin: ...


4

readfile() returns a list, each line being in a separate list item. You can therefore make use of map() to change the list inplace: let a=map(readfile('LICENSE'), { i,v -> '/* ' . v. ' */'}) This makes use of lambda expression and wraps a the comment characters /* and */ around it. Alternatively, you can do this: :let a=['/* '] + map(readfile('...


4

I understand that Vim does not support regex capture groups I'm not sure where you got that idea from. Vim-regex most definitely supports capture groups. It wouldn't be very useful without them... Your regex is already pretty much right. Just a couple differences with which characters need to be escaped or not: ^def \(\w\+\) \?(.* Or if you want to use ...


4

3 kinds of <xxxx> "\<xxxx>" '<xxxx>' <xxxx> Let's see "\<xxxx>" first, :h string says: `\<xxx> Special key named "xxx". e.g. "\<C-W>" for CTRL-W.` ... It's an expression, it's a string, a literal string for keycode, let's see it's relation ship with literal terminal keycode on my xterm-256color: echo "\a" ...


4

You could do this: let @b=system("time.bash " . @a) The @a is register a and @b is register b. The system(...) runs a command and returns the output. The result is a line, so when you paste it, you get a new line. See :help system(). Another way is: call setreg("b", system("time.bash " . @a), "v") Here you can set the mode for the register. The lower ...


4

0- +1 to D. Ben Knoble suggestions. Regarding pure vim-scripting 1- Never define autocommands globally. Prefer to define them in their own group, and when filling the group, start by clearing it. This way, the related snippet of code can be re-executed, which you'll will want when you'll be working on your script aug MyGitBranch au! au BufEnter * call ...


4

It depends on how you get the result of your external command but you might be interested in :h systemlist(). It executes the command given as parameter and returns a list containing every lines of the output. You can then use :h list-functions on the result or simply listVar[1:]. I think that is more robust and portable than matching the lines and doing ...


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