New answers tagged

6

I was playing around with Vim 8.2's popups recently (I have a small plugin that allows navigation of sections in a markup document and I was looking at showing section hierarchies in popups). I figured the info I collected could make a decent introduction... Overview Vim 8.2's popup windows allow Vimscript authors and plugin developers to create one or ...


1

That's very ambitious and impactful! 👍 My recommendation, though, is that you should look into whether you can implement this outside of Vim. More specifically, if you can use the Language Server Protocol to implement this style of AI-powered code completion enhancements. (See also the Wikipedia page on LSP and also langserver.org If you do implement this ...


2

Yes, you've got it. It's an optional argument. func(foo [, bar]) Can be called as func(foo, bar) or func(foo) In the latter case the function will usually have some predetermined value assigned to bar. (What that is is usually noted in the function's documentation.) Or it might ignore it altogether. Nested square brackets indicate that an optional ...


0

You are making use of vim-plug here to get solarized run PlugInstall inside vim to install it or just copy solarized.vim file manually present here to you ~/.vim/colors/ directory. Then call the colorscheme by adding the line colorscheme solarized to your .vimrc


0

Simpler is function! CustomReplace(target, newWord) call CustomGrep(a:target) cdo execute 's/'.a:target.'/'.a:newWord.'/gc' endfunction Or with cfdo and %s, function! CustomReplace(target, newWord) call CustomGrep(a:target) cfdo execute '%s/'.a:target.'/'.a:newWord.'/gc' endfunction


0

With the help of @ChristianBrabandt, I finished this function: function! CustomReplace(target, newWord) call CustomGrep(a:target) let x = 0 let cnt = len(getqflist()) while x < cnt execute 's/'.a:target.'/'.a:newWord.'/gc' w if x != cnt - 1 cnext endif let x = x + 1 endwhile ...


2

You can just use <cword> directly here: function! CustomGrep() vimgrep <cword> **/*.h **/*.hpp **/*.c **/*.cpp endfunction If you look up :help <cword> you'll see it's on a section about "Ex special characters", which also cover special characters you might be familiar with, such as % and # (as in, :e #, to edit the alternate buffer.) ...


2

Did I do something wrong here? :vimgrep is a command which takes a string. expand() is a function call. You must use execute then: execute 'vimgrep' expand('<cword>') '**/*.h ...'


1

Check vim help for the following entries: :h function-list :h setbufline() -- what you probably need :h getbufline() -- and also this. :h appendbufline() -- and this.


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, ...


1

In my plugin library, I define the following to help running a function n times in order to have an estimation of the time it takes to execute It's meant to be used this way echo lh#time#bench_n(10000, function('Function1'), the, list, of, parameters)[1] / 10000 lh#time#bench_n() returns a list of two elements: the 10000 results of the 10000 function ...


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 = ...


1

You can try using strptime function, if available, to convert both dates to unix time, substract and get number of seconds. Unfortunately on my win box this func is not available. Something like this, NOT TESTED: let u_time1 = strptime("%c", "24/03/2020 07:31:22") let u_time2 = strptime("%c", "24/03/2020 07:31:28") echo "Duration = " . (u_time2 - u_time1)...


1

The function setwinvar can change options using the & syntax: call setwinvar(1, "&list", 0) You can execute any code in the context of another window using win_execute (vim only): call win_execute(winid, 'set syntax=python') In neovim there is also nvim_win_set_option call nvim_win_set_option(win, 'list', 0)


2

You need to load it. Add colorscheme solarized to your .vimrc. You can also load it on the fly executing :colorscheme solarized on the Vim command line


1

What about the new text-properties? They seem to have the property (sic) to follow. Text properties can be attached to text in a buffer. They will move with the text: If lines are deleted or inserted the properties move with the text they are attached to. Also when inserting/deleting text in the line before the text property.


2

I find a way myself -- a python module rpdb - remote debugger based on pdb. It works for me. Install using pip install rpdb Set breakpoint with rpdb.set_trace() in plugin python script. Try to active the plugin in vim. The vim will hang-up. Use telnet to connect the vim process. telnet localhost 4444. It will be same as pdb to use.


2

I feel like this is all overly complicated, you can realize this with just a few lines of regex: s/<\(\w\+\)>\%#/&<\/\1>/g This expression will allow you to add a closing tag after the cursor: - < matches the start of the opening tag - \w\+ matches the tag content, we include it in braces so that we can use it in the replacement - > ...


1

If you want to generate key sequences as strings, you need to use double-quoted strings and quote the < with a backslash. Such as "\<C-x>\<C-o>". See :help expr-quote for more details (single quote strings are under :help literal-string). Putting it all together: inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : \ getline('.'...


Top 50 recent answers are included