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 ...


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

The answer is actually not as complicated as you might think. A trick that I have found very useful in situations similar to this is to remove the <cr> from the end of your mapping and see what comes up. If I do that and run 30<C-x>b, this pops up in the command line: :.,.+29call MyFunction(30) This is because it's basically like you typed 30:...


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 ...


5

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 (...


5

I though it wasn't possible, but I was wrong. See :h :func-closure You need to patch two things: add closure at the end of the inner of the function declaration respect the usual naming conventions For instance function! s:my_function(dict_arg) let darg = copy(a:dict_arg) func! s:my_inner_func(cond) closure return darg[a:cond] endfunc ...


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 ...


3

Try this: :call feedkeys(':e ' . expand('%')) See :help feedkeys() for more details.


3

Your version of vim was compiled without eval support, and I suspect that it therefore does not support functions. Vim would then ignore the function statement and likely tries to execute the bodies. From :h eval: Note: Expression evaluation can be disabled at compile time. If this has been done, the features in this document are not available. See |+...


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 ...


3

From :h :function-verbose: When 'verbose' is non-zero, listing a function will also display where it was last defined. Example: > :verbose function SetFileTypeSH function SetFileTypeSH(name) Last set from /usr/share/vim/vim-7.0/filetype.vim So :verbose function GitFiles should do the work.


3

Essentially, the answer is no, :call is the mechanism for invoking functions starting from normal mode, but there are at least two mechanisms I can think of that you could theoretically use if you needed to call a function from a normal-mode mapping but the colon key had been stolen from your keyboard: Expression mappings Expression mappings work by ...


3

What you are seeing here, is essentially the same problem, as why many people struggle with using variables on the command line with the ex commands. See e.g. this question, there are a lot similar ones. Basically, Vims ex commandline commands expect their arguments to be literal, they cannot contain expressions (like variables or strings). Those commands ...


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

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

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

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

Rather than take a direct approach to "inserting text in the middle of a string" I'd suggest something a bit more robust (and a bit more complex). It allows you to, say, change the root directory path or the converted file directory name in a straightforward way if you need to in the future. With a straight string manipulation you'd have to redo the logic. ...


2

the system I am working on, its very very difficult if not impossible to get pluggins so I have to do stuff through my vimrc or other method. Basically trying to get a plugin installed could take half a year. Please note that you don't need to install plug-ins system wide and they can live completely inside your home directory (under ~/.vim more exactly. A ...


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...


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

TL;DR: You can use this auto-command to maximize the width of your NERDTree window when opened: autocmd FileType nerdtree let b:NERDTreeZoomed = 1 | wincmd | Alternatively, you can consider increasing the width of the window by setting the g:NERDTreeWinSize variable to a higher value (defaults to 30), you can set it to something very high to get the same ...


2

Using 0read on BufNewFile actually works as expected, in fact the documentation for BufNewFile explicitly mentions using that event for loading a template or skeleton file. If we also rule out the other things that might have gone wrong there, then the most likely explanation is that 0read is working, but the contents of the buffer are later erased by ...


2

I don't know why it happens, but if you add a \n after the echo it all works and the result is what you would expect: fu! MyFun(count) echo a:count . "\n" echo a:count . "\n" if a:count > 0 normal , call MyFun(a:count - 1) endif endf But maybe you already knew that and was just curious to know why (as I confess I am).


2

The problem is all about screen redraw (see :h echo-redraw) in Vim. Changing echo to echom still produces the same (broken) screen output (3 0 2 0 1 0 0 0), but :mess reveals what is hidden: 3 3 0 0 2 2 0 0 1 1 0 0 0 0.


2

From :h insertcharpre: It is not allowed to change the text |textlock|. You need to delay the change with a one-shot autocmd, for example until the next TextChangedI is fired: fu! Test() abort au TextChangedI * ++once call setline(1, getline('.')) endfu augroup test au! au InsertCharPre * call Test() augroup END The ++once flag is provided ...


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