14

The tilde is only treated specially if it's used in commands like :w ~/event.log. When used in a string that is passed to a function -- even if this function treats the string argument as a file name -- it has no special meaning. You have to take care of the expansion of the tilde to the home directory yourself. Vim has an expand() function that can be used ...


5

What I've tried is a exe ':'.pupid.'windo norm! zi' however the command fails upfront with and 'Invalid range` error. The pupid is being obtained via popup_findpreview() and is correct. That's because popup_findpreview() gives you a window ID, but the range passed to :windo expects window numbers: :[range]windo {cmd} Execute {cmd} in each window or if [...


5

As Jürgen Krämer said, '~' string won't be interpreted by most vim functions. Thus, when receiving the string from elsewhere, we may indeed need to expand() the tilde. However, when directly working on hardcoded pathnames as in your MWE, we can also use $HOME as in call writefile(['foo'], $HOME.'/event.log'), 'a')


4

From :h notation: Curly braces denote parts of the command which must appear, but which can take a number of different values. So, a placeholder.


3

Yes. Choose one: :windo se scb :windo set scrollbind This sets scrollbind for every window. :help scrollbind: See also |scroll-binding|. When this option is set, the current window scrolls as other scrollbind windows (windows that also have this option set) scroll.


3

com! -nargs=+ PS let @/ = printf('\v%s(\W+\w+){,%d}\W+%s', <f-args>) The way this is intended to work is to act as if you entered, after hitting /, the same search term that was provided in the answer to your question. So when you run the command you just need to use n and N to go forward and back to any matches. The / register always contains the ...


3

In an extremely related Q/A, I've listed all the tools I provide and use to help tracking errors in vim scripts: https://vi.stackexchange.com/a/25863/626 They come in complement of :debug.


3

TL;DR: Check out :help abbreviations. Example: Let's say I wanted to make a snippet to quickly create a JavaScript object in the following format with the abbreviation "obj" (| represents the cursor position after doing the abbreviation): var foo = {|}; I could do: iabbrev obj var foo = {};<Left><Left> Then, whenever I type obj in ...


3

You need to add a literal newline (displayed as ^M). You can type this character into your _vimrc by holding down Ctrl and typing v followed by m, and then releasing Ctrl. So for each line you would have: normal i __ __ __^M normal i / | / |/ |^M " etc... where ^M is not the characters "^M" literally, but the result of typing Ctrl+...


2

If you look at the help for the :pedit command, you will see this: :ped :pedit :ped[it][!] [++opt] [+cmd] {file} Edit {file} in the preview window. The preview window is opened like with :ptag. The current window and cursor position isn't changed. Useful example: ...


2

To apply Ex command to an arbitrary selection you can do the following: Copy selection to the end of file Select those new lines and run the command Cut the result Replace old selection with the result Of course, it's no good in doing this manually, so the plugins exist. I know of VIS (written by DrChip), and vim-opera (that one is mine; it also provides ...


2

You could use abbreviations as we used to do 2 decades ago, but I wouldn't recommend it for multilines snippets as the ones you've shown. Of course it's possible, to use abbreviations. As we can do with abbreviations almost everything we can do with snippet plugins -- on the details that you'll want to eat away the extra space you'll be inserting with the ...


2

Version 8.2.935 introduced a flatten() function (and version 8.2.937 fixed a bug in that function). With this function you can also write let s:asciiart = flatten(["", "", systemlist("command params"), "", ""]) to insert the elements of the inner list into the outer list.


2

:help system() tells you about this: system({expr} [, {input}]) *system()* *E677* [...] When prepended by |:silent| the terminal will not be set to cooked mode. This is meant to be used for commands that do not need the user to type. It avoids stray characters showing up on the screen which require |CTRL-L| to remove. > ...


2

There are a few plugins that have started to use {name}://{whatever} to name scratch buffers (e.g. tags://patternsearched, tasks://..., ). This is kind of helpful when other plugins try to do things on buffers but wish to ignore scratch buffer. A typical example is a local-vimrc plugin that applies project configuration settings on every buffer under a ...


2

The problem with [Scratch] itself is that that's not really the name of a buffer, but just Vim telling you that this scratch buffer is actually unnamed... It's much easier if you start with a named buffer and use bufadd() to create it. For example: let bufnr = bufadd('MyFancyScratchBuffer') execute 'sb' bufnr setlocal buftype=nofile bufhidden=hide noswapfile ...


2

You still need the execute, in order to interpolate the contents of the result Vimscript variable into the shell command: execute 'read !grep "'.result.'" file' Note that now this is a shell command and no longer just a Vim command, so consider using shellescape() to properly escape the string for use in a shell command. (But note that you may ...


2

I have similar problem so I have developed and posted a plugin (https://github.com/rickhowe/partialnumber.vim). In your example, :g/^##.##\n\ze[^#]/+1,/[^#]\zs\n##.##$/ SetPNU would show numbers in sign column.


2

You cannot. From :h 'number' (emphasis mine): Print the line number in front of each line You can only enable number or relativenumber for the whole window. See: :help 'number' :help 'relativenumber' Edit: In Vim, this isn't feasible because 'signcolumn' has a max width of 2 characters. For some reason, even though Neovim supports larger sign columns, ...


2

With the cursor in or on the parentheses, you can use Ctrl+o combined with dab to delete the parentheses and any text contained within. Ctrl+o lets you execute one normal mode command, then return to insert mode. dab deletes a block text object, including ( and ). This also works with an empty block (). Example: Say I am in insert mode with the following ...


2

Scroll-binding is definitely an option, but there are some downsides to it in that you might create interference with the use of scrollbind elsewhere, for instance if you're also using a diff at the same time... From previous questions, I understand your use case is to use custom line numbering covering specific blocks of your buffer, and you're considering ...


2

I think that index() would be the most efficient way for a strict equality. There is match() when pattern matching is required IIRC. As Christian said, :h list-functions is a perfect place to start. Still many list related functions are missing. Over the years I've defined the one I'm missing in my library plugin: https://github.com/LucHermitte/lh-vim-lib/...


2

Try to limit the height of the popup, at least 1 line less than the height of the terminal window, by including this key in the options dictionary passed to popup_create(): maxheight: &lines - 1 For example: call range(50) \ ->map({_, i -> string(i)}) \ ->popup_create(#{ \ line: 1, \ col: 1, \ minwidth: 1, \ ...


2

I tried using windo set scrollbind, but this doesn't work on a popup window (as far as i know). It cannot work because :windo only works on windows which have a number; popup windows don't. Any ways to do this? OTOH, popup windows do have an ID. So, you could try: call win_execute(winid, 'setlocal scrollbind') Or: call setwinvar(winid, '&scrollbind',...


2

I've had some success by creating the popup window without focus: let m = range(50) \ ->map({_, i -> string(i)}) \ ->popup_create(#{ \ line: 1, \ col: 1, \ minwidth: 1, \ minheight: 1, \ maxheight: &lines - 1, \ cursorline: 1, \ wrap: 0, \ firstline: 1, \ scrollbar: ...


2

You can't just start lines with * in your vimrc and have Vim ignore them. * is not really a comment character, it's a valid command. Under 'nocompatible' (which is most surely the mode under which everyone is using Vim these days), :* is a shortcut to :'<,'>, which is the range of lines comprising the last Visual selection. (See :help cpo-*, keeping in ...


2

For this particular task it's much much easier to do simply :filter /txt$/ oldfiles The error is due to -bar argument: the quote is parsed like a comment sign, and so the rest of the command is lost (see :h :command-bar, :h :quote). Either always escape all quotes (and bars) with backslashes, or remove -bar argument from the command definition.


1

There are two approaches to detect weither we are within an empty pair. The simple one: getline('.')[col('.')-2 : col('.')] == '()' that's simple to understand. To support more pairs we can test a regex instead: getline('.')[col('.')-2 : col('.')] =~ '\V()\\|[]\\|{}\\|<>\\|$$' The one that supports multicharacters pairs like <del></del>. ...


1

TL;DR: Use :source % instead. Local functions and variables are indeed a limitation of the :@ approach. As I actually mentioned in my answer to your previous question: There are some limitations, such as you can't define local functions and variables (in the s: namespace.) If you want to be able to only load parts of it using the :@ command, then you ...


1

The :@ command, to run a set of Ex commands, is the most direct one to run a block of Vimscript directly. There are some limitations, such as you can't define local functions and variables (in the s: namespace.) Until recently, Vim would break a :@ if line-continuations starting with backslash were used, but that was fixed in version 8.2.0997. I think my ...


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