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
194 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
80 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
388 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
114 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
168 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
64 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
75 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
112 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
27 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
181 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
378 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
29 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
71 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
223 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
176 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
117 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
237 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
35 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
38 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
260 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
134 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
36 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
25 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
53 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
153 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
422 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
70 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
77 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
56 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
34 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. ...
1
vote
1answer
166 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
79 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
26 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
191 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
34 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") ...
0
votes
0answers
27 views

How can I display text differently from how it is actually stored?

I am making a custom syntax partially based on Markdown. I want to display links differently from how they are stored in the file. For example, [About me](about.md) in the file should be displayed as ...
1
vote
0answers
12 views

Get comments LINED UP in 65c816 asm syntax [duplicate]

I've been writing some 65c816 assembly lately. They have some interesting commenting conventions that I was hoping VIM could help me with. LDA $E7 ; You see, they BEQ IfZero ...
1
vote
1answer
272 views

How to populate the preview window?

I need to show a 'prompt' in the preview window when the user makes a selection of an item in a popup window, which is similar to the way the tern-for-vim completion plugin does in Javascript files, ...
0
votes
1answer
97 views

How can I have lnext/lprev fallback to cnext/cprev when appropriate?

It is often the case that I am in projects with varying filetypes. Sometimes I'm compiling using :make<CR> and sometimes I'm using plugins like ALE. At any given time, I probably only have one ...
1
vote
1answer
31 views

Ways to improve a function

Perhaps this is more of a 'code-review' question, but I think this is perhaps the best (or only) place to post this question. I've been working over the past few days to understand how vim functions ...
0
votes
0answers
15 views

hlexists() for hilight group name or syntax groupname, or both?

My understanding of how hlexists() work is that it checks for groupname. I am assuming that there are two kinds of groupnames: highlight syntax Does it work not only on groupname provided by the hi ...
1
vote
1answer
18 views

Vimrc syntax move up and down a certain line continously

So I am new to Vim and I am trying to understand the language of vimrc. I have this in my vimrc: map <F8> <C-E>: sleep 100m<CR>j<F8> This would automatically move the cursor ...
1
vote
2answers
167 views

using input() for custom command

I'm using vim to edit my latex files and I'm trying to automate some aspects of it. I want a command that inserts the following: \begin{env} \end{env} Where env is an user input. So I came up whit ...
0
votes
2answers
41 views

How to store state (e.g. variables) between user actions?

The main question is in the title, that is, I have a function, which is invoked by the user and it should 'remember' necessary stuff between invocations, so the next time the user calls it (like, ...
1
vote
1answer
214 views

How to open directory in toggled netrw window?

I've toggled netrw explorer window by adding the following commands found in an answer posted to this question to the vimrc file. let g:NetrwIsOpen=0 function! ToggleNetrw() if g:NetrwIsOpen ...

1
3 4
5
6 7
25