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
1
vote
1answer
39 views

How to search for vue components with vim's gf?

I want to go to a vue component file. Vue component filenames are written in PascalCase: ExampleComponent.vue In html (or in my case blade.php) the ExampleComponent.vue is instantiated by <example-...
0
votes
1answer
75 views

Solving issue with clang-format-vim.py saving new buffer

Summary I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...
1
vote
3answers
1k views

try catch with :Rexplore

I want to be able to hit a single key to see the netrw buffer for the directory of the file I'm in. Rex will handily move your cursor to where it was previously, but only works if you opened the file ...
0
votes
1answer
24 views

How to run internal (Neo)Vim “:Command” from external Terminal?

I'm using MacOSX, and I have script on Terminal, and since I will probably forget how to update everything inside Vim/NeoVim, is it possible to pass command, e.g. :PlugUpdate, to nvim/vim so that I ...
0
votes
1answer
56 views

How to inverse boolean in Vimscript?

I have the following script but not working: I don't know what's the standard way to inverse the boolean(I used number 1/0). I not sure whether it's correct to put global variable, which I used to ...
0
votes
1answer
36 views

Map to a key to do nothing?

I'm tuning :sp, :vsp things, and for example I have: nnoremap <nowait> <C-L> <C-W><C-L> nnoremap <nowait> <C-W><C-L> :vsp<CR><C-W><C-L> ...
9
votes
1answer
2k views

Is there any way to distinguish between neovim and regular vim?

I was trying to migrate to neovim from vim. But in the end, there's some plugins which require python3 support and neovim package doesn't build with python3 by default( I'm on ubuntu, install neovim ...
0
votes
1answer
16 views

Waiting for a copy event

I have the following function: function _X() normal! gvy vs tmp normal!p ALEFix black normal! ggVG normal! y <------- endfunc Unfortunately, the y does not work. That is, ...
0
votes
1answer
41 views

ALE Fix for a visual selection

I am figuring out a way to apply linting to a visual selection of code. For example: I only want to lint run :ALEFix on that section of code, and not the 100s (or 1000s) of lines of other code in the ...
4
votes
1answer
1k views

How to get the current mode in vim?

I'm writting scripts for vim, and I want to let the script do different things in different mode. I know that the statusline will show the current mode, but I don't know how to get the exact current ...
1
vote
2answers
239 views

VimScript: Is it possible to reduce a list into a dictionary like in JS?

I've tried this but it didn't work function! Reduce(array, oper, accumInit) abort let l:accum = a:accumInit for l:item in a:array let l:accum = a:oper(l:accum, l:item) endfor return l:...
1
vote
2answers
33 views

How to check last char is { in vimscript?

I want to create a {} completion myself, and I did: inoremap <CR> if_open_curly_on_left()? <CR>}<ESC>O : <CR> function! s:if_open_curly_on_left() abort let col = col('.') - ...
0
votes
0answers
48 views

How to run vimscript function on visually selected lines of text?

I'm editing DocBook XML files and sometimes I need to format the using an external xmlformat command. it is easy to run do this on the whole buffer of text, but how can i achieve the same only for a ...
2
votes
3answers
142 views

Is it possible to perform a visual block selection programmatically using line and column numbers?

I've looked around in :help V but haven't found anything of this sort, but was wondering if there's a function I can call from vimscript that would visually select a region based on (row, column) ...
20
votes
3answers
2k views

The simplest way to start Vim in private mode

I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands: set history=0 set nobackup set nomodeline set noshelltemp set ...
0
votes
1answer
26 views

How to use tab for indent in indent function while expand tab was set?

When expandtab is set, how to let the indent function defined in file vim/indent/xxx.vim use tabs, rather than spaces to indent lines? Edit: Here is the background. I have use vim's built-in CHANGELOG ...
2
votes
1answer
35 views

How to use func to quickly add specific comments to certain lines of a file?

I wrote a function, the function is used to add comments to some lines, the content is as follows: func Add(x) call setline(a:x+1, "\ //*********************************************************...
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
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&...
2
votes
3answers
2k views

How to insert text from a variable at current cursor position?

I am writing a vim script, and I need to insert the contents of a string variable at the current cursor position. What is an appropriate way to do this? let text = "Lorem ipsum sit dolor amet ..." " ...
1
vote
1answer
111 views

Understanding a command definition

I have the following line in a vim plugin: nn <silent> <LocalLeader>E :call HOLSelectTactic()<CR>-Vo+ :help helped me in understanding lots of details, I list them to check if they ...
1
vote
1answer
78 views

How to create key bindings that apply on in a quickfix buffer?

The autoload command can be used to execute code depending on a range of events and filetypes. When I list the active buffers, the buffer hosting the quickfix window has what seems to be a unique ...
0
votes
2answers
474 views

Set cursor in quickfix on autocmd event

I need to set cursor position when opening quickfix window. I have tried autocmd BufEnter * call cursor(2, 2) It doesn't set cursor for quickfix buffer immediately after I have opened it. UPD: I am ...
0
votes
1answer
36 views

How do I open a relative path under the cursor

I often have file log where there are several relative path to files. The paths are relative to the location of the filelog. My understanding is that I'm able to open the relative path if the CWD of ...
6
votes
4answers
2k views

How can I get the character at the cursor position in a multibyte aware manner?

Consider the following line: € € This file is encoded in UTF-8 and between the two Euro marks is a Tab character (the Stack Exchange software expands this to spaces). The byte value is: e2 82 ac ...
2
votes
1answer
34 views

How to get the list of modified lines in the buffer?

Is there a n[vim] function to get the list of modified lines? A clunky way is to parse the output of :changes but I only require the changes since last write. I have to use it in a python-based plugin....
1
vote
1answer
32 views

How do you explicitly throw an error?

There are several wordings for this depending on what programming languages you are used to, but none of them turned up results for me. Also, neither help abort() nor help raise() nor help throw() ...
0
votes
1answer
67 views

regex and matchstr to get final directory and file in path

I am wondering about a regex that would enable me to get the final "directory/file" from a path. I'll explain the reason why. After using vim for 20+ years, I've finally had cause to edit &...
0
votes
3answers
47 views

How to filter without destroying original list?

I have a list of strings which is interesting in its own right, but I also want a filtered version of it for other purposes. But I discovered to my horror that filter, in addition to returning a ...
0
votes
1answer
85 views

How to bind these keys to prevent recursive binding in Vim?

I have been trying to do :noremap j k and :noremap k j which works but instead of going up it goes slanted up and down. I want j to move up and k to move down which is opposite in vim. I also tried :...
1
vote
1answer
147 views

How to check if a string starts with another string in vimscript

I know I can use regex matching with ~= and that stridx(haystack, needle) == 0 does work, but if I just want to verify that one string starts with another, I don't want to waste resources checking the ...
4
votes
2answers
362 views

Reliably get the character at a byte index in a string

I'm doing some string processing in vimscript. I obtained a byte index for a character in the string and now want to obtain the character at that byte index. For single-byte charsets (like latin1) ...
0
votes
0answers
163 views

Vim-Airline TabLine not displaying with arrows

I have set up Vim-Airline, but Vim-Airline-Tabline's tab seperator is showing vertically rather than as arrows. My tabline: Expected tabline: init.vim relating to airline: let g:...
3
votes
3answers
394 views

What does the 'z' flag for search() do?

I was looking at the documentation for search() (:help search()). I noticed that there is a "z" flag: 'z'    start searching at the cursor column instead of zero When the 'z' flag is not ...
3
votes
2answers
532 views

Vimscripts: check if item in list

I was wondering how to check if an element is in a list. I have the following function defined in a file: let g:some_list = ["a", "b", "c", "d", "e", &...
0
votes
1answer
55 views

VIM: How to call a vimscript function after press a shortcut or execute a command?

I want to know how to call a function after a normal or Ex command. Examples: bind a function to search command. When I input /xxxx to search xxxx, also call the function. press * to highlight ...
1
vote
2answers
537 views

How to delete a line from a variable?

Inside a function, saved multiple lines of external command output to a variable. How to delete a line from the variable? Like first line. I can run let tmp = split(variable, "\n") to assign the ...
0
votes
1answer
40 views

How do I enable mouse in netrw only (terminal vim)?

I would like to be able to use my mouse to scroll and click on directories to expand them in netrw. I don't want the mouse to be on for any other filetype/buffertype, so that I can still highlight/...
5
votes
2answers
136 views

Unit Testing Vimscript built-ins: possible to override/mock or inject substitutes?

I found a bug in the CoC plugin, and I was going to fix the bug, but first I wanted to write some documentation/learning tests as well as a regression test. The question was how: unit testing does not ...
1
vote
2answers
1k views

Get filetype by extension or filename in vimscript

Is there a way to get filetype for given extension or filename For example: let my_f='text.rb' let my_ft=GetFileType(my_f) echo my_ft " should output ruby
3
votes
1answer
38 views

Backward search in current line with search() and z option

I am trying to write a couple of simple functions to find the next and previous links in Vimwiki and move to them. Links in Vimwiki are indicated with the syntax [[link to something]]. Since I only ...
3
votes
1answer
2k views

Searching with vimscript function [duplicate]

I want to create a custom search in vimscript, using this line for searching: :execute "normal gg/[A-Z]\\+*.:\<cr>" it will tell me (correctly) that it searched for the pattern: /[A-Z]\+3a.*: ...
2
votes
2answers
75 views

How to find first item that satisfies predicate?

:help index explains that only exact matches are returned. How would you add a predicate to the search, so that we could find the first element that matches that? I want to write this: let i = 0 ...
1
vote
1answer
300 views

How to use TexMathZones in Markdown Syntax, for Snippets?

I am a recent and very happy Vim User. I write Mathematics and Computer Science Lecture Notes in Markdown Files, organized in a Vimwiki. I use the UltiSnips Snippet Plugin. This plugin provides me ...
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 ...
5
votes
3answers
2k views

Select multiple words, one at a time, then replace them all

Goal: Select multiple words, one at a time, then replace them all. I'm new to Vim; I come from Visual Studio. I would like to achieve one important feature that helped me a lot in my productivity: ...
6
votes
2answers
131 views

Convert absolute path to one relative to another absolute one

Context I’m working on an 'omnifunc' function for Markdown editing. It’s supposed to help me link to other Markdown files while I’m typing a link – based on file content though, not file name. Suppose ...
0
votes
1answer
35 views

Map the - key to “delete the current line, then paste it below the one we're on now”

I am doing the exercise of learn vim the hard way I have trouble mapping "the - key to "delete the current line, then paste it below the one we're on now". I tried: :map - dd p :map - :...
0
votes
2answers
49 views

What is the vimscript's no operation statement?

What is the NOP code for vimscript?
0
votes
0answers
42 views

Tool for convert multi files vimrc into single file

i try to collect my .vimrc files into single file is there anyway to generate single file using vimscript depending on source vimscript keyword or python code example of my .vimrc if isdirectory($HOME....

1
2
3 4 5
24