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
0answers
13 views

How can I use let `g:netrw_keepdir = 0` for folders and `autochdir` for files?

Normally I want to use autochdir to change to the directory containing the file which was opened or selected However, in netrw, there's a warning However, the autochdir option: :set acd is ...
0
votes
1answer
18 views

Using a vim syntax file, I would like some Keywords, such as ??, to be colored

I have been trying to get through the syntax file documentation on vim help, https://vimhelp.org/syntax.txt.html#%3Asyn-files but it's quite the read and I figured someone here may know how to go ...
1
vote
0answers
27 views

Write a custom linter for ale to consume the output of command line utility

I am trying to write an ale linter for the norminette program. How can I make it work ? It's a program that checks if C source code files follow the coding norm of the 42 school network and it would ...
0
votes
1answer
29 views

How do I send the output of an :r! command to another Vim command?

I would like to edit some text before dumping it into the Vim buffer. I retrieve the content of a webpage with :r! w3m -dump someurl.com. I would like to delete everything in the returned text from ...
0
votes
1answer
24 views

choose template option for newfiles in vim

I have different templates in this directory ~/Documents/Library/ like: Template.cpp, normal.cpp, advanced.cpp normally i use this autocmd BufNewFile *.cpp 0r ~/Documents/Library/Template.cpp I want ...
0
votes
1answer
19 views

Spaces in mappings: where to put them and where not?

The question is actually rather short, don't be afraid. :-) I'm Russian, and so to tweak Vim in a way it will understand its commands even if a Russian language is currently active, I have the ...
0
votes
1answer
16 views

difference between `wildignore=` and `wildignore+=` in vim

I have seen many vimrc's which have wildignore+= and i don't know what it refers compared to wildignore= others like: clipboard= and clipboard+= some configs have also like clipboard-= Can anyone ...
0
votes
2answers
37 views

how to make a word turn into certain commands in vim command line?

I want :cup in vim command line to turn into :tabdo call MapRunCmd()<CR> Hope that somebody can help me out PS: I've tried this nnoremap :cup :tabdo call MapRunCmd()<CR> but didn't like ...
2
votes
1answer
39 views

What is the purpose to use "==#" with empty string?

The following is from vim-sensible plugin: set incsearch " Use <C-L> to clear the highlighting of :set hlsearch. if maparg('<C-L>', 'n') ==# '' nnoremap <silent> <C-L> :...
0
votes
0answers
34 views

Need help to make a by-default `:RunWithFile` of this toggle function

related to this post, How to make a toggle function in .vimrc that toggles multiple configs of almost same type? @BLayer's code func! MapRunCmd() abort if exists("b:rwfcmd1") && ...
0
votes
1answer
51 views

How to make a toggle function in .vimrc that toggles multiple configs of almost same type?

My .vimrc code autocmd FileType cpp nnoremap <F4> :RunWithFile autocmd FileType cpp nnoremap <F4> :RunWithFile ~/Downloads/ > output.txt && cat output.txt<s-left><s-...
1
vote
1answer
65 views

Explore command not working in Terminal normal mode

In vim, I open a terminal using :term and enter the normal mode using <C-w> <N>. Then, :Explore does not open the vim's file navigation view, but creates a another split window of the ...
1
vote
1answer
47 views

silent vs. silent! - What is the difference?

This might be a silly question, or someone may say it lacks research, but I really cannot understand what does the exclamation mark after silent mean. For example, in the following function that ...
0
votes
1answer
39 views

Why vim creates an extra last line when importing a template?

My init.vim code: autocmd BufNewFile *.cpp 0r C:\Users\User\Desktop\cp\Template.cpp When i create a .cpp file, Template.cpp code is imported in that cpp file. upto this point, everything is fine. ...
0
votes
1answer
54 views

Non-interactively call a user defined vim script function and pass the buffer?

How do I non-interactively call a user defined vimscript function, and pass it the buffer? My best guess is below, but it doesn't work: echo "110511093 some dude" | vim -es ':call ...
2
votes
1answer
33 views

Create a new matching-tag-pair textobject?

Vim provides a builtin textobject t that captures a matched pair of HTML tags — so e.g. if you start with this <i>that█ <b>those</b></i>, then typing dat in normal mode leaves ...
1
vote
1answer
21 views

How to check if a dict has a specific key?

In Vimscript, how can one check whether the dictionary my_dict has the key abc? Something like this: echo 'abc' in my_dict " The above naive approach gives "E121: Undefined variable: in"...
0
votes
1answer
15 views

system(cmd) fails if cmd includes # character

I have been trying the https://github.com/ngemily/vim-vp4 plugin for integrating Perforce version control commands into Vim. The Vp4Diff command fails for me. I tracked it down to a step where a ...
0
votes
1answer
14 views

How to separate the negative and positive values from 3rd column in vim file?

I am dealing with a long data in the vim file. I want to separate the positive values and negative values in the 3rd column in separate files. Example: 1.000 3.889 4.666 4.889 2.809 -8.687 3.896 4....
0
votes
1answer
14 views

Unable to resume backgrounded Neovim-terminal-emulator-process using `kill -CONT`

So, I'm trying to find an actual solution to another question on here that doesn't really have one. However, I'm running into a problem with backgrounding/foregrounding behaviour. I need to background ...
1
vote
1answer
119 views

How can I expand a:000 list in order to pass through all varargs parameters to another function?

I have a varargs function, which I want to refactor to include a separate 'argument handling function' first, so that that becomes separately callable. I've read :help function-argument but was unable ...
0
votes
1answer
40 views
2
votes
2answers
130 views

Vim 8.2 no user defined functions

Yesterday I updated Vim to version 8.2 thru my Linux distro repositories (Fedora). And now I noticed that no user defined functions exist. They worked just yesterday, before the update. I define ...
3
votes
1answer
61 views

Inserting strings with `<plug>` inside `<cmd>`

When using <cmd>...<cr>, there are some special keys such as <plug> or <cmd> that are not allowed to be contained inside the block. Trying to execute the command will result in:...
1
vote
1answer
26 views

How to copy contents of wl-clipboard into a Vim register?

I would like to swap content between my system clipboard and a Vim register. I am missing one last piece of the puzzle, indicated below. Any thoughts? map <Leader>" :call SwapBuffer()<CR&...
2
votes
1answer
57 views

How to quickly search for today's date in a file?

Question How does one effectively find today's date in a file? The format of the date is given by GNU's date(1)'s command as: $ date '+%a %d-%m-%Y' Mon 16-08-2021 What I already tried This is how I ...
1
vote
2answers
57 views

Moving to special marks inside opfunc

I'm trying to write a opfunc which surrounds selected motion with two stars (bold in Markdown): nnoremap <localleader>b :set opfunc=BoldIt<CR>g@ function! BoldIt(type, ...) execute &...
1
vote
1answer
43 views

How I can add <C-6> to a mapping

I am trying to create a mapping that will close the current buffer and replaced by the previous buffer. I tried this noremap <silent><Leader>bd :<C-6><Bar>bd #<CR> But ...
0
votes
1answer
31 views

How to get the union/merge of dictionaries?

I'd like to combine two nested dictionaries following these rules: if value is not a dictionary, override the key in resulting dictionary if value is a dictionary, compute union of the two. Example: ...
1
vote
2answers
86 views

Is it possible to detect if shiftwidth/tabstop/etc was set in modeline

I have my own detection of the file indent settings based on the file contents. All good and works ok for my needs but... When I open a c source file of the vim itself it overrides options set by ...
1
vote
2answers
49 views

How to make an user-defined command that works in normal and visual mode?

Goal I would like to create a command that can automatically put an x inside a []. This command should work in both normal mode and visual mode. normal mode If it is in normal mode, and the cursor is ...
0
votes
2answers
37 views

Delete until the start of next visible line?

I'm using MacOS. As title, for example before the command: $('h1#title') .css({'font-size': '80px', 'text-align': 'center'}_)_ .text() .testing() .tset() (Notice that the blank line ...
0
votes
2answers
32 views

How do I convert a file mark to a string?

If I for example create a mark inside the file ~/.vimrc with mV. How do I convert the mark 'V to the path of the file the mark is in? When I type :marks I can see a list of marks and the corresponding ...
0
votes
1answer
24 views

substitute() with ampersand in replacement

I’m doing something like this: let l:new = substitute(l:old, l:word, l:repl, ‘’) l:repl comes from an external source and often has an ampersand in it. Is there a way to prevent vim from interpreting ...
0
votes
1answer
30 views

How do I load the same script multiple times?

I would like to have a line in a vimscript that would load this exact script once again. What I tried to do is to: firstly set the guards, like if !exists("g:second_load") (and it worked), ...
0
votes
2answers
23 views

Compare string and 0

I just stumbled upon this strange problem: echo 'test' ==# 0 This returns 1. Therefore it is true. But in "reality" it is not true. Any string is different from 0. How to do this check? For ...
0
votes
1answer
24 views

How to detect if script is running in floating window using vimscript?

The title pretty much says all. I have the following custom script (which resizes windows for me): " CUSTOM WINDOW SPACE MANAGEMENT ************************************ function! s:...
0
votes
1answer
20 views

force close windows and last empty buffer

when i open multi windows like bellow: vim foo.txt bar.txt then , if i'm closing foo.txt by :bw then ,i'm closing bar.txt by :bw vim still open ! , i must close by :q i don't want vim open if last ...
0
votes
0answers
13 views

how to mkview *.cpp file if and only if a fold is made within the file?

My init.vim code cd ~/Documents/cp set backupdir=~/Documents/cp/vimtmp// set directory=~/Documents/cp/vimtmp// set undodir=~/Documents/cp/vimtmp// set viewdir=~/Documents/cp/vimtmp// augroup ...
0
votes
2answers
53 views

Function-local inner functions

These exist with lambdas function A() let B = { -> 'thing' } endfunction // B does no exist But the lambda returns a value and not a sequence of commands. (I know I could put execute("..&...
1
vote
1answer
33 views

how to tabdo all the visible buffers without changing the current tab?

My init.vim code: cd ~/Documents/cp nnoremap <leader>lcd :tabdo lcd %:p:h<cr> suppose, i have 4 tabs opened in nvim via using nvim -p A.cpp B.cpp C.cpp D.cpp A.cpp B.cpp C.cpp D.cpp ...
1
vote
3answers
201 views

Can I open a file using the index shown by ":scriptnames"?

I am wondering how to open a file or load it into a buffer using the index shown by :scriptnames? 23: /usr/share/vim/vim80/plugin/tarPlugin.vim 24: /usr/share/vim/vim80/plugin/tohtml.vim 25: /usr/...
1
vote
1answer
71 views

How to pass a shell command to a vim function and execute it in the neovim terminal?

I've recently switched to neovim (NVIM v0.4.4) from vim. Previously in my .vimrc file I had these two mappings that allowed me to run javascript and c++ files inside vim. nnoremap <f4> :!node %&...
1
vote
1answer
52 views

Redirect output to a persistent window that respect window layout

So this is a continuation of my adventures into creating my first plugin ;-) Today's issue is that I want to execute some shell command, and redirect the output to a separate window that respects my ...
1
vote
1answer
44 views

Character level buffer modification

It is possible to modify buffer at the line granularity. E.g. :py3 vim.current.buffer[0] = "abc". But it deletes the attached marks even if a single character is replaced. Is it possible to ...
0
votes
1answer
57 views

smart single or multiple character deletion of x

I want vim to ignore whitespace copy Default cut x will work same but When i cut one whitespace character or a visual block of whitespaces with x, vim register won't copy like this thread, Vim ...
0
votes
0answers
22 views

Does vim have support for processing its comma-separated options?

Vim has comma-separated dictionary options like 'comments' and 'listchars': :set comments? comments=s:--[[,m: ,e:]],:-- :set listchars? listchars=tab:⇥ ,trail:␣,extends:⇉,precedes:⇇,nbsp:⚭ Commas ...
3
votes
4answers
126 views

How to open current directory in File Explorer by vim?

The problem is solved My purpose is that: I use vim to edit my m-file and debug it in Matlab. There is no easy-to-use interface plugin between vim and Matlab in Win10. So I just edit m-file in vim ...
0
votes
0answers
19 views

how can i define g:errorMessageString as a List?

related to this thread Multiple error messages in vim message history How can i define g:errorMessageString as a List? Can anyone help me fix this? i am using this code in my vimrc but i don't know ...
0
votes
0answers
32 views

How can vim show multiple files are changed on disk?

How can vim tell me which buffer is changed on disk among multiple buffers? related to this thread, @b-layer helped me my current vimrc code: set autoread autocmd FocusGained,BufEnter,CursorHold,...

1
2 3 4 5
25