New answers tagged

0

Recently someone asked a similar question on Reddit and I wrote a piece of code to answer it. Today I've found this question in a review queue so that is the opportunity to share my code in a late answer. The idea is to create two new mappings <leader><c-o> and <leader><c-i> which will execute respectively <c-o> and <c-i> ...


0

In addition to the answer given by @statox, I did some testing & found out the RAM used by dictionary variables in (Neo)Vim. I don't have any experience with C language, so I did testing in a following way. Process I created 100 dummy .txt files with random data around a few KB. Totaling 1.5 MB size. With bash script. I added below code in my .vimrc. ...


2

In Vim, if you look at the source code for buflist_new() which adds a filename to the buffer list you'll find the part where the b: dictionary is initialized // init b: variables buf->b_vars = dict_alloc(); if (buf->b_vars == NULL) { vim_free(ffname); vim_free(buf); return NULL; } init_var_dict(buf->b_vars, &buf->b_bufvar, ...


0

A bit of a hack, but if you can get the window ID of the popup (popup_create returns it; popup_locate or popup_list might help find it), you can get the buffer contents and create a new one: const popup_winid = … const popup_bufnr = winbufnr(popup_winid) const lines = getbufline(popup_bufnr, 1, '$') " do something with them, like: new put =lines 1delete


0

I use the following script with assumption: nnoremap <nowait><silent><expr> ∑ "(YOUR_SHORT_CUT) \ (&filetype=="fern" <bar><bar> &filetype=="startify" \ <bar><bar> len(getbufinfo({'buflisted':1}))==1 && &filetype=="")? ":q<CR>&...


2

Whilst there isn't a vim-native option to configure this, you can simulate it by writing your own functions to overload :bnext and :bprev. function! Bnext() let bufnrs = range(1, bufnr("$")) call filter(bufnrs, {_, v -> buflisted(v)}) if bufnr() == max(bufnrs) echo "You are at the last buffer" else bnext ...


3

Following from @statox comment, it is possible to Use :redir in a function, like function! s:runCmdActiveBuffer(cmd) :redir => lbufs_str :ls a :redir END :let lbufs = split(lbufs_str, '\n') :for i in lbufs :let bufnr = split(i)[0] :execute 'b '.bufnr :execute a:cmd :endfor endfunction command! -args=+ ActBufdo :call s:...


5

Interesting question. I had to think about how to do this as I wanted to avoid using :ls a. (Parsing :ls output isn't ideal in much the same way that parsing the output of the shell command ls is non-ideal.) I've got it down to a single Ex command line, though one that could use a bit of explanation depending on your familiarity with Vim. Per :h active-...


1

Here's two vim versions of the "recursive, lazy, sed substitute" that the function is performing. Both involve the same technique: filling one of vim's special lists and then calling the corresponding do command. Using the arglist The arglist can be filled with files and traversed with :next, :prev, and a few other commands. Conveniently, we can ...


0

Looks like instead of :bufdo! e! (which also caused buffer highlighting to disappear: Syntax highlighting is gone after :bufdo :e) I needed to do :bufdo! checktime with the autoread option locally disabled: :let ar = &autoread :set autoread :bufdo! checktime :redraw! :let &autoread=&ar


2

bufdo runs a command (here, the ex command :/), so there's no real interactivity For a search over multiple files (or buffers), use :grep/:vimgrep. For example: :grep -R pat . " or :vimgrep /pat/ **/* " or whatever you need Then you navigate with the quickfix list (:help quickfix). Probably :cnext/:cprevious are useful, or :cwindow if you want to ...


Top 50 recent answers are included