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
2
votes
1answer
67 views

Quickly correcting spelling mistakes but omitting some cases

I am using vim as a note-taking app. Following an earlier answer here , I have the following mappings which allow me to quickly correct earlier spelling mistakes: " spelling imap <C-l> <...
1
vote
1answer
58 views

Vim: How to manipulate appearance of signs in .vimrc?

I have seen a guy on YouTube who has some sort of Markdown rendering in Vim. The * sign from a list is displayed as a •. When the cursor travels over it, the actual sign shows up. I have checked his ....
2
votes
1answer
629 views

VimWiki - create a "smart" index page for subdir/section of wiki?

I'm using VimWiki for a writing project and for certain sections (like "chapters", contained in sub-directories) I want to create indexes that work similarly to the way VimWiki's diary index ...
0
votes
1answer
34 views

Vimscript: Placing the cursor at a defined position in the buffer

I use vim as a note-taking app by editing a text file and appending notes to it. I have written a simple function to insert a block of text as follows: function! AddBlock2(...) range let l:hdr = ...
0
votes
1answer
62 views

Measuring how much I write in vim by comparing word count on each save

Suppose I want to write N words related to my studies in Vim everyday as my daily goal. Every time I am done writing something I can do g+Ctrl-g and then I can send that number variable to a file. I ...
2
votes
1answer
237 views

Is it safe to define more than 120 signs?

I am working on a plugin that could potentially define more than 120 different signs. The vim / neovim documentation specifies that you can define about 120 signs (not sure why this number and why so ...
3
votes
1answer
277 views

how to loop through list of files?

I can do :echo globpath('~/path/to/dir', 'string*') to get a list like: /home/alec/path/to/dir/string_xyz123.mkd /home/alec/path/to/dir/string_xyz456.mkd /home/alec/path/to/dir/string_xyz789.mkd but ...
2
votes
2answers
65 views

Get first and last visible line from other buffer than current

I know that I can get the first and last visible lines in the current buffer by using line('w0') and line('w$'), but is there a way to do it for other buffers that are visible but not active as well? ...
3
votes
1answer
83 views

Vim shows incorrect theme in error

Basically, all I'm trying to do is enable the syntax option. syntax enable colorscheme cobalt2 For some reason, I get no errors if I comment out the first line, but in case I don't comment it, I get: ...
1
vote
1answer
400 views

How to exit vimscript? [duplicate]

How to exit .vim script file? I want something like this in my init.vim if exists('g:vscode') "Do not execute rest of init.vim, do not apply any configs exit endif "...some configs... ...
4
votes
2answers
222 views

Is it possible to override the filetype of a text file based on the first line?

I have some specifically formatted text files that I'd like to detect when I start vim. When I load these files now, the filetype is automatically set to text. I only want to override that if the ...
1
vote
2answers
74 views

How can I turn these mappings into a vim function?

I use the following mappings to toggle relative numbers in visual mode: nnoremap <silent> v v:<c-u>set nonu rnu<cr>gv nnoremap <silent> V V0:<c-u>set nonu rnu<cr>gv ...
3
votes
1answer
136 views

Vim does not call functions correctly when wrapped in another function

Please consider these 3 small functions: " place sign >> at line 10 function PlaceSign() call sign_define('a', {'text': '>>', 'texthl': 'LineNr'}) call sign_place(10, 'g1', 'a', ...
1
vote
1answer
89 views

Vim expands percent sign '%' in URL

In my script, I am trying to open an URL in my default browser using silent exec '!rundll32 url.dll,FileProtocolHandler '.a:url where a:url is an URL-encoded string containing percent % signs. Vim ...
2
votes
2answers
68 views

Buffer scope variable not exists when run autocmd BufUnload

Describe the issue I use a vim plugin that when use Vim to open a ipynb (python notebook) file, will call system function to use jupytext create corresponding python file to enable use like, YCM to ...
-1
votes
2answers
71 views

How can i make this autocmd BufEnter command work?

i am setting the default vim-statusline, and i made this line on my colorscheme: hi MyStatusLineDevIcon ctermfg=7 ctermbg=0 cterm=NONE So i can color the devicons on my statusline.vim config I call ...
0
votes
1answer
53 views

When hitting Enter keyboard on a file path, open a new tab with the file content

I'm new to vim language and I'd like to see a new tab opening when I hit the enter keyboard on a line containing only a path of a file. When I create a map like this nnoremap <buffer> <cr> ...
2
votes
1answer
101 views

why doesn't regex work in vimscript (while it does in normal search)?

I have simple regex to search for lines that only contain alphabetic characters: ^\(\a\)\{1,}$ which works in normal search /^\(\a\)\{1,}$ but not when invoked from my script: "in .vimrc file: ...
0
votes
1answer
26 views

append strings with order

The original text: line1 lline2 line I want to add strings into the below format: line1 lline2 x y z line Move cursor at the 2th line,and ctrl+;,enter into ex mode: for s in ['x','y','z'] call ...
3
votes
2answers
184 views

Reversing all characters on each line of a range

In order to invert all characters on each line of a range I could think of the following :s/.*/\=list2str(reverse(str2list(getline('.'))))" where I can put a [range] if I want. Is there any ...
0
votes
1answer
99 views

Get visually selected text - weird behavior when last selected char is multi-byte

I have made a simple function to echo the visually selected text. The function is simplistic as I am only interested in max one-line selection. The problem is, if the last character of the visual ...
2
votes
0answers
60 views

Conditional mapping for two plugins (UltiSnips and Vimwiki)

Vimwiki table default mappings include <tab> for moving to the next table column in insert mode. Also UltiSnips default mappings include <tab> for expanding snippets in insert mode. Here ...
2
votes
2answers
86 views

Get list of marks inside Vimscript

some time ago, I wrote a small plugin in vimscript that was using builtin function getmarklist. Recently I reinstalled Vim and was surprissed that this plugin no longer worked because Vim couldn't ...
0
votes
1answer
336 views

Vim function : how to expand vim variable in shell command?

I'm trying to write a vim function to update ctags and cscope databases. I'm trying to save the vim variable projectRoot in environment variable then expand this enviroment variable in the find ...
1
vote
1answer
131 views

How to create key bindings that apply on in a quickfix buffer?

The autoload command can be used to execute code depending on a range of events and filetypes. When I list the active buffers, the buffer hosting the quickfix window has what seems to be a unique ...
0
votes
2answers
43 views

How can I make a mapping to toggle cursorbind?

I know that adding a ! to the end of an option works for some commands, but it doesn't work for cursorbind. How can I toggle between cursorbind and nocursorbind with a keybinding?
1
vote
1answer
62 views

Execute command with special characters from user input

I would like to correctly intepret the <cr> in a command that is created based on user input. For example, this function runs correctly and it will split the line a the location where the cursor ...
3
votes
1answer
40 views

Need a functionality behaving like Replace on text but for Pasting Blocks

One of my vim usages is to do sketches of topologies in networking I've found the script Draw it really really useful for that So I can draw things like this by pasting these boxes +------+ |ROUTER| ...
0
votes
1answer
19 views

Any way to create a VimL equivalent of Python's @property decorator?

As the title says, I'd like to be able to use something like Python's @property decorator (its semantics ofc, not the syntax) when writing a 'class' in VimL. Currently I have something along the ...
0
votes
1answer
111 views

Literal character escapes in VimL string

I'm trying to use vimlsp server to help me write VimL, but it is prevented for me due to a parse problem with a literal carriage return (^M) char inside this code: function! ChompCtrlM(string) ...
0
votes
1answer
104 views

Solving issue with clang-format-vim.py saving new buffer

Summary I configured vim to call clang-format.py following the steps in the clang documentation for vim integration. But when I save a new buffer the plugin fails. I'm new to vimscript and trying to ...
1
vote
1answer
39 views

Enhance Latex Syntax without Rewriting everything

I want to extend the latex syntax for the given file: \documentclass[a4paper,11pt]{book} \begin{document} \begin{figure}[t] \begin{tikzpicture} \node[alter] at (0,0) (v1) {typ0}; ...
0
votes
0answers
20 views

Automaticall close LaTeX begin environment with end [duplicate]

I want to automate some routine operations when working with LaTeX documents writing, e.g. I often write these lines: \begin{<environment-name>} some text and commands here \end{<environment-...
1
vote
0answers
16 views

system function puts extra characters onto stdout [duplicate]

I just updated to the latest vim (git fetch && git merge origin/master followed by building and installing to /usr/local/...). Everything is great except with a little extra stuff I added to ...
0
votes
1answer
49 views

Get the content of the first column

I'm writing a vim function to comment the selected lines in visual mode. Then I have written the following function to toggle the "#" character. I want insert the # when thereisn't and ...
0
votes
1answer
767 views

Inside a mapping check if a variable is empty in vim

So i'm new to vim, and specially new to vimscript, and messing around i made the following code to get the name for a file and then create said file in a new buffer. I want a way to check if FileName_ ...
1
vote
0answers
20 views

How can you isolate the date portion of each request of a IP adress? [closed]

How can you isolate the date portion of each request of a IP address if it's at the first line of each request from a log file using awk, creating a list of distinct dates, and then using grep to ...
5
votes
3answers
4k views

Select multiple words, one at a time, then replace them all

Goal: Select multiple words, one at a time, then replace them all. I'm new to Vim; I come from Visual Studio. I would like to achieve one important feature that helped me a lot in my productivity: ...
1
vote
2answers
73 views

How to trigger rhs of a map?

Let's say I have a function like this: function! Foo() echom 'foo' endfunction And a map like this: nmap gf :<C-U>call Foo()<CR>0v$ When I type gf I see foo echoed and the current line ...
3
votes
1answer
68 views

Folding example from Learn Vimscript the Hard Way not working?

I'm reading Learn Vimscript the Hard Way - Chapter 18, which is also about folds. I'm surprised to see that copying the sample code " Vimscript file settings ---------------------- {{{ augroup ...
2
votes
0answers
118 views

vimscript - copy a file from one path to another

How do I rewrite this line of code call system("cp /tmp/foo.txt /tmp/bar.txt") into a vim command which is more portable and OS-independent? I've been looking around but checking for "...
0
votes
1answer
20 views

function with one argument that search for word and then replace something on that line

I want to create a custom function that: Take 1 argument Search for a word On that line do a movement like f@ change till " (ct") with the argument I provided Example: Library "...
0
votes
0answers
107 views

How to set statusline for specific buffer

I want to use netrwm instead of nerdtree. I have my own statusline but I don't want it to be displayed in netrw. Nerdtree had it's own option for it (let NERDTreeStatusline="") which made it ...
1
vote
2answers
21 views

why doesn't col("^") work as expected

I know that there is a function col({expr}), which returns the column position given with {expr}. For example, col("$") gives me the column position of the end of the cursor line. So I ...
0
votes
1answer
111 views

regex and matchstr to get final directory and file in path

I am wondering about a regex that would enable me to get the final "directory/file" from a path. I'll explain the reason why. After using vim for 20+ years, I've finally had cause to edit &...
0
votes
0answers
118 views

vim: is possible to use mouse to move lines around

Question: Is possible to use mouse to move lines around? Requirements & Clarification I do know keyboard solutions. normal mode ddp d2j'}p dapggp alike. cmdline commands, :co. '<,'>m'a etc....
0
votes
0answers
20 views

Want template files pre-populated based on keystrokes

So based on the keystrokes I enter I want to copy the full file templates into the new file and begin editing them. This is my vimscript and I have tried a couple of different ways, from using :r :e ...
0
votes
0answers
135 views

Load scripts one after another

I have a syntax highlight, that is presumably overwritten by another script. When I execute :scriptnames, it shows ~90 scripts. The syntax script is around number 40. Is it possible to manually load ...
4
votes
1answer
91 views

Statusline wrong column count for multi-byte characters

I have set this statusline. :set statusline=%c According to :help statusline, %c means column number. If the buffer contents is abcdef éÀ│§õ→ and the cursor is on the f character, the statusline ...
2
votes
1answer
98 views

Print the output of vim-scripts function in current line

Say I want to print the output of strftime("%D") in the current line, or to print the return of any user-defined function for that matter. What's the standard (one step?) way to do it? I ...

1 2 3
4
5
25