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
1answer
30 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 ...
3
votes
1answer
28 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
19 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
17 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
25 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
54 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
30 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
98 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
14 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
20 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
22 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
21 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
1answer
33 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
36 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
291 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, ...
-1
votes
0answers
24 views

Why isnt syntastic working?

Previously syntastic checked for unused imports, variable and long line length but now there is no error. Also this is my .vimrc set ignorecase set number set incsearch syntax on call plug#begin('~/....
0
votes
0answers
19 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
43 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 ...
0
votes
1answer
31 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
46 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
27 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
12 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
21 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
39 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
12 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
36 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
22 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
22 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
27 views

How to populate the preview window?

Let me give a bit of context to the question: 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-...
0
votes
1answer
22 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
13 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
13 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
29 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
27 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
69 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 ...
0
votes
1answer
33 views

How to bind these keys to prevent recursive binding in Vim?

I have been trying to do :noremap j k and :noremap k j which works but instead of going up it goes slanted up and down. I want j to move up and k to move down which is opposite in vim. I also tried :...
0
votes
1answer
17 views

Can the command :filter be used recursively?

I mean the :filter command, not the external one. I want to filter the filtered results again, if not clear. The trivial try didn't work - :filter /abc/ filter /cbd/ %list
0
votes
0answers
14 views

redirect doesnt save error

Errors, ie python errors, appear in :messages. And yet, they are not present in the file generate by redir >> fil. I wish they would be added too. Any chance? For example, these lines aren't ...
2
votes
1answer
62 views

Vimscript: How to check if a buffer is modified

Given a buffer number i, I want to check if the buffer has been modified after the last save. How do I do that in vimscript? I tried to use getbufvar() like the following: if getbufvar(i, "&...
1
vote
3answers
162 views

How to find plugin vimscript function definition?

Assume I am using some plugin function e.g. For vim-plug, I put this code in my .vimrc at the end call plug#end() How to find out where is this function plug#end() is located? from vimrc directly ...
0
votes
0answers
34 views

vimscript: Efficient way to extract portion from line of text

I have a plugin that does syntax highlighting and folding for a kind of data file. The syntax and folding are both dependent on textual values in specific places (columns) of current line of text. ...
0
votes
1answer
46 views

How to set cursor position in a popup buffer?

I'm tinkering with popups and trying to open one, select a line (namely set the cursor line by pressing mapped keys (Ctrln / Ctrlp)), then close it. The problem is that I cannot select a line, despite ...
1
vote
1answer
38 views

Usage of t. and | in vim command

I've assembled the following command to take a markdown file and add a ==== under each line that starts with a #: :g/^#/t. | s/./=/g How exactly does this work? As far as I understand: :g/ start a ...
1
vote
3answers
41 views

Customizing Tabbing and backspace properties in vim

There are two features related to indenting that I find very helpful in Textmate, and I'm looking to find the closest thing in vim. First, I can tab to the correct level of indentation, especially in ...
0
votes
1answer
44 views

How to send contents of visual selection to an external script

I would like to write a python script that parses some vim data and returns a result. For example, we'll turn numbers, separated by lines, into a sorted list of unique numbers. If we had this as the ...
1
vote
0answers
14 views

Design guideline for doing both autocompletion and highlighting?

For Vim, are there any design guidelines for simultaneously doing autocompletion and syntax highlighting? For the NFTABLES command line (and file) syntaxes, I see lots of recurring but partial syntax ...
1
vote
1answer
25 views

vim input function with default value

I'm working a function to rename the visual selected text function! Rename() name = getline("'<")[getpos("'<")[2]-1:getpos("'>")[2]-1] let newname = input('rename the selection with: ...

1
2 3 4 5
20