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 ...
TL;DR: Yes, but you probably shouldn't (in general)
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 ...
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 ...
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 ...
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:
(Note, a funcref variable must start with a capital letter).
Parse the script number inside your s:...
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)
To check whether an extra argument is supplied you do
let arg1 = a:1 " ...
" current window buffer number
" 'previous' window buffer number
" Name of the 'previous' window buffer number
"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 ...
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 (...
You can do something like this:
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 ...
Replace the single quotes with double quotes.
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 ...
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 ...
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 ...
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:
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 ...
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 ...
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:
E523: Not allowed here
Using :normal is not allowed in a map-<expr>. See :help map-<expr>.
BTW: You could replace that with ...
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 ...
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:
let Func = function('FoldingFunction') "...
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.
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:
execute "winpos 1241 ".ypos
execute "winpos 1241 ".getwinposy()
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.
PS: half a year is almost the time we spent on validating our snippet plugins...
There are two <para> because you apply v:count1 to every tag you render. Try this:
" apply v:count1 to the outside tag
put =repeat(s:DocbkRenderTag(a:tag), v:count1)
" render single tag here
for incl_tag in include
let incl_result .= ...
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 ...
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) This should work for you, though it isn't perfect:
let l:start = reltimefloat(reltime())
let l:char = getchar()
if reltimefloat(reltime()) - l:start < 0.200
echo "Too slow!"
The only downside to this approach is that you'll have to press a button regardless of whether ...
This touches the implementation details of fzf#complete. If you look into the source code of fzf#vim#complete, you will see
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 ...
...: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?
Have you read all of the applicable Vim documentation? ...
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:
Ad-hoc macro solution
I couldn't be bothered doing maths, so I implemented this with normal editing
commands in a recursive macro:
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: