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
66 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
39 views

How can I make a mapping to toggle cursorbind?

I know that adding a ! to the end of an option works for some commands, but it doesn't work for cursorbind. How can I toggle between cursorbind and nocursorbind with a keybinding?
1
vote
1answer
53 views

Execute command with special characters from user input

I would like to correctly intepret the <cr> in a command that is created based on user input. For example, this function runs correctly and it will split the line a the location where the cursor ...
3
votes
1answer
38 views

Need a functionality behaving like Replace on text but for Pasting Blocks

One of my vim usages is to do sketches of topologies in networking I've found the script Draw it really really useful for that So I can draw things like this by pasting these boxes +------+ |ROUTER| ...
0
votes
1answer
18 views

Any way to create a VimL equivalent of Python's @property decorator?

As the title says, I'd like to be able to use something like Python's @property decorator (its semantics ofc, not the syntax) when writing a 'class' in VimL. Currently I have something along the ...
0
votes
1answer
50 views

Literal character escapes in VimL string

I'm trying to use vimlsp server to help me write VimL, but it is prevented for me due to a parse problem with a literal carriage return (^M) char inside this code: function! ChompCtrlM(string) ...
0
votes
1answer
64 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
1answer
38 views

Enhance Latex Syntax without Rewriting everything

I want to extend the latex syntax for the given file: \documentclass[a4paper,11pt]{book} \begin{document} \begin{figure}[t] \begin{tikzpicture} \node[alter] at (0,0) (v1) {typ0}; ...
0
votes
0answers
20 views

Automaticall close LaTeX begin environment with end [duplicate]

I want to automate some routine operations when working with LaTeX documents writing, e.g. I often write these lines: \begin{<environment-name>} some text and commands here \end{<environment-...
1
vote
0answers
16 views

system function puts extra characters onto stdout [duplicate]

I just updated to the latest vim (git fetch && git merge origin/master followed by building and installing to /usr/local/...). Everything is great except with a little extra stuff I added to ...
0
votes
1answer
31 views

Get the content of the first column

I'm writing a vim function to comment the selected lines in visual mode. Then I have written the following function to toggle the "#" character. I want insert the # when thereisn't and ...
0
votes
1answer
359 views

Inside a mapping check if a variable is empty in vim

So i'm new to vim, and specially new to vimscript, and messing around i made the following code to get the name for a file and then create said file in a new buffer. I want a way to check if FileName_ ...
1
vote
0answers
20 views

How can you isolate the date portion of each request of a IP adress? [closed]

How can you isolate the date portion of each request of a IP address if it's at the first line of each request from a log file using awk, creating a list of distinct dates, and then using grep to ...
4
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: ...
1
vote
2answers
54 views

How to trigger rhs of a map?

Let's say I have a function like this: function! Foo() echom 'foo' endfunction And a map like this: nmap gf :<C-U>call Foo()<CR>0v$ When I type gf I see foo echoed and the current line ...
3
votes
1answer
63 views

Folding example from Learn Vimscript the Hard Way not working?

I'm reading Learn Vimscript the Hard Way - Chapter 18, which is also about folds. I'm surprised to see that copying the sample code " Vimscript file settings ---------------------- {{{ augroup ...
1
vote
0answers
85 views

vimscript - copy a file from one path to another

How do I rewrite this line of code call system("cp /tmp/foo.txt /tmp/bar.txt") into a vim command which is more portable and OS-independent? I've been looking around but checking for "...
0
votes
1answer
19 views

function with one argument that search for word and then replace something on that line

I want to create a custom function that: Take 1 argument Search for a word On that line do a movement like f@ change till " (ct") with the argument I provided Example: Library "...
0
votes
0answers
69 views

How to set statusline for specific buffer

I want to use netrwm instead of nerdtree. I have my own statusline but I don't want it to be displayed in netrw. Nerdtree had it's own option for it (let NERDTreeStatusline="") which made it ...
1
vote
2answers
19 views

why doesn't col(“^”) work as expected

I know that there is a function col({expr}), which returns the column position given with {expr}. For example, col("$") gives me the column position of the end of the cursor line. So I ...
0
votes
1answer
63 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
0answers
41 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
0
votes
0answers
20 views

Want template files pre-populated based on keystrokes

So based on the keystrokes I enter I want to copy the full file templates into the new file and begin editing them. This is my vimscript and I have tried a couple of different ways, from using :r :e ...
0
votes
0answers
98 views

Load scripts one after another

I have a syntax highlight, that is presumably overwritten by another script. When I execute :scriptnames, it shows ~90 scripts. The syntax script is around number 40. Is it possible to manually load ...
3
votes
1answer
66 views

Statusline wrong column count for multi-byte characters

I have set this statusline. :set statusline=%c According to :help statusline, %c means column number. If the buffer contents is abcdef éÀ│§õ→ and the cursor is on the f character, the statusline ...
2
votes
1answer
61 views

Print the output of vim-scripts function in current line

Say I want to print the output of strftime("%D") in the current line, or to print the return of any user-defined function for that matter. What's the standard (one step?) way to do it? I ...
-1
votes
1answer
222 views

How to compile a program and open the output in a vertical terminal window?

How can I write a command that does the following? With one mapping, compile and/or run a program based on the filetype (*.c, *.cpp, *.js, *.py, etc.), and open a vertical terminal window with the ...
1
vote
1answer
29 views

How to invoke Linux shell env variable into vimrc?

How to invoke Linux shell env variable into vimrc ? I split vimrc configurations into multiple files and included these files in vimrc via :runtime [file]. This works well. :runtime vimrc.d/vimrc....
0
votes
0answers
36 views

How to determine including file in includeexpr

I've tried to convince vim to parse my import statements in EcmaScript modules. My goal is to use vim's native include-search (and definition search) tools without tags with vanilla EcmaScript. Though ...
6
votes
2answers
1k views

Why can't I write to a file in the home directory?

I want to write to a file in the home directory, so I tried the following command: :call writefile(["foo"], "~/event.log", "a") But I got an error: E482: Can't create ...
1
vote
1answer
87 views

Making custom command behave like “:echo” with respect to quotes

This command works without errors: :echo v:oldfiles->copy()->filter('v:val =~# "txt$"') (see :h method, :h v:oldfiles, :h v:val and :h =~#) I want to create a custom command / ...
0
votes
1answer
29 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
1answer
27 views

Change default character for comments

The assigned character for comments is " for vimscript. But i want to change it to some other character (like * or # for example). Based on this post, it seems like the string setlocal ...
0
votes
1answer
60 views

Ignore error on specific character in .vimrc

I'm using the accepted answer in this post, and as such, tried using the character * in my .vimrc, but it seems to generate E20: Mark not set as error, which i want to ignore (only for the instance ...
0
votes
0answers
45 views

Execute vimscript without saving first?

From my two previous questions, I learned about using :source %, @", and other tricks to execute vimscript. But as I noticed, :source % needs the file to be saved first, furthermore, @" and ...
1
vote
2answers
98 views

Sync cursors of popup window and current window

I'm trying to sync the cursors movement of a popup window, and the current window. call range(50) \ ->map({_, i -> string(i)}) \ ->popup_create(#{ \ line: 1, \ col: 1, ...
2
votes
1answer
113 views

Scrolling down in popup window not working as intended

I have the following code: let text = range(50)->map({_,i -> string(i)}) let winid = popup_create(text, { \ 'line': 1, \ 'col': 1, \ 'minwidth': 1, \ 'minheight': 1, \ '...
1
vote
2answers
154 views

Remove a pair of brackets without using plugins [duplicate]

I am looking for a way to remove a pair of brackets in the insertion mode without plugins. It's like (|) When I press the delete key only the first bracket get deleted |) But I want to auto-remove ...
1
vote
2answers
60 views

Any ways to sync the movement of the number column and another window?

I want to be able to control/sync the movement (scrolling) of the number column (usable with :set number) with another different window (which doesn't have :set number set). Any ways to do this?
1
vote
1answer
93 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, ...
2
votes
1answer
51 views

Any way to execute vimscript beside yanking and doing @" on the commandline?

I'm used to just yanking and pasting the register @" into the commandline to execute vimscript, when I'm doing testing experimentation (since it's faster than pasting it into the .vimrc) Any ...
1
vote
1answer
32 views

“Could not pop the stack error” in vimwiki function

Got a vimwiki function: function! vimwiki#base#is_diary_file(filename, ...) abort echo a:filename let l:diary_file_paths = a:0 > 0 ? a:1 : vimwiki#diary#get_diary_files() let l:...
2
votes
1answer
297 views

What is {what} supposed to mean in the official documentation?

I keep seeing mention of {what} here and there, mainly in eval.txt, popup.txt, terminal.txt, syntax.txt, and channel.txt. From :h popup_create() popup_create({what}, {options}) Open a popup window ...
2
votes
1answer
46 views

Finding where one word is close to another word: parametrized command in vimrc

I asked this question, about how to find where one word is close to another word, and Quasimodo gave the very fine answer: /\vaid(\W+\w+){,3}\W+country Now I want to parametrize this command into ...
3
votes
2answers
457 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", &...
1
vote
1answer
133 views

Any recommended ways to debug vimscript?

I'm interested in different ways to debug/trace or/and see the execution in real time (a la bash -x) vimscript.
1
vote
1answer
73 views

How to run a <SID>SomeString normal mapping?

After reading help I've started experimenting with a kind of a weird type of mappings — ones that are strings to be emitted and captured and not entered by user. So inside a script I've created: ...
0
votes
1answer
325 views

Why does ViM use VimScript? [closed]

As a person that is interested in the tools used to build useful software Why does ViM need a built-in language such as VimScript ( VimL )? Why It cannot be just C?
0
votes
1answer
42 views

How to identify the script that's calling a user command?

I have a problem: I need to pass « any » caller-session trace into a user command… Was trying with: command WantToKnowWhosCalling call Impl("\<SID>", \ expand("<SID>&...
2
votes
2answers
88 views

Set line number on chunks of file

Following an example such as: ##1## many text and lines ##z## ##2## more text ##z## ...etc How could i make the line number display only on chunks of text, inside of the ##digit## and the ##z## ...

1 2
3
4 5
24