People who code: we want your input. Take the Survey

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
5
votes
1answer
4k views

Escape quotes within quotes in command

I'm trying to run a command (from within a function) that goes somewhat like this: execute a:firstline . ',' . a:last line . 'g/\(\.\|!\|?\)\()\|]\|"\|'\)*\($\|\s\)/execute "normal! v(:call ...
5
votes
1answer
2k views

How to use <Leader> in a normal command?

In the command-line mode or in a vimscript I can use the following to duplicate a line: normal! Yp Now let's says that I map my leader key to do that: nnoremap <Leader>a Yp. If I use this key ...
5
votes
1answer
509 views

How do you convert between non-literal strings and literal strings?

I was writing a small plugin, when I decided that I should give the option of customizing which key triggers the plugin's function. Here is an example of this: let g:foo_key = "\<Tab>" While ...
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 ...
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 ...
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 ...
4
votes
1answer
4k views

Custom syntax highlighting: highlight word following keyword

I am currently trying to set a custom syntax highlighting using a mysyntax.vim file. I have several keywords (int, real, real2D, real1D, etc) currently highlighted using syn keyword VariableType real ...
4
votes
2answers
150 views

What is `v` in this vimscript?

I'm trying to understand the code suggested in https://vi.stackexchange.com/a/28506/6189: function MyLinks(pat, strip) abort return glob(a:pat, v:false, v:true) \ ->map({_, v -> printf(...
4
votes
2answers
304 views

`system()` can't get output of shell command in vimrc

I want to enable some configurations only when the distribution is Fedora. Here is my code. let s:os = system("sed -n 's/^NAME=\(.*\)/\1/p' /etc/os-release") echo s:os if s:os == "Fedora" " ...
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
1answer
2k views

Echo highlighted warning in one line

I found from the vim's manual that we can echo colored text by the following command: :echohl WarningMsg | echo "Warnging" | echohl None | echo ":Some warning" which will highlight the string ...
4
votes
1answer
1k views

Resolve path to current file

I have an abbrevation for running git blame on the current file, but it fails in the presence of symlinks. Here's the abbreviation cnoreabbrev gbl ! ( cd %:h ; exec git blame %:t ) My .vimrc is a ...
4
votes
2answers
1k views

How to check if file is binary?

Is there any way to determine within Vim that the file which I'm editing is either in text or binary format? For example: vim http://example.com/ vs: vim http://cdn.sstatic.net/vi/img/apple-touch-...
3
votes
1answer
765 views

Identify syntax region under cursor

I'm writing a VimL function that needs to behave differently for different filetypes. I know I can use &filetype to detect that, but my issue is with files that have embedded languages. Let's say ...
3
votes
2answers
477 views

Passing a # character to the shell in vimscript?

In my previous question, I passed an argument into a Vimscript function and concatenated it into the command line. This works great, but when you pass a string that contains the # character, it balks ...
3
votes
1answer
366 views

Code review request: Base converter

I do a lot of low level programming at work. As such I often found myself pulling up an online base converter to check my conversions. I relized that I wanted a way that I could do this from vim and ...
2
votes
3answers
166 views

VIM mouse scrolling on Konsole show ^[OA at the top and ^[OB at the bottom of the page

function! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfunction function! StatuslineGit() let l:branchname = GitBranch() return strlen(l:...
2
votes
1answer
680 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
2answers
716 views

Pipe shell command into buffer in real-time

I wrote this little function to update my plugins from within vim: function! UpdatePlugins() call system('for f in ~/.vim/bundle/*; do cd $f; git pull; done') endfunction command! UpdatePlugins ...
2
votes
1answer
480 views

Vimscript: How to check if a buffer is modified

Given a buffer number i, I want to check if the buffer has been modified after the last save. How do I do that in vimscript? I tried to use getbufvar() like the following: if getbufvar(i, "&...
2
votes
2answers
102 views

How to return first match from search

Following my question about some search pattern in vim, I would like to get the the text corresponding to the first match (if any) of my search pattern wich includes cursor position and is multiline. ...
2
votes
2answers
1k views

How to execute selected lines in bash and print the output in the next line?

I know that with this command: :yyp!!bash I can execute current line and print the output in the next line (actually it copies the current line to the next line, executes it, and replaces it with ...
2
votes
1answer
222 views

Operator pending mode remaps not working

I'm trying to build a vimscript can be used with the Dvorak Simplified Layout. I.e., given that the keys on the keyboard plugged into the computer are laid out in the Dovark Simplified Layout (and the ...
1
vote
1answer
280 views

Catch the “search hit BOTTOM, continuing at TOP” when cycle through the badly spelled words

Can anyone show me how to catch the last badly spelled word when vim says ...hit BOTTOM? I tried to do it like this: while 1 try " Jump to the next silent keepjumps normal! ]s ...
1
vote
1answer
246 views

How to read/get the number of lines of code in the buffer or a directory?

We can read some information about the current buffer, by hitting g C-g; for example: Col 3 of 2; Line 28 of 106; Word 144 of 474; Byte 916 of 3396 And we can capture the same information in a ...
1
vote
1answer
107 views

Running function using <SID> on commandline not working

So i found the following vimscript code: let s:mappings = { \ 'k': {id -> s:scroll_line(id, -1)}, \ 'j': {id -> s:scroll_line(id, 1)}, \ 'd': {id -> s:scroll_page(id, ...
1
vote
1answer
59 views

Vim filter command not using line-wise selection

I may have seen this question before on Vi Exchange but I'm having trouble locating it while searching now. If it's already been answered, please let me know the duplicate and I can find that. I have ...
1
vote
1answer
227 views

function: sort output alphabetically

This function outputs data between braces as joined lines in a quickfix window. The output is sorted based on line numbers. I'm searching for a method to sort the data alphabetically. I tried to ...
1
vote
1answer
141 views

Change comment char based on filetype

I am playing around with asm, which uses ATT syntax. For the filetype asm, vim is using the comment char ;, though it should be #. How/where can I change the comment char per file type? Note that I am ...
1
vote
1answer
333 views

How can I get path from vim-rooter's function and run it with QuickRun's makeprg?

How can I run vim-rooter's function FindRootDirectory() instead of /vagrant/my_project? I have tried multiple variations like: set makeprg=FindRootDirectory().'/app/Console/cake test '.expand('%:p') ...
1
vote
1answer
402 views

VimL functions to differentiate between File Exists and File Readable

Because on Linux, there is possible that file exists but is not readable by the user (I rather don't think it is feasible on Windows, but...), I seek for VimL functions to differentiate between those ...
1
vote
1answer
383 views

Concatination of arguments in vimscript when reading the output of a command to a buffer?

Is there a way to use a vimscript function to pass arguments to an external command? I have the following: function! GetJobLines(argA) " 1. Create a new buffer for the output enew " 2. ...
1
vote
1answer
27 views

Understanding a vimscript function

I have the following function in a vim plugin: fu! HOLSelect(l,r) let l:cursor = getpos(".") if search(a:l,"Wbc") == 0 return endif normal v if search(a:r,"W&...
1
vote
1answer
32 views

Selecting a region with vimscript

This is a follow-up to Understanding a vimscript function The file format is: Theorem ∀ P. P ==> P Proof rw [] \\ metis [] I modified that vimscript function: fu! HOLSelectTactic() let ...
1
vote
1answer
705 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 ...
1
vote
1answer
1k views

How to paste a text block in visual block mode?

I want to paste text which spans across multiple lines and is rectangular. For example, a rectangular box representing a device topology diagram. +-------+ | | | | ...
1
vote
2answers
78 views

Why would you use `nnoremap gf gf` as SpaceVim does?

While writing this answer about vim-rails on SpaceVim, I found out these mappings set by SpaceVim, such as this one: nnoremap gf gf SpaceVim also creates similar mappings for all of the other gX ...
1
vote
0answers
206 views

How to flush job output in vim8?

Trying to do something with job output in exit_cb or close_cb, but it's all buffered, how to flush it. e.g.: function! s:exit_cb(job, status) echom getbufline(s:bufnr, '$') endfunction function! s:...
0
votes
1answer
113 views

search a pattern preceding cursor position, modify it and insert the modified string

I am writing a mapping to autocomplete tags Pattern: <.*?>, matches complete HTML tags only. The goal is to lookbehind and see if there exists a text like <html>. Mapping: inoremap <...
0
votes
0answers
40 views

How to show “/foobar match 1 of ” or “E486: Pattern not found: foobar” in commandline when calling `normal! n` in function [duplicate]

I'm calling normal! n in a vimscript function. If there is a match, I don't get the message /foobar match 1 of 3 in the commandline. If there is no match, my commandline shortly flickers up and down ...
0
votes
1answer
55 views

How to send contents of visual selection to an external script

I would like to write a python script that parses some vim data and returns a result. For example, we'll turn numbers, separated by lines, into a sorted list of unique numbers. If we had this as the ...
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
3answers
309 views

Redirect output of vim command to external program

I would like to filter the output of vim commands with fzf. The idea is for example, if I use vim unimpaired plugin and I don't exactly remember which map was to navigate to the next git conflict but ...
0
votes
1answer
31 views

Changing cpoptions only work in commandline

So i tried to change the setting from cpoptions, so i did: set cpoptions=aABceF on the commandline, where s for the star is missing (on purpose) and it seems to work fine but only if i do it in the ...
0
votes
2answers
2k views

Getting Shift-Tab to work in VIM Insert mode

I've been trying to get Shift+Tab or <S-Tab> to work in VIM and for the life of me I can't figure it out. I read this document, but the remap solution only works for normal mode (because if I ...
0
votes
0answers
111 views

How to stop a function when <esc> is pressed? OR how to catch a <esc> signal in vimscript?

I have a function which calls another function that reads user input from input(). function! fun1() call fun2() endfunction function! fun2() let temp = input("Please input:") endfunction What I ...
0
votes
1answer
326 views

Match pattern and highlight it in modeline for a specific filetype

I need to match Issue in .conf filetype and highlight it with custom color but set in mode line instead of a fix in syntax/conf.vim file. The use-case is for each kind of document I need to highlight ...

1 2
3