Questions tagged [vimscript]

A scripting language embedded into Vim. It can be used to customize Vim to suit your needs and to create plugins. Also called VimL.

Filter by
Sorted by
Tagged with
2
votes
0answers
46 views

How to implement a check-in test for omni completion script?

I've been working in an omni-completion script for Vim that is becoming more and more complex. At this point I'm interested in implementing some kind of check-in regression test for the script. Any ...
0
votes
0answers
264 views

Window close event

For my vim plugin I try to catch an event when quickfix window is closed. I did it with BufWinLeave event. But it does not work when I have quickfix open on multiple tabs, because of 'Not when it's ...
13
votes
3answers
2k views

How to grep in ex command output?

How does one search for a pattern in ex command output? For example, how to search for a file name pattern in the output of :scriptnames command? In the help for all flavours of grep and vimgrep there ...
3
votes
3answers
2k views

How to put custom functions at bottom?

I want to organize my vimrc better, so I want to put all the custom functions at bottom: "different setting between different os if MyDetectOS() ==? "windows" set rtp+=~/vimfiles/bundle/Vundle....
3
votes
1answer
626 views

How to detect the buffer number of new buffer

I would like to create a new scratch buffer in vim script. I would like to use this buffer to output the result of the execution of a scala script. I am creating the buffer with this function: ...
1
vote
0answers
332 views

Writing a command-line tool in VimScript

I am going to write a program which can be run from the command line, at least on *nix systems. I considered using Python or Perl, but why not Vimscript? Has anybody done this? What is the best ...
2
votes
1answer
277 views

Is there a way to disable Vim from creating a new buffer every time I jump to a hyperlinked page within Vim Help pages?

I have setup my Vim Help to appear as a listed buffer for my ease of quick access and return to same page. The problem I face is that every time I jump around in Vim Help page using Ctrl-] a new Vim-...
5
votes
2answers
620 views

Is there a version of “strpart” that is aware of characters, rather than bytes

According to :help strpart(), the parameters start and len are bytes, not characters, so that returns a string of 2 characters, starting with the letter Beth. What I'd like to have is a function, ...
12
votes
3answers
4k views

How do I reverse a string with Vim script

I am trying to reverse a string, so that 'abc defg hij' becomes 'jih gfed cba'. The solution I came up with is join(reverse(split(l:text, '.\zs')), '') Is there a more elegant solution or should I ...
3
votes
1answer
517 views

Why `v:lnum` doesn't return 1 for the first line?

I really want to know why doesn't Vim's v:lnum return 1 for very first line. I tried googling and searching in Vim's docs, but I can't find an answer. I understand that v:lnum returns line number, ...
4
votes
2answers
176 views

Apply formating with a script, or have ftplugin format particular text based on syntax

When I am writting a Latex document I generally like to keep an 80 column line width to keep things easy to read. However I don't like to use text wrapping because it can get in the way of typing ...
4
votes
2answers
176 views

modify conque to gate selected text

Via Conque I use vim as an IDE for all my coding. I am starting to work in python, which is persnickety about spacing, so to test deeply indented subroutines or code blocks, I need to gate code sent ...
2
votes
2answers
602 views

How to execute a mapping on <F7> key from a script?

I have the following mapping in my project: nnoremap <F7> :execute '!gtags'<cr> :cscope kill -1<cr> :cscope add CTAGS<cr> Under certain conditions I want to be able to ...
2
votes
1answer
839 views

How can I detect whether an unlisted buffer contains a new file or an existing file?

Upon opening a new file in an active buffer in the current window, the message line at the very bottom of the screen shows "%f" [New File]. How does Vim know that the buffer contains a new file, ...
4
votes
1answer
2k views

What is a better way to use `windo` without changing of window?

In my vimscripts I sometimes have to use the windo command to execute an action on each open split. The problem with this command is that it cycles through all the open splits and ends on a different ...
1
vote
1answer
166 views

Wrapper script for vim --remote

I need to set on my Linux box VIM as default mime application for editing text file. On zsh I managed to wrap a function from vim --remote. But I would like to use it for default xdg-mime application ...
4
votes
1answer
893 views

How can I clearly document errorformat patterns in a plugin compiler file?

While testing out the vim-go plugin I encountered an issue that I wanted to look into more closely. In a comment on the issue, the owner of the plugin writes: The text read 0 byte, err read tcp 127....
4
votes
1answer
185 views

Jump to Vimscript breakpoint

Do you know how to jump to a defined Vimscript breakpoint ? For example I define a breakpoint with: :breakadd Then I can see it with: :breaklist > 1 func <SNR>114_MyFunctionName line 2 ...
5
votes
2answers
1k views

Call function from string name

I am trying to achieve the following : Having a set of predefined functions in my script Having a map of relation between the functions and their argument Calling the functions with their argument ...
1
vote
1answer
558 views

How do I use input() to get the name of a new composer project from the user?

I often start new projects in the same way. I guess it exists a way to be fast a starting a project. For example: I am trying to start new composer project with the following function. I perfectly ...
21
votes
1answer
21k views

Why am I getting a “E488: Trailing characters” error on this custom command?

I have a ~/.vimrc that contains just this: function! NewFile() let filename = input("Filename:") endfunction command NewFile :call NewFile()<cr> (of course my real .vimrc is more ...
3
votes
1answer
2k views

How do I access variables in if statements?

Following on from Put variable to line above current line VIm I added some logic to only run if the begin and end tags in the list are present, snippet .... let findStart='<'.taglist[s1].'>' ...
4
votes
1answer
2k views

How does vimscript know which buffer these buffer-local variables use?

Consider the following vimscript: function! DecideWhetherToStrip() let l:search = @/ " Check if a file being opened has trailing spaces in the first place. let b:dostrip = !search('\s\+$',...
2
votes
1answer
514 views

Run following command even if previous command fails to run?

I have shortcut map in gVim like nmap <a-k> SomeKeySequence:SomeCommand, it seems the last command will not be run if the previous key sequence aborted (like no valid operating target then bell ...
0
votes
1answer
142 views

Why is division of a negative number by 0 not the minimum number? [duplicate]

Related to Why does vim allow to divide by zero, what's going on here? :let a=-42/0 :echo a -2147483647 :let b=a - 1 :echo b -2147483648
0
votes
1answer
221 views

Is there any global() function?

I searched a little for a global function that would act as the :g command but in a more Function-style. Like the substitute command which has a function associated : :h substitute() :h :substitute ...
3
votes
2answers
907 views

How to convert series of commands into a Vim Function?

I currently run a series of commands on any file I am working on to compress the lines. That series is - G:a PRESS ENTER KEY . :g/^./ .,/^$/-1 join So I press S-g, S-:, a, enter, ., then run that ...
16
votes
3answers
2k views

Why does vim allow integer division by zero?

I just discovered that vim obviously allows division by zero: :let a=42/0 :echo a prints 2147483647 (which is the value of a). Is this documented somewhere and why does vim allow division by zero?
2
votes
4answers
855 views

Is there a vimscript function to wrap text

Is there a vimscript function that wraps text in a similar manner like gqgq does? For example, if I have the following string variable: let txt = 'One foo, two bars and three bazes went up the hill' ...
2
votes
1answer
1k views

Capture group in substitute function

I try to do a substitution from a vim script and to operate over a captured group like so: let string = "{b1} {b2} ({b3})" echo substitute(string, "{\([^}]*\)}", "a", "g") It doesn't match anything ...
1
vote
1answer
706 views

Put variable to line above current line VIm

I'm writing a function to automate a repetitive task. Copied from a macro so still not elegant while I get it to work. Basically I want to fold a xml file my way to make visual comparison easier for ...
17
votes
4answers
1k views

Merge blocks by interleaving lines

Is there a dedicated way to merge two blocks of text by interleaving lines, like passing from this: a1 a2 a3 a4 b1 b2 b3 b4 to that: a1 b1 a2 b2 a3 b3 a4 b4 in a few commands? ...
1
vote
2answers
931 views

Setting foldmethod=expr when re-sourcing vimrc?

I have the following on my vimrc file to handle custom folding: " ++ Folding set foldenable " enable folding ...
2
votes
2answers
555 views

is there a way to define the syntax highlighting keyword programatically?

I followed the link creating-a-simple-vim-syntax-highlighting, for doing the syntax highlighting for my purpose. This is really nice., but it's static. So, keywords are to be predefined. In a ...
0
votes
1answer
332 views

Is there any proper autocomplete and/or syntax checker for CoffeeScript in vim?

Is there any proper autocomplete and/or syntax checker for CoffeeScript in vim? This is not a very complex question but i cant seem to find anything. I am currently using YCM.
0
votes
1answer
433 views

Nicer way to not mach a pattern in autocmd [duplicate]

I want to to run run an autocmd for all but tex files, i figured out this solution: autocmd BufWritePre *.[^t][^e][^x] :Autoformat but is kind of ugly, because of this repeated [^..] pattern. Is ...
0
votes
2answers
394 views

a problem with a mapping ( map enter and tab key)

I have this mapping in my vimrc: imap <expr> <silent> <cr> neocomplete#mappings#close_popup() . \ "<Plug>(neosnippet_jump_or_expand)" and it's working great. When I press ...
6
votes
1answer
579 views

Can I do array destructuring in VimL?

Can I do this in Vimscript? let [a, b] = s:MyFunc() function! s:MyFunc() return [1, 2] endfunction
2
votes
1answer
184 views

`normal` does not seem to allow automatic indentation

Why does this not work as expected? function! MyO() normal! o endfunction nnoremap TT :call MyO()<cr>i If this is the situation: | an indented text ^ (normal mode) typing o gives: ...
4
votes
2answers
526 views

Use vi/vim from shell to filter / format text

Is there a way to call vi/vim from the shell to format text? It would be like running a vim-golf sequence from the command line. It is so easy to compare effects of commands in vim that I can easily ...
2
votes
1answer
688 views

Search and replace in vimscript using a range?

I was wondering how it is that I would place VIMScript variable values in my regex range and also in the replacement portion of my regex? function! GoogleFormsStep(startnum, endnum) let x = ...
2
votes
1answer
483 views

How can I yank two matches of regex group into two different registers?

This answer teaches me how to yank matches of regex group into one register. But I want to yank two into two different registers. I've tried the following but failed. :%s/\(regex1\)\(regex2\)/\=...
5
votes
4answers
1k views

How to generate patterns for comments?

As a way of organizing my codes, I like to include some titles as comments with specific patterns (I wish I can add ASCII art!). Consider for example, putting the following to mark a specific block of ...
1
vote
1answer
112 views

How to make mappings that yank text without overwriting the global registers

Many useful mappings need to temporarily save text. Some practical examples are: " Move line up/down nnoremap <c-j> ddp nnoremap <c-k> ddkP " Substitute word under cursor (use `cc` ...
6
votes
1answer
2k views

How to check with Vimscript whether python support is enabled?

I think it would be very nice if I can check whether current vim was compiled with python support, instead of having error message popping out every time vim is launched. Can this check be done in ...
16
votes
1answer
2k views

Is it possible to get the matched string after calling :search()

In a vimscript-function, I need to assign a matched string to a variable l:matched after calling search() and I am wondering if there is a shorter way than what I am currently doing: let l:pattern =...
5
votes
1answer
1k views

Why `NERDTree` doesn't trigger the autocommand `BufEnter`?

I am writing a vimscript function which should keep in a consistent state a "home made buffer manager". The idea is that I want to keep a trace of my buffers in the tabs they were open in. This "...
5
votes
2answers
3k views

Calling function to insert text with inoremap

I have a function that is called via a mapping when I am in insert mode: inoremap <buffer> <M-i> <ESC>:call TheFunc()<CR> The function is supposed to "calculate" a string (l:...
2
votes
1answer
435 views

Original column number in a mapped function called with a count

Here's an example: function! TestCursorPosWithCount() range echo virtcol('.') endfunction nmap <leader>c :call TestCursorPosWithCount()<CR> If I press <leader>c, the column ...
7
votes
1answer
1k views

Is it possible to add inline comments in a multiline statement?

I have a function that looks like fu! MultiLineTest(u, v) if a:u != 2 && \ a:v != 2 return 'yes' else return 'no' end endfu Of course, the actual ...