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
28 views

How to put Shift+v in a function?

I'm trying to apply the Shift-v keymap in a vimscript, but not sure how. I tried using <s-v> and Shift-v without success.
1
vote
2answers
332 views

Check if a specific window is open

I have a window in vim opened (current file) and another one in split called [Scratch]. I want to check if the [Scratch] is open or not. Any example is appreciated.
1
vote
1answer
82 views

How to use read instead of execute in a function?

I'm trying to search for the selected line of a file using the following: function! GrepSelection() normal! gvy let result = escape(@", '\\/.*$^~[]#') let result = substitute(result, &...
3
votes
1answer
50 views

How can I make a new line in my _vimrc after using the normal i command?

I'm very new to Vim and I have some ASCII art in my _vimrc. I've inserted it there using normal i, but it doesn't display properly, because the normal i commands don't have a line break at the end. I'...
4
votes
2answers
106 views

How to open folds in a pedit-preview popup window?

I'm displaying a file contents by using :pedit …the-file-path…, to then call popup_setoptions(…the-ID…,#{firstline:anumber}) in order to scroll the popup and highlight/show the desired part of the ...
1
vote
1answer
55 views

Vim filter command not using line-wise selection

I may have seen this question before on Vi Exchange but I'm having trouble locating it while searching now. If it's already been answered, please let me know the duplicate and I can find that. I have ...
4
votes
3answers
835 views

create own snippets

I'm rather new to vim. And I don't like much to install many packages. I use html, javascript and react.js, and i would like to create some simple way to type and then have the correct snippet on the ...
1
vote
1answer
123 views

get vimrc or init.vim defined by -u switch in vim/neovim

According to :help starting, we can specify a specific vimrc file using the following command $ vim -u /path/to/vimrc How can I access the path of that vimrc/init.vim file in vim/neovim? I have ...
2
votes
3answers
154 views

VIM mouse scrolling on Konsole show ^[OA at the top and ^[OB at the bottom of the page

function! GitBranch() return system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'") endfunction function! StatuslineGit() let l:branchname = GitBranch() return strlen(l:...
0
votes
1answer
129 views

how to use variables in vimscript shell commands

I have this code intended to: read current line extract variable from end of line, looking for text like #ad04e482 search for filename that begins with the string ad04e482 open that file to edit in ...
4
votes
1answer
56 views

Set variable equal to search match subsection

Unnecessary Context: I want to write a function that closes open HTML tags, because closetag.vim seems complicated, and I like to understand all the stuff I run in Vim. My plan for this is to match ...
1
vote
2answers
339 views

Global options as function local variables

I'm asking about this code snippet: :function TextwidthIsTooWide() : if &l:textwidth ># 80 : return 1 : endif :endfunction This is what vim-help says on the l (local) prefix: Inside ...
2
votes
2answers
89 views

How to return first match from search

Following my question about some search pattern in vim, I would like to get the the text corresponding to the first match (if any) of my search pattern wich includes cursor position and is multiline. ...
3
votes
2answers
165 views

Can't repeat negated pattern using \@!

I have this text: ```python x = 1 ``` Basically markdown python cells. I would like to extract the content of the cell surrounding the cursor, if any. As you may have guessed already, I am trying to ...
1
vote
1answer
60 views

In VimScript what is the best technique for changeing the text when the cursor moves away?

I am new to vimscript. I am trying to figure out how plugins like vimwiki or vim-note reformat the visible text. I know how to use the syntax highlighter to highlight, bold, underline, strikethrough, ...
0
votes
1answer
57 views

How are quotation marks used in this dotfile?

I'm a complete Linux beginner, trying to understand dotfiles. I've got the .vimrc dotfile, and tried to add the following command to the bottom: " <Ctrl-l> redraws the screen and removes ...
2
votes
1answer
108 views

Why does invoking “normal!” in insert mode cause error “Not allowed here”?

New to vimscript. I am trying to invoke a function in insert-mode. The function is a bit complicated, but I am stuck at running "normal!". Here is the mapping: inoremap <buffer> <...
1
vote
1answer
26 views

How can I alter the window to which ctrl+w, ctrl+p will jump to?

What I'm looking for is a programmatic way of changing which window Ctrl+w, Ctrl+p will jump to. The reason why I want to do this is that I have an autocmd like the following autocmd BufEnter ...
0
votes
2answers
113 views

How to iterate over a directory of files in vimscript?

I have a directory ~/.vim/rc.d/ that houses various configuration files. I like this pattern for configuring various things in my homedir because it modularizes configuration options. The problem is ...
2
votes
1answer
280 views

Vimscript: evaluating the contents of a variable

I know I can evaluate a (visually) selected piece of vimscript by yanking it into a register and then executing the register with :@registerName. Can this be done without clobbering a register e.g., ...
2
votes
0answers
24 views

Can you read the value of `showcmd` in a vimscript function?

I don't know how to make any vimscript I'm writing or running aware of what my pending command is! Specifically: When I hit ^W in preparation to change the window I'm selecting, I'd like to have my ...
0
votes
0answers
62 views

How to hide a buffer thru vimscript, with buffer number or buffer name

I'm trying to make a plugin that hide and show a terminal window on the bottom of the window, but i can't find a reliable way to hide a specific buffer, i tried using hide but you only can hide by ...
1
vote
1answer
174 views

Improve copy to clipboard using xclip

I'm trying to improve the answer here for copying to clipboard in a vim without the +clipboard option. The problem with the above approach is that :w always writes the entire line, so it is not ...
1
vote
1answer
121 views

Change comment char based on filetype

I am playing around with asm, which uses ATT syntax. For the filetype asm, vim is using the comment char ;, though it should be #. How/where can I change the comment char per file type? Note that I am ...
4
votes
1answer
91 views

Count lines matching a pattern

I'm trying to obtain the number of lines matching a pattern, from a function. I would like the cursor not to be moved at all during the process. In this case, non-empty and non-comment lines. Here's ...
1
vote
1answer
193 views

Syntax in autocmd command to compile and run cpp code

From this post here: https://stackoverflow.com/questions/540721/compile-directly-from-vim One of the answer is: autocmd filetype cpp nnoremap <F4> :!g++ % -ggdb -o %:r <CR> autocmd ...
1
vote
1answer
27 views

add second column next to line number column

I would like to create a second column next to the line number column. It shall behave identical to the line number column, i.e., move up and down when scrolling. Ideally its content should be ...
2
votes
0answers
34 views

How to delete the previous buffer when loading new result from quick-fix window?

In the quick-fix window, if I'm loading new results, the previous buffers stay which I don't want. I want only those buffers to stay which I open intentionally (e.g. to write new code, do diff of ...
1
vote
2answers
191 views

How to get the line numbers for all matches?

How can I get the line numbers of all matching strings in a buffer? Like in this buffer, I want to get the list [1,6,50] of all line numbers with matching strings. 1: test .... 6: test .... 50: ...
1
vote
1answer
35 views

Inconsistent behavior from map

I've got map that grabs the title and url from the browser and generates a markdown link from it: inoremap <Leader>gg [<esc>:set fo-=t <cr>:silent !~/bin/copy_safari_title.osa <cr&...
0
votes
1answer
122 views

Un-tab the cursor

Is there a way in vim to move backwards a tab as it does move forward a tab? For example, if my line is: * * * * * * hello | = 4 ^ ^ cursor ...
0
votes
0answers
29 views

Tagbar line numberings being overwritten

I'm trying to use the Tagbar line numbers: " Show line numbers (0 = none, 1 = absolute, 2 = relative) " note: this doesn't work well and is often overwritten by rnu settings let g:...
0
votes
2answers
21 views

How do you use a variable as argument to another vim command? [duplicate]

I have the following function: fu! EditFileInBrowser() let l:url = @+ let l:url = substitute(l:url, 'http:\/\/127\.0\.0\.1:4000\/', '', '') let l:url = substitute(l:url, '/$', '', 'g') let l:...
0
votes
1answer
24 views

Doing multiple backspaces in a command

I have a script where the first line works: execute "normal!i\<BS>l" But this line does not: let BS = repeat('\<BS>', NUM_CHARS_TO_DELETE) execute "normal!i" . BS It ...
0
votes
0answers
45 views

How to clear and write current buffer in a function

New to vimscript. I'm writing a function that I want to be able to clear the contents of the current buffer and write this to the corresponding file (or alternatively, clear the contents of the file ...
0
votes
2answers
85 views

How can I view a list of all of the features that can be checked for using `has()` in Vim?

How can I view a list of all of the features that can be checked for using has() in Vim? I recently came to know the has() function for testing the presence of "features" (see below). :h ...
15
votes
2answers
4k views

What does three commented curly brackets ("{{{) at the end of a line mean? Is it just a comment?

In the tcomment plugin, specifically in: ~/.vim/pack/tml/start/tcomment.vim/autoload/tcomment.vim and ~/.vim/pack/tml/start/tcomment.vim/plugin/tcomment.vim I'm seeing this at the end of some lines: ...
1
vote
1answer
39 views

How to create mappings with a function?

I am trying to create a function in vim that is capable of creating mappings for me. This is so I don't have to type out very similar commands over and over in my vimrc. Take these two mappings as ...
4
votes
1answer
387 views

How to stop Vim from sourcing a file halfway through? [duplicate]

I'm mostly a Neovim user and I would like to share part of my config with regular Vim. Here's the problem: my init.vim is organized in such a way that at the top there are the general Vim options, ...
0
votes
0answers
20 views

How to follow while searching regex in vim? [duplicate]

In my previous vim, when i typed /something and after reaching upto so vim started immediately following and with each letter typed i got into new word until i got the perfect. However this following ...
1
vote
1answer
65 views

Why cant i use `"+` in vim? [duplicate]

Previously, whenever I typed "+yy in vim, it yanked a line to the system clipboard. I reinstalled the OS again, and, when I try to do the same now the input disappears after entering +. Steps: I ...
1
vote
1answer
58 views

Quit script after a certain condition is true

I have a script that checks for a certain condition (it checks if pip dependencies are installed). If they are installed and everything is ok, I want to import a bunch of python functions from my ...
1
vote
0answers
53 views

Local “statusline” override problem

I'm currently writing a plugin, and got stuck with this problem. My plugin opens a new window with all local options I want, but also sets the statusline option to display some useful information. Vim ...
1
vote
0answers
33 views

embed one text file in another and edit the embedded file from the file it's embedded in

Is there any existing plugin or gist somewhere that would allow you to embed one text file inside another? Ideally it'd also allow editing the embedded file from the file in which it is embedded. ...
0
votes
0answers
13 views

Paste into search instead to buffer with vim-fuzzyseach?

I’m using this plugin and find it useful with its regrex search and as it’s not updated recently, I find that when I map it to / to replace default function search of vim and then try to paste text ...
1
vote
1answer
117 views

Update a Vim Session file's loaded plugins without losing window positioning

I have a Vim Session file I created by doing: :mksession Then I quit Vim. I then downloaded a plugin to: ${HOME}/.vim/pack/vendor/start/vim-markdown-folding and then I fired up Vim with the session ...
1
vote
1answer
69 views

Text to vim-quickfix with navigation

LaTeX, being a markup language, is very hard to grammar-check. I found one program, that do this exactly Textidote. Problem is, this is a standalone program and, for example, this latex code: \...
1
vote
1answer
24 views

Compare with hex

How to compare with hex? Wanted to test I had it right. At first I thought let a = 13 if a == "\x0d" | echo "Match 13" | else | echo "Not 13" | endif " => Not ...
0
votes
1answer
143 views

Organize plugins and .vimrc settings for different filetypes using ftplugins?

I'm new to vim (8.2) and have been learning how to set it up on my computer (Ubuntu 18) for the past few days. I'd like to configure VIM so that when I open code in different programming languages, ...
1
vote
1answer
33 views

Why do plugins have to check if they are already loaded?

I noticed that most of the plugins I use have a line at the start that checks if the plugin has already been loaded. It often looks similar to this: if exists("g:loaded_commentary") ...

1 2 3
4
5
24