6

To create a custom command line command :command is a good choice: :command! -nargs=1 SL g/<args>/z#.1 You'll need to use a name that starts with a capital letter, though, so I'm using "SL" instead of "sl". Run with :SL pattern. The rest is pretty self-explanatory. Use a bang (!) after :command to allow subsequent overrides (good for including it in ...


6

TL;DR: Yes, but you probably shouldn't (in general) Other answers Christian's answer offers two approaches that modify myplugin.vim in order to expose the script-local function (either as a Funcref or just the SID that allows you to obtain a Funcref). Having to extend a plugin just for testing purposes is not nice, and as I understand, you're reluctant to ...


6

Let's get this confusion out of the way first: Are these ex commands or Vimscript? Vim scripts are made of ex commands. From :help script: Your first experience with Vim scripts is the vimrc file. Vim reads it when it starts up and executes the commands. You can set options to values you prefer. And you can use any colon command in it (commands that ...


5

This can be done with either regex+substitute or macros Substitute. This is the same as your regex except the important parts are surrounded by \( . \) to create capture groups. These are referred to by submatch(1) and submatch(2) respectively. We use the replace expression \= and execute('let') idiom. Finally, use /n to prevent substitution from ...


4

I think there are two different possibilities to achieve what you want. You can create a global funcref to your script local function and then call that funcref. Something like this: :let g:MyCustomFuncref=funcref("<sid>MyScriptLocalFunction") (Note, a funcref variable must start with a capital letter). Parse the script number inside your s:...


4

Explanation It means variadic arguments (see :h ...). To get all the extra arguments as a list, you use a:000. To get the i-th extra arguments use a:i where i is the integer (equivalent to a:000[i-1]). a:0 represents the number of extra arguments a:0 == len(a:000) Example To check whether an extra argument is supplied you do if a:0 let arg1 = a:1 " ...


4

Try this: " current window buffer number :echo winbufnr(winnr()) " 'previous' window buffer number :echo winbufnr(winnr('#')) " Name of the 'previous' window buffer number :echo bufname(winbufnr(winnr('#'))) "Previous" here means the window you have switched from to the current with, for example, <C-w>w. So if you have 3+ windows opened then the ...


4

The operatorfunc is a option. A option can only have the types boolean (on/off), number or string (see :help options). So you can't assign a lambda to an option. Also the documentation help 'operatorfunc' says This option specifies a function to be called by the g@ operator. My interpretation of "specifies" is "names". I had a look at the code (...


3

You can do something like this: :let a=[] :%s/\w\+/\=add(a, submatch(0))/gn :new :put =uniq(sort(a)) This will first declare a list a to work with. Then we run a :%s command, to capture all word-characters (\w\+) and act on all matches (g flag of the :s command), but won't actually replace (n flag). We use a sub-replace-expression(\=) in the replacement ...


3

Replace the single quotes with double quotes. return "\<C-\>\<C-O>:ALEComplete\<CR>" Single quoted Strings are "literal strings". Every character is used as entered. They are useful to express regular expressions etc as you don't have to double the backslashes. In double quoted strings backslash-escapes like \<C-O> are interpreted ...


3

The important part of the question is missing: The mapping. I assume the following: inoremap <localleader>@p <C-O>:call MaybeSetPackage()<CR> The point here is, that you are leaving insert mode (here with <C-O>) and Vim automatically removes spaces that were added by automatic indent. If you add the spaces yourself, they are not ...


3

I don't believe it's possible to redefine :Glog without losing access to the script-local function. However, bearing in mind your muscle memory is for glog, not Glog, I propose another approach: cnoreabbrev <expr> glog (getcmdtype() == ':' && getcmdpos() == 5) ? 'Gitv' : 'glog' This abbreviation will convert your :glog commands into :Gitv ...


2

You can use v:count/v:count1 to get the current count. Use execute/let to accomplish these type of mappings: xnoremap <leader>w :<c-u>execute 'set textwidth='.v:count<cr>gvgq xnoremap <leader>w :<c-u>let &textwidth=v:count<cr>gvgq For more information see: :h v:count :h v:count1 :h :execute :h c_CTRL-U :h :let-& ...


2

I think that your feedkeys() invocations write keys in the typeahead buffer, but they're not pressed immediately. Vim probably waits for the whole mapping and the function it calls to be processed. You can tell feedkeys() to make Vim press the keys immediately by passing it the x flag (see :h feedkeys()). You may also want to pass the n flag to prevent ...


2

Try it like this: silent execute('!isort -q -a ' . a:name . ' ' . expand("%:p")) This executes the given string. The expand("%:p") creates the fully qualified file name for the current file. BTW: I would recommend to add set autoload before executing and set noautoload after it. That way the file will automatically be reloaded after execute. No need for e ...


2

In a map-<expr> the allowed actions are limited. You explicitly suppressed error messages with silent!. If you remove this, you get the error message: Error detected while processing function RightPane: line 2: E523: Not allowed here Using :normal is not allowed in a map-<expr>. See :help map-<expr>. BTW: You could replace that with ...


2

If you can have any number of parameters, you'd have the choice between the following (untested) solutions :exe '%s/hello/ goodbye '.join(a:000, ', ').'/' (expecting the parameters contain no backslashes) or :%s/hello/\=' goodbye '.join(a:000, ', ')/ This second solution works only when the dynamic part is used in the replacement text, not in the ...


2

The value of the foldexpr option is evaluated to get the foldlevel of a line. You don't need to add extra call to it. You can copy following code in a new file and source it to check how it works. " vim:set foldmethod=expr noexpandtab: function! FoldingFunction(lnum) return getline(v:lnum)[0]==#"\t" endfunction let Func = function('FoldingFunction') "...


2

Maybe this: :%s/\W/\r\0\r/g :sort u :g/^\s*$/d The first puts a line break before and after each non-word character. The second command sorts the entire file with the option "unique", so all duplicate lines are removed. The third command deletes all lines that are empty or only contain whitespaces.


2

Use :execute to assemble a command from a string, which allows you to include the contents of a variable or return value from a function. This should work: function! WinRight() let ypos=getwinposy() execute "winpos 1241 ".ypos endfunction Or even: function! WinRight() execute "winpos 1241 ".getwinposy() endfunction


2

Define a list of all the lines you want to insert, and then insert them with either append() or setline(). You'll also need to extract the current indentation. See: :h List :h setline() :h append() :h indent() PS: half a year is almost the time we spent on validating our snippet plugins...


1

There are two <para> because you apply v:count1 to every tag you render. Try this: function s:DocbkPrintTag(tag) " apply v:count1 to the outside tag put =repeat(s:DocbkRenderTag(a:tag), v:count1) endfunction function s:DocbkRenderTag(tag) ... " render single tag here if !empty(include) for incl_tag in include let incl_result .= ...


1

Simply? normal! '< However, I would highly recommend seeing if there is a way to accomplish what you want via simpler (Ex) commands. If you need to do some work over a range, Ex commands are good at it. For example, visually select the lines (e.g., Vap), then :'<,'>normal! Isome text and :'<,'>normal! Asome text. Then you should be able to ...


1

You can use grep with the --only-matching/-o flag to accomplish this: :%!grep -o '\w\+\|\W' | sort -u


1

The option foldtext defines a expression, that is evaluated to create the text displayed for a closed fold. By default this is set to the build in function foldtext(). You can create a custom function, to create the text displayed on a closed fold. The documentation :help fold-foldtext contains an example. Note that the resulting text is truncated to fit ...


1

1) This should work for you, though it isn't perfect: function! GetKeyUnder200ms() let l:start = reltimefloat(reltime()) let l:char = getchar() if reltimefloat(reltime()) - l:start < 0.200 echo l:char else echo "Too slow!" endif endfunction The only downside to this approach is that you'll have to press a button regardless of whether ...


1

This touches the implementation details of fzf#complete. If you look into the source code of fzf#vim#complete, you will see call feedkeys("\<Plug>(-fzf-complete-trigger)") return '' So when you do imap <expr> xxxx fzf#vim#complete(), what returns from the expression is '', and the key \<Plug>(-fzf-complete-trigger) stored in a buffer and ...


1

...:echoerr without throwing an error or some way to achieve something similar? Call it outside of a try block. Per :h :echoerr you're seeing this behavior... When used inside a try conditional, the message is raised as an error exception ...make a function fail without :echoerr? Use :throw? Have you read all of the applicable Vim documentation? ...


1

The * command does this natively. The problem with your function is you need to escape your / or use literal-string (I recommend). let @/ = '/\<'.CurrentWord.'\>' You also should be using :normal to create the search. execute "normal! /\\<".expand('<cword>')."\\>\<cr>" For more help see: :h * :h literal-string :h quote/


1

Ad-hoc macro solution I couldn't be bothered doing maths, so I implemented this with normal editing commands in a recursive macro: gg2zjqqqqqzko<CR><CR><Esc>d/^.<CR>zjzj@qq@q Read on to see how this works, or skip to the bottom for a mapping you can paste into your .vimrc. How it works First move to the top of the file: gg Move ...


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