12

VimScript is more of a programming language. So the following won't work just like in C. let foo = $HOME/bar It's division. let foo = "$HOME/bar" Inside quoted string only "backslashes" are pre-processed. Therefore, you must do one of concatenation: let foo = $HOME..'/bar' printf: let foo = printf('%s/bar', $HOME) expand: let foo = ...


7

Here's an example that doesn't depend on 'W'. Enter ALFALFA, position the cursor on the first L and compare: :call search('ALFA') This moves the cursor left to the first A in the line. Surprising! Why didn't it move forward? :call search('ALFA', 'z') This moves the cursor right to the second A in the line. This seems more like what you'd expect. The ...


7

Since Vim 8.1.553, you can simply supply a count to the scriptnames command to have it edited. So in your case, you can simply use: :25scriptnames or :scriptnames 25 to edit the zipPlugin.vim


6

See :h :func-abort, like function! AmendCommit(commit_hash) abort ... This is recommended practice in the current version of VimScript. In Vim9Script "abort" is planned to be the default behaviour, and so the word "abort" won't be needed/supported.


5

The way shortcuts work is that cmdidxs1 and cmdidxs2 are defined in ex_cmdidxs.h, which contain a index to the actual command definition. It's not easy to re-implement this in Vim, as it depends on the order in which the commands are defined in ex_cmds.h (the reason :s is :substitute is because this occurs before any other command starting with :s). The ...


5

What you are creating with the maps commands are mappings (:h key-mapping) which are used to change the meaning of typed keys. Very concretely what you command does is to say to Vim "When I type the keys <LocalLeader> followed by shift+e then consider that I actually pressed the following keys: :call HOLSelectTactic()<CR>-Vo+ So let's take ...


5

It is not entirely clear when you say to "trigger some mapping"... Do you want to create a mapping with nnoremap if current line is empty? I guess not. Or you want to have a mapping that does different things depending on whether current line is empty? If so then there are many possibilities, for example: func! DoSmth() if getline('.') =~ '^\s*$...


5

You need to use explicit string concatenation here, since :let wants an expression and the /bar looks like a division by a variable named "bar". What you want here is: let foo = $HOME . '/bar' Note that . is the Vim operator for string concatenation here.


5

So how can I define function with namespace in a file foo-bar.vim? Is it possible? I don't think it is possible. See :h 41.15 of the User Manual for autoload feature of vim (which you call namespace) When such a function is called, and it is not defined yet, Vim will search the "autoload" directories in 'runtimepath' for a script file called "...


5

You can use line continuations (lines after the first starting with a backslash) and using |s to separate commands. Something like this might work for you (but I haven't tested it, so it might be missing some escaping): autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/* \ nnoremap <Enter> :DiaryTagBrowser <Enter> \ | nnoremap <...


5

That's a lot of code. ;) What if I said we could compact that whole thing down to a one-line command (and mapping)? Let's take it a step at a time, though. First, the substitution... :s/\u/ \l&/g ...will replace each capital letter in the current line with a space and the lower-cased letter. Same pattern/replacement can be used in substitute(). Let's ...


5

In the :help cmdline-completion section, see this paragraph discusses suffixes *c_CTRL-D* CTRL-D List names that match the pattern in front of the cursor. When showing file names, directories are highlighted (see 'highlight' option). Names where 'suffixes' matches are moved to the end. The '...


4

During development of vimscript code, having to source the whole file where it resides just to try out a snippet is sub-optimal. In my experience, there are always a bunch of variants of the code we're trying to make work that we don't want to throw out (yet), but we need to keep commenting it out (or in) so that the :so % doesn't trip up all over the place. ...


4

index() can be used to check whether or not an item is in a list. The body of your function should be written like this: if index(g:some_list, a:item) >= 0 " If item is in the list. echo "Yes" else echo "No" endif To check that the item is not in the list, use index(g:some_list, a:item) == -1 instead.


4

Scripts in your init.vim are only executed when you first launch Neovim, or when you source the file manually (same goes for vimrc and vim). To trigger a script automatically, based on an event, you can use an autocommand. For your case, this should do the trick: augroup ShowLineNumberForLongFiles autocmd! autocmd BufEnter * if line('$') > 150 | ...


4

I would argue that even if it were possible, it's not a good practice to mock has( in this way. Instead, you should test directly against the versions of vim which you are trying to support. Many vim plugins do have CI pipelines which test the most latest version of vim, vim 8.0, vim 7.4, various neovim versions, etc. Automated testing frameworks in ...


4

An example that illustrates the use of this flag is below. Add the text 'abc123' to a buffer. Place the cursor on 'b' and execute the following command: call search('abc\zs123', 'W') The cursor will be positioned on '123' even though the cursor is after the start of the match. Now move the cursor back to 'b' and execute the following command: call search('...


4

Use append() function instead as described in :h setline() help section. It accepts the line number and and either a text line or a list of text lines that would be inserted/appended after given line number. func! AddCommentHeader(lnum) abort let comment_header = \[ \'//*****************************************************...


4

You can invert a boolean with !: let foo = 1 echo foo " will print 1 let foo = !foo echo foo " will print 0 I'm afraid I can't help much with the overall function as I am unfamiliar with minimap, but that might help you get started. Note that the syntax in your ternary operatory is incorrect. If you are doing it that way you want: let foo = foo =...


4

Another option is the Scriptnames command in Tim Pope's vim-scriptease plugin. https://github.com/tpope/vim-scriptease The script names are loaded into a quickfix list. Hitting return opens the script name under the cursor.


4

<C-6> is a normal mapping (I guess you want to switch to alternate buffer). But the way you call it is incorrect -- calling it as an ex-command. Normal mode commands in vimscript should be called with :normal! sequenceofkeypresses. For <C-6> it would be :normal ^^ where ^^ is generated by pressing <C-v><C-6>. Even more, with normal ...


4

It is possible if you manage escaping rules very carefully. For example, nnoremap x <cmd>echo "<bslash><lt>Plug>MyWonderfulMap" v:count<cr> Then :map x prints: n x * <Cmd>echo "\<Plug>MyWonderfulMap" v:count<CR> And typing 3x echos, as expected, <80><fd>SMyWonderfulMap ...


4

Use :h call(): func! Bar(...) abort return a:000 endfunc func! Foo(...) abort echo call('Bar', a:000) endfunc call Foo('asdf', 'qwer') " --> ['asdf', 'qwer']


4

It's explained in :help :silent *:sil* *:silent* *:silent!* :sil[ent][!] {command} Execute {command} silently. Normal messages will not be given or added to the message history. When [!] is added, error messages will also be skipped, and commands and mappings will not be aborted when ...


4

While I was pretty sure the answer was "they are identical" I was only 99% sure so...I checked the code. Function eval4() in eval.c is the entry point for "expr4" operations, i.e. comparisons (==, <=, is, !=, isnot, etc.) This function sets up the two values to compare and then calls typval_compare() in typval.c for the actual ...


4

The :put Ex command will always work linewise, which is actually described in :help :put: Put the text [from register x] after [line] (default current line). This always works linewise, thus this command can be used to put a yanked block as new lines. You can also follow the link to :help linewise to understand what it means. What you actually want, “...


4

This is possible if you unset flag c in setting 'cpoptions' (alias 'cpo'). Absence of that flag is described thusly: When not present searching continues one character from the cursor position. With 'c' "abababababab" only gets three matches when repeating "/abab", without 'c' there are five matches. Now the simple pattern... AABBAA .....


3

I don't think this is possible either. I'd say you may found a solution depending on how the call to has() is used. Sometimes you will be able to overwrite the direct consequence of a call to has() (like changing/removing a function/a command... that depends on has() result), other times it wouldn't be possible. In all cases, if the plugin you want to ...


3

An auto command is appropriate here... autocmd BufReadPost * if line('$') > 150 | :setlocal number | else | :setlocal nonumber | endif OR, you can use this nice enhancement care of MartinTournoij. It has the same result but takes up a lot less space: autocmd BufReadPost * let &l:number = line('$') > 150 Explanation: First, &l:number is a ...


3

The proper syntax is noremap gus :silent !setxkbmap -layout us<enter><C-L> The exclamation mark introduces an external, shell command and Ctrl-L redraws the screen.


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