4

Try: if type(l:foo_list) == v:t_list Or in older versions of Vim: if type(l:foo_list) == type([]) See :help type() for more details.


4

As @Matt points out, you can parse JSON natively in Vimscript, that's the best solution to your problem. But still, two main recommendations here, for interacting with external commands from Vimscript: Use systemlist() instead of system(). systemlist() returns a list of lines, which ends up being more natural to handle in Vimscript. Both systemlist() and ...


4

VimScript has a JSON parser of its own. There's no need to invoke an external utility. A sample code: " read in file let s:js_data = readfile('windows.json') " decode into Vim variable let s:list = js_decode(join(s:js_data)) " filter out the skims let s:skims = filter(s:list, 'v:val.app=="Skim"') " do whatever... echo s:skims echo len(s:skims) for s:item ...


3

From :h input() input({prompt} [, {text} [, {completion}]]) *input()* If the optional {text} argument is present and not empty, this is used for the default reply, as if the user typed this. Example: > :let color = input("Color? ", "white")


3

In vim script, everything has to be an ex (:) command. Thus, the way vim distinguishes a command named foo and changes to the variable foo is the let command: let foo += 1


3

The easiest way is to use \ze to mark end of the match: syn match mysqlTable2 "TBL_[A-Z_]\+" syn match mysqlQualifier "TBL_[A-Z_]\+.\s\+[A-Z]\+" contains=mysqlTable syn match mysqlTable "TBL_[A-Z_]\+" contained syn match mysqlQualifier "[A-Z]\+\ze\."


3

The reason for this is that both *.adoc and *.fr.adoc match for foo.fr.adoc, so both autocmds are run. The documentation for autocmd patterns is at :help file-pattern; looking at it, doing a robust "match *.adoc but not fr.adoc" is a bit tricky (though not impossible). Personally, I would opt for just an if: autocmd BufNewFile *.adoc \ if ...


3

As it was noted, the problem is that neither :h :@, nor :h execute() know anything about :h line-continuation. Only :h :source supports it. Here is the piece of code taken from my config to deal with this problem. " preprocess VimScript to allow " :h line-continuation and :h line-continuation-comment function s:preprocess(script) if stridx(&cpo, 'C'...


2

As stated in the comment to https://vi.stackexchange.com/a/25009/21417 this has nothing to do with if-statements (or 'compatible' being set). But there obviously is a difference between running that code by sourcing a vimscript file or by running it from a register. In my case I was just testing a function and didn't bother to :source the whole script that ...


2

The marks '< and '> are only set when you leave Visual mode. When you're using Vim interactively, this happens naturally, as you use the : to start typing a "substitute" command Vim will leave Visual mode and enter command-line mode. But that's not the case when you're using normal! from a function. You can add an <Esc> to leave Visual mode ...


2

From this video: UltiSnips evaluates each text object that might have a dependency on some types of text multiple times, to make sure that all dependencies are properly updated. To prevent the date from being updated several times, you could switch to a python interpolation, and use the guard if not snip.c. For example, you could replace this: ** ...


2

Have you considered modifying the function to move the cursor after the list insertion? This worked in my Vim (v8.1.7777) function! CompConst() let constName = toupper(input("Compiler Constant: ")) let defBlock = ['#define ' . constName . '_SUFFIX_1', \'#define ' . constName . '_SUFFIX_2', \'#define ' . constName . '...


2

Simply use :let to set each entry of the dictionary at a time. let text = {} let text['code1'] =<< trim END if ok echo 'done' endif END let text['code2'] =<< trim END if something echo something else endif END echo text This produces the following output: {'code1': ['if ok', ' echo ''done''', 'endif'], 'code2': ['if ...


2

There's no way to change this behavior for all operators (short of mapping them all.) But you can make your <F4> keep the cursor position (and window view) by saving and restoring it before and after it's used. Note that since <F4> ends in an operator-pending g@ command, saving and restoring need to happen in different contexts, you should save ...


1

The error you are getting is happening because your Vim doesn't include support for Python, which is required by UltiSnips, as that plug-in is implemented in Python for the most part. My recommendation is that you should get a Vim binary from your distribution. You mentioned using Linux Mint, so make sure you are not using a vim-tiny package, since that ...


1

You can use :startinsert and :stopinsert here. From :help :startinsert: Start Insert mode just after executing this command. Works like typing i in Normal mode. When the ! is included it works like A, append to the line. Otherwise insertion starts at the cursor position. Note that when using this command in a function or script, the insertion only ...


1

I don't think you can map fn key in vim since it's mostly hooked in global os level. I've managed to remap my fn key using software like Karabiner


1

This substitution works: :%s/\v^ {4}.*\ze(\n( {4}.*\ze)?)*/\="```".lang."\r".substitute(submatch(0), '\v(^|\n\zs) {4}', '', 'g')."\r```"/ Note that even though the regex is not anchored at the first line that starts with four spaces. But that is fine if we're using it with a :%s command, since that command will not rescan text it has already replaced, so ...


1

I think I can make a guess (but I have never seen this before either, and I haven't used SpaceVim yet) based on this issue: gq for reformatting doesn't work #787. nmap g [G] essentially blocks all the usual normal-mode commands that start g. gq, for example, is now [G]q. nnoremap gf gf, by virtue of being a noremap version, blocks further mapping expansion, ...


1

I slightly refactored your function and made it more robust. After quitting the terminal, with for example exit command in Windows, you will get an error when trying to invoke your ToggleTerminal() function. let s:term_buf_nr = -1 function! s:ToggleTerminal() abort if s:term_buf_nr == -1 execute "botright terminal" let s:term_buf_nr = ...


1

According to :help E10, :set nocp while editing the if statement will fix the issue. That is, after setting it, command line continuation will be enabled.


1

There is something called "bracketed paste mode", see :h xterm-bracketed-paste. Check if iTerm supports it. If it does, make sure you don't unset t_BE and t_BD in your configuration. (I don't have a Mac, so I can't test.) If that doesn't work: I have configures F9 to toggle paste mode: set pastetoggle=<F9> " toggle paste option


1

I have been using the paste mappings from vim-unimpaired by Tim Pope, which will drop you on insert mode under set paste and restore nopaste as soon as you leave insert mode. The mappings are: [op: Paste above the current line (similar to O but with set paste) ]op: Paste below the current line (similar to o but with set paste) yop: Paste replacing the ...


Only top voted, non community-wiki answers of a minimum length are eligible