New answers tagged

1

First, if your script runs from a mapping than you probably should support v:register - let the user decide what to use. Next, if your operation is a sort of "visual replacement" (get selection, modify and put it back) it makes sense to model it after :h v_p (maybe even end it with gvp or such). In this case either @- (for "less-than-a-line" selection) or @...


3

One undocumented trick is to use %{MyFunc()} expression in the statusline syntax. MyFunc() is always called whenever something happens so you can check the window size in it. For example, You can see the window height/width in the statusline. function! EchoWinSize() return winheight(0) . '/' . winwidth(0) endfunction let &statusline = "%{EchoWinSize(...


2

You can try this: silent let result=systemlist("some_program", getline(1, "$")) " do something with result " cleanup buffer normal! gg_dG call setline(1, result) Or this: silent let result=system("some_program", getline(1, "$")) " do something with result " cleanup buffer :%delete _ call setline(1, split(result, '\n')) If you want specific buffer to be ...


1

There are different approaches to this problem. Assuming your Vim has('job') you can do: let temp = bufadd('noname') call setbufvar(temp, '&buftype', 'nofile') call bufload(temp) let job = job_start('luacheck', #{in_io: 'buffer', in_buf: bufnr(), \ out_io: 'buffer', out_buf: temp, \ exit_cb: {id, status -> execute(printf('cb %d | bw %d | cw 5'...


1

You can create temporary file name with :h tempname(): let tempname = tempname() call writefile([ "hello world" ], tempname) " do something with tempname file " ... call delete(tempname)


1

Perhaps I should have searched the internet more before I asked this question. I was able to accomplish what I needed using the system function. So here I needed to do: let g:coc_node_path = substitute(system('which node'), '\n', '', '') The substitute is necessary because we need to get rid of the new line at the end of the output, otherwise the path is ...


0

Customize fzf search command You can pass a dict with custom source to fzf functions: nnoremap <c-p> :call fzf#vim#files('', {'source': g:fzf_project_source})<cr> let g:fzf_project_source = 'find . \( -name ".hg" -o -name ".git" -o -name "build" \ -o -name ".vscode" -o -name ".clangd" \) -prune -o -type f -print' Customize fzf ...


3

It's not possible to achieve this with regular mappings of K and KK. If the K mapping fires then Vim is necessarily no longer waiting to see if KK is typed, and there are no configuration options that can change this behaviour. There are ways to workaround this, however. filbranden suggested one possible method in the comments which D. Ben Knoble has ...


2

I think something like this would do: let s:pressed = 0 function KFunc() abort let s:pressed += 1 if s:pressed == 1 " do one else if s:pressed == 2 " do two let s:pressed = 0 endif endfunction augroup ResetPressed au! au CursorMoved,CursorMovedI,CursorHold,CursorHoldI * let s:pressed = 0 augroup END nnoremap K :call KFunc()<CR&...


1

This looks as expected. Airline is a statusline plugin (read :help statusline). To set the editor's colorscheme, use :colorscheme [name].


1

I think the main problem is that the search() function is moving your cursor. You can fix this by passing the 'n' flag: let newBG = search(searchString, 'n') != 0 ? "green" : "red" Then you have the problem that when you first type / the code highlights the status line according to the previous search. The cleanest way to fix is this not to run the code if ...


1

You can get a workflow that's close to what you want without configuring vim at all. You can jump to the nth buffer using <C-^> (ctrl + 6). If you type a digit while viewing the output of ls, then that digit is stored and can be passed to the next command. In order to produce the fake vim screenshots, I increased the font size so I can only see a ...


0

You can do this in a round about way by first casting the float to a string then casting it to number for example: echom str2nr(string(log10(200))) Hope this helps people searching in the future.


3

Why don't you disable the wrapping momentarily while the function is executing? function! CountAll() abort let ws = &wrapscan set nowrapscan try keepjumps normal! gg " FIXME: If the first word is an error, count it " - may be with a reverse search? " - Or by testing the syntax highlighting under the cursor let nb = 0 let p ...


3

As it has been explained, this function will always assume 9 submatches can exist and it will return an entry in the result list for all possible submatch. Hence the 5 extra elements returned. On a practical note, this means that we cannot call it this way let [all, a, b, c, end] = matchlist('acd', '\v(a)?(b)?(c)?(.*)') " fails But we don't have to fill 5 ...


4

what's up with those 5 empty strings at the end? matchlist() always returns the list of 10 items (the matched string and nine submatches - just like \0, \1, ..., \9 in :h sub-replace-special). The last five weren't used, so they are set to empty strings.


2

I had another binding that <leader>h was a prefix and I had forgotten about; it was <leader>html. Removing it solved the problem.


4

Method 1.1 " from start of cWORD to cursor echo matchstr(getline('.'), '\S*\%'. col('.') .'c.') " from cursor to end of cWORD echo matchstr(getline('.'), '\%'. col('.') .'c.\S*')


4

One option is to take the current line, then the substring starting at the current position, split it into multiple words and take the first one. Or, in Vimscript: let word = split(getline('.')[col('.')-1:])[0] One alternative is to use a normal mode command such as yW and then access the contents of the default register (or, better, use a named register.) ...


2

:noh is executed automatically Well, that's kind of prohibited. :h function-search-undo The last used search pattern and the redo command "." will not be changed by the function. This also implies that the effect of |:nohlsearch| is undone when the function returns. Note that internally all autocommands are functions, so :noh inside an autocommand ...


Top 50 recent answers are included