New answers tagged

5

So how can I define function with namespace in a file foo-bar.vim? Is it possible? I don't think it is possible. See :h 41.15 of the User Manual for autoload feature of vim (which you call namespace) When such a function is called, and it is not defined yet, Vim will search the "autoload" directories in 'runtimepath' for a script file called "...


1

Thanks to the comments, especially @statox. I think the easiest way to do this is to use UltiSnips and define an automatic snippet. It's somewhat frustrating how limited vim abbreviations are, but UltiSnips really seems like a well designed and reliable plugin. I made the following snippet in UltiSnips/markdown.snippets - replace the underscores with spaces. ...


2

Afaik, opfunc requires literal function name not the variable name holding function reference. If what you want is to simplify opfunc creation there is another way: func! ToggleComment(type = '') if a:type == '' " HERE you set opfunc to ToggleComment let &opfunc = matchstr(expand('<sfile>'), '[^. ]*$') return 'g@' ...


1

Starting from 8.2.1794 vim has null coalescing operator aka falsy operator let value = somevar ?? othervar ?? 100 :h ?? The expression before the '??' is evaluated. If it evaluates to |truthy|, this is used as the result. Otherwise the expression after the '??' is evaluated and used as the result. This is most useful to have a default value for an ...


1

I would try something like the following. In my vimrc (or a plugin file, :help load-plugins; I often use ~/.vim/after/plugin/config/<pluginname>.vim), I would define let g:UltiSnipsExpandTrigger="<c-tab>"` Then, in an ftplugin (:help ftplugins, I would use ~/.vim/after/ftplugin/vimwiki.vim), make the change: let b:...


2

You could use a macro, started on the first letter of the word (and assuming it's all lower cast to begin with (if not do guu to put the line into lower case): qa~lq Then just do @a to replay the macro (and thereafter @@ to repeat). This won't ensure that the first letter of each word in a sentence is of the same case though: SoMe aLtErNaTiNg tExT If you ...


2

Substitution is one way... :s/\v(.)(.?)/\u\1\l\2/g Breakdown: \v : use "very magic" mode (.) : first dot is our "odd" character; enclosed in capture group 1 (.?) : second dot is our "even" character; enclosed in capture group 2; have to make it optional in order to capitalize last char of line if it's "odd" \u : ...


2

A simple fix is to use the third argument of input, which is a {completion} type (list at :help :command-completion): … const bufname = input('warp: ', '', 'buffer') … (I used const instead of let, too.)


1

I ended up writing this little script: " --Warp: fast buffer switch function Warp(...) let bufname = a:1 if bufname == "" b# else if bufname == "d" echo("d") %bd|e#|bd# else exe "b " . bufname endif endif endfunction command! -nargs=? -complete=buffer Warp :call Warp(<q-...


1

You can use :execute {expr1} to execute the string that results from the evaluation of {expr1} as an Ex command. execute "syn sync ...".s:funcrgx."..." in place of syn sync ...


2

As I understand it, the problem is that your plugin will do an operation which leaves the "dot" repeat command in an inconsistent state. From the question, I don't know what this operation is, but generally you can re-structure your plugin in a way that it will work as expected. You can use the g@ operator feature to run arbitrary commands which ...


3

You will have to remap a . to do series of changes that your mapping introduces. It is not that simple to do and it might interfere with other things user might have mapped on the dot like vim-repeat of Tim Pope (which does exactly that and exposes API for other plugins to have complex repeats with a dot)


Top 50 recent answers are included