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
6 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
10 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
44 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
24 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
190 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
49 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
48 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
37 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
50 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 ...
-1
votes
0answers
23 views

To show in vim, which lines of working file are changed on disk

related to this thread, How can vim tell me which buffer is changed on disk among multiple buffers? My vimrc code set autoread autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' | ...
0
votes
0answers
17 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 ...
2
votes
4answers
68 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
18 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
29 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,...
0
votes
1answer
23 views

How can vim tell me which buffer is changed on disk among multiple buffers?

I am using this code in my vimrc if a file is changed outside vim, it shows File changed on disk. Buffer reloaded. set autoread autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * if mode() != 'c' |...
0
votes
1answer
39 views

Cycle through a list of letters in multiple groups - Code review

This is a follow up question to Cycle through a list of letters in multiple groups where I asked how to cycle a group of letters. I got a bunch of great tips and this is my follow up question. This is ...
0
votes
1answer
10 views

How to test if the current file is in some directory?

I want to have a piece of vimscript (a custom formatter) only apply if the current file is inside some directory. How can I tell whether the active buffer is within a particular directory?
1
vote
4answers
362 views

How do I change the word under the cursor?

I've written a little function that changes a 'CamelCaseWord' to a space separated 'camel case word': " Convert a CamelCase word to space separated words. function! s:converFromCamelCase(arg1) ...
2
votes
1answer
101 views

how to include multiple commands nested inside a single `autocmd BufRead…`?

I want to make several keybinds and options set for certain files based on their location. Is there a more elegant way than... autocmd BufRead,BufNewFile /tmp/wiki-tag-reports/* nnoremap <Enter>...
0
votes
0answers
25 views

Is there a way to detect whether a `:normal` command is executing, or if the input is actually typed in?

Ideally, I'd like to have different behavior for those two cases. For macros specifically, there is reg_executing, but I don't know about any way to achieve the same for a general :normal command. (I ...
0
votes
1answer
41 views

how to conditionally re-bind <Enter> key depending on file

My vimwiki plugin has Enter key bound to the function to create a "hyper"-link to another file (and if it already is a link then open the linked file to view/edit). I want to be able to jump ...
0
votes
2answers
36 views

Function only executing first “execute” statment

I'm trying to make a vmap that takes a count and then indents all the highlighted lines so that the top one is more than the line above it, while keeping all the lines' relative indentation. I have ...
0
votes
1answer
31 views

Can I define a function with '#'-namespace in a file with hyphen '-' in its name?

I often see #-namespaces in plugins source code, e.g coc#status(), fzf#run(), fugitive#extract_git_dir. I would like to use namespaces in my own config, mappings and commands source code also. But I'm ...
1
vote
0answers
19 views

cannot run `:normal s<CR>` just for nerdtree (opens file vertically splitted)

what im trying to achieve: use <C-V> to paste text in normal mode in current buffer use same <C-V> to vertically split a file from nerdtree what i know: when you are with your cursor in ...
1
vote
0answers
30 views

neovim, vimscript execute keystroke from function

I am trying to execute a keystroke from function when its called. However, it does not work. function SmartNERDTreeFocus() if expand('%') =~ 'NERD_tree.*' normal <C-w><C-p> ...
0
votes
0answers
21 views

`echohl` not highligthing with custom color, but its working with the defaults

in my init.vim (.vimrc) file i have this: hi TerminalGreenColor guifg=#6bd676 function! EchoInitVimReloadedSuccessfully() echon " -- [ " echohl Identifier echon "init.vim&...
0
votes
1answer
23 views

How to create an abbreviation that matches a regular expression

I'd like to create an abbreviation that will change the following (in a markdown file): - list item 1 into this: - list item 1 Whenever I type - f it should be expanded to - f (from 1 space to 3 ...
0
votes
1answer
42 views

How to curry a function in vimscript?

I am trying to curry a function in Vimscript to map an operator. I have a function written in Lua, and I want to pass 'n' or 'v' to that function, depending on the mode that trigger that mapping. ...
0
votes
1answer
33 views

Define default value to a variable

I want to assign an expression to a variable, and if it has no value, use some default. On almost every programming language I can use something like: let linked_hl_id = hlID(l:linked_group) || 114 ...
0
votes
0answers
27 views

different highlight if a certain highlight is on

I'm writing a function to highlight current word, but on commented out lines, I want a different highlight to apply. Example: Notice how the word exists is highlighed, but on a grey commented out ...
0
votes
1answer
22 views

Assign value based on filetype [duplicate]

I want to assign value based on filetype. I am using UltiSnips plugin and want to have one set of bindings for one filetype and another set for everything else. Something like if &ft='vimwiki' ...
1
vote
2answers
56 views

How to apply alternating caps?

Fast way to type or change to AlTeRnAtInG CaPs?
1
vote
0answers
26 views

Center-align command bar and/or tabs bar

I'm often using vim fullscreen on an extrawide monitor (multiple splits, including terminals). Because both the command bar and the tabs bar span the full terminal width and are left-aligned, commands ...
2
votes
2answers
65 views

Making functions react to keypress

Im very new to vim scripting. I have the following script in my .vimrc: If there is no user input aka I press <CR> => go to recent buffer If input is 'd' => delete all buffers except for ...
0
votes
1answer
23 views

How to put sync region start=<this> into a variable?

I have the following code: com! -nargs=* ShFoldFunctions <args> fold ShFoldFunctions syn region shFunctionOne start="^\s*[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\s*()\_s*{" end="}&...
1
vote
2answers
65 views

Manipulate the dot command without editing text in insert mode

I need to manipulate the dot command without directly editing the buffer for a plugin I'm developing. The plugin needs to manually append text to the dot command that will be executed while in insert ...
0
votes
0answers
34 views

Emulate Emacs-like Mode

I'm used to Emacs different modes, that is: Setting up functions/setting once entering a specific Mode Renaming the statusbar with the name of the Mode "Cleaning up" (resetting setting to ...
1
vote
1answer
23 views

vimscript to insert function result is not inserting with proper formatting

I have a function that I want returning pre-indented xml: function! InsertStep() let stepTemplate = "<step index=\"\">\n \ <description></description>\n \ ...
1
vote
2answers
65 views

How to substitute filename on reading or opening new file

We have rather complex file structure and I would like simplify opening file independently where am I in the filesystem at the moment. Let's say we have a project_folder and several files in it: /...
6
votes
2answers
1k views

Why is `let foo = $HOME/bar` invalid?

Why is let foo = $HOME valid and let foo = $HOME/bar invalid in vimscript? I have tried let foo = "$HOME/bar" but it is the equivalent of foo = '$HOME/bar' in shell script, $HOME is not ...
2
votes
1answer
24 views

vimscript to skip a block of text with lines containing similar words

I need a little help with some vimscript-ing. I have a huge log file with multiple blocks of text resembling the following: [log file start] ... ... Information: Setting NDR rule shield_rule on net a ...
1
vote
1answer
107 views

Auto pairing using strings instead of characters

I'm already aware of existing solution to automatically "surround" sentences/word/etc (eg: auto-surround, vim-surround, etc) but those (as far as i know) don't support using normal strings ...
0
votes
0answers
29 views

Chronologically store visual selections in a buffer

My goal is to enhance the usage of gv with counts, in order to access older selections quickly. Such that 2gv would reselect the selection made before the last. Vim doesn't have events for entering ...
2
votes
1answer
47 views

Passing arguments function with --argument or -a format

Is it possible to pass arguments to Vimscript functions with the --argument or -a format, similar to arguments in the command line? I am writing a command that submits a job in a remote machine. I ...
0
votes
0answers
28 views

Measurement/ tracking the time for editing a file (overall and statistics)

I use vim for coding and also for writing scientific articles and book chapters. It would be very interesting to know the time I spent on a file. For example how many hours or minutes the buffer was ...
0
votes
1answer
31 views

How to detect the change that from insert mode to normal mode, so I can implement Auto-Save?

I want to do the following: autocmd changeFromItoN * if &readonly == 0 && filereadable(bufname('%')) \ | silent update | endif That is: I want to implement the ...
0
votes
0answers
27 views

Open file in new tab or split if current file has changes in fzf.vim

I have been using :Files to get a list of files using fzf.vim. Although whenever I hit enter to open a new file and the current file has not been saved I get an error message saying No write since ...
0
votes
1answer
44 views

Remove text specifying mode “INSERT” in bottom vim line

In the bottom two lines, you'll see the statusline saying "INSERT", and the line where you enter commands showing -- INSERT -- This is quite redundant, and I would like any recommendations ...
0
votes
1answer
27 views

how to autocmd BufWritePost stdout to tidy upon :w?

tldr; How do pass stdout of BufWritePost to an external command? On command line I can run cat index.html | tidy -indent -modify I'm trying to call tidy automatically when I :w This is what I have so ...
0
votes
1answer
24 views

how vi automatically collapses {}

I always come across a lot of code wrapped in {}s while reading, and I wondered if there was a way for vi to automatically fold these {}s instead of manually marking them.

1
2 3 4 5
25