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
0
votes
1answer
19 views

When hitting Enter keyboard on a file path, open a new tab with the file content

I'm new to vim language and I'd like to see a new tab opening when I hit the enter keyboard on a line containing only a path of a file. When I create a map like this nnoremap <buffer> <cr> ...
1
vote
1answer
35 views

why doesn't regex work in vimscript (while it does in normal search)?

I have simple regex to search for lines that only contain alphabetic characters: ^\(\a\)\{1,}$ which works in normal search /^\(\a\)\{1,}$ but not when invoked from my script: "in .vimrc file: ...
3
votes
2answers
147 views

Reversing all characters on each line of a range

In order to invert all characters on each line of a range I could think of the following :s/.*/\=list2str(reverse(str2list(getline('.'))))" where I can put a [range] if I want. Is there any ...
0
votes
1answer
36 views

Get visually selected text - weird behavior when last selected char is multi-byte

I have made a simple function to echo the visually selected text. The function is simplistic as I am only interested in max one-line selection. The problem is, if the last character of the visual ...
1
vote
0answers
28 views

Conditional mapping for two plugins (UltiSnips and Vimwiki)

Vimwiki table default mappings include <tab> for moving to the next table column in insert mode. Also UltiSnips default mappings include <tab> for expanding snippets in insert mode. Here ...
1
vote
1answer
51 views

Get list of marks inside Vimscript

some time ago, I wrote a small plugin in vimscript that was using builtin function getmarklist. Recently I reinstalled Vim and was surprissed that this plugin no longer worked because Vim couldn't ...
0
votes
1answer
33 views

Vim function : how to expand vim variable in shell command?

I'm trying to write a vim function to update ctags and cscope databases. I'm trying to save the vim variable projectRoot in environment variable then expand this enviroment variable in the find ...
0
votes
1answer
27 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
27 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
29 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
34 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
18 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
14 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
30 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 ...
-1
votes
0answers
21 views

`ci{` doesn't detect the first {} on the line as `ci"` does [duplicate]

On the following line (the cursor is |): |some text "in quote" etc if I do ci", I'll end up like this: some text "|" etc which is great, because I don't have to manually ...
0
votes
1answer
22 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
39 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
19 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 ...
2
votes
3answers
319 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
34 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
55 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
24 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
30 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
18 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
41 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
21 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
19 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
68 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
47 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
37 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
101 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
26 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
23 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
997 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
56 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
16 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
26 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
23 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
39 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
75 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
39 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
111 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
58 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
40 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
46 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
16 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:...

1
2 3 4 5
22