viml

How to send escape sequences from within Vim?

无人久伴 提交于 2020-01-22 15:20:20
问题 So recently Apple have included support for displaying the working directory and file in the status bar of Terminal. The escape sequence that must be sent (to set the current file) is this: ESC ] 6 ; Pt BEL where Pt is a file:// url pointing to the file currently being edited. So I figured I could get Vim to send this command as an escape sequence, but I'm having a bit of trouble. I have this so far: au BufNewFile,BufReadPost,BufFilePost,BufWritePost * echo <escape sequence> but I have a

Define a syntax region which depends on the indentation level

99封情书 提交于 2019-12-21 19:58:14
问题 I'm trying to built a lighter syntax file for reStructuredText in Vim. In rst, literal blocks start when "::" is encountered at the end of a line: I'll show you some code:: if foo = bar then do_something() end Literal blocks end when indentation level is lowered. But, literal blocks can be inside other structures that are indented but not literal: .. important:: Some code for you inside this ".. important" directive:: Code comes here Back to normal text, but it is indented with respect to "..

regex in vimscript

无人久伴 提交于 2019-12-18 12:54:33
问题 let test = 'a href="http://www.google.com">www.google.com</a;' In vimscript, how can I get http://www.google.com out of this using a regexp, and store it in another variable? I can't seem to find any documentation about this. 回答1: let url = matchstr(test, '\ca href=\([''"]\)\zs.\{-}\ze\1') if empty(url) throw "no url recognized into ``".test."''" endif For more information, see: :h matchstr() :h /\c :h /\zs :h /\{- 来源: https://stackoverflow.com/questions/3135322/regex-in-vimscript

Vimscript: Number of listed buffers

血红的双手。 提交于 2019-12-09 17:46:13
问题 In my vimscript, I need to get a count of all buffers that are considered listed/listable (i.e. all buffers that do not have the unlisted, 'u', attribute). What's the recommended way of deriving this value? 回答1: You could use bufnr() to get the number of the last buffer, then create a list from 1 to that number and filter it removing the unlisted buffers, by using the buflisted() function as the test expression. " All 'possible' buffers that may exist let b_all = range(1, bufnr('$')) "

Define a syntax region which depends on the indentation level

﹥>﹥吖頭↗ 提交于 2019-12-04 13:00:26
I'm trying to built a lighter syntax file for reStructuredText in Vim. In rst, literal blocks start when "::" is encountered at the end of a line: I'll show you some code:: if foo = bar then do_something() end Literal blocks end when indentation level is lowered. But, literal blocks can be inside other structures that are indented but not literal: .. important:: Some code for you inside this ".. important" directive:: Code comes here Back to normal text, but it is indented with respect to ".. important". So, the problem is: how to make a region that detects the indentation? I did that with the

vimscript call vs. execute

左心房为你撑大大i 提交于 2019-12-03 14:45:12
问题 In vimscript, what is the difference between call and execute ? In what scenarios / use cases should I use one vs the other? (Disclaimer, I am aware of the extensive online help available within vim - I am seeking a concise answer to this specific question). 回答1: From the experience of writing my own plugins and reading the code of others: :call : Used to call functions: function! s:foo(id) execute 'buffer' a:id endfunction let target_id = 1 call foo(target_id) :execute : Used for two things:

vimscript call vs. execute

风流意气都作罢 提交于 2019-12-03 05:31:07
In vimscript, what is the difference between call and execute ? In what scenarios / use cases should I use one vs the other? (Disclaimer, I am aware of the extensive online help available within vim - I am seeking a concise answer to this specific question). From the experience of writing my own plugins and reading the code of others: :call : Used to call functions: function! s:foo(id) execute 'buffer' a:id endfunction let target_id = 1 call foo(target_id) :execute : Used for two things: 1) Construct a string and evaluate it. This is often used to pass arguments to commands: execute 'source'

regex in vimscript

烈酒焚心 提交于 2019-11-30 08:23:59
let test = 'a href="http://www.google.com">www.google.com</a;' In vimscript, how can I get http://www.google.com out of this using a regexp, and store it in another variable? I can't seem to find any documentation about this. let url = matchstr(test, '\ca href=\([''"]\)\zs.\{-}\ze\1') if empty(url) throw "no url recognized into ``".test."''" endif For more information, see: :h matchstr() :h /\c :h /\zs :h /\{- 来源: https://stackoverflow.com/questions/3135322/regex-in-vimscript