5

Just compare the character you got with a tab, which can be represented with the \t escape sequence. That is, getline(".")[col(".")-1] == "\t" The expression will return 1 if the character is tab, 0 if not.


3

One undocumented trick is to use %{MyFunc()} expression in the statusline syntax. MyFunc() is always called whenever something happens so you can check the window size in it. For example, You can see the window height/width in the statusline. function! EchoWinSize() return winheight(0) . '/' . winwidth(0) endfunction let &statusline = "%{EchoWinSize(...


3

Is there a better way to do what I want? That is, to operate on a WORD (or any text object, really) without clobbering a register? If you want the current WORD in specific, then this works: let input = expand('<cWORD>') It's not a general solution, but it seems to fit what you're after in this particular instance.


3

First, if your script runs from a mapping than you probably should support v:register - let the user decide what to use. Next, if your operation is a sort of "visual replacement" (get selection, modify and put it back) it makes sense to model it after :h v_p (maybe even end it with gvp or such). In this case either @- (for "less-than-a-line" selection) or @...


3

Ripping from ftplugin/man.vim to deal with this kind of backspace-bold hack: :%substitute/.\b//g Using Christian's col solution: :%!col -b You can also just do command that creates output | vim +MANPAGER -


3

I made a Vim plugin which is to jump to Vim script's last error or load errors to current loclist. https://github.com/rbtnn/vim-vimscript_lasterror If you would like, you can try it.


2

There are two separate issues in your code: In most situations, if you want to use the contents of a variable in a Vim command, you need to use :execute to achieve this. lcd w:baseCwd will attempt to change to a directory named w:baseCwd. To change to the directory currently stored in that variable, use :execute 'lcd' w:baseCwd. You cannot assign to a ...


2

There is an auto-command event InsertCharPre that detects entry of any character while in Insert mode yet still inserts it into the buffer. Here's a dead simple example (put this in your vimrc, for instance): augroup InterceptKeyPress autocmd! autocmd InsertCharPre * :echo localtime() augroup END You can run any vimscript you want in response to ...


2

The issue is that you're calling feedkeys() and that function adds the keypresses to the end of the typeahead buffer, which means they don't execute right away. From :help feedkeys(): By default the string is added to the end of the typeahead buffer, thus if a mapping is still being executed the characters come after them. There are flags you can pass ...


2

You can try this: silent let result=systemlist("some_program", getline(1, "$")) " do something with result " cleanup buffer normal! gg_dG call setline(1, result) Or this: silent let result=system("some_program", getline(1, "$")) " do something with result " cleanup buffer :%delete _ call setline(1, split(result, '\n')) If you want specific buffer to be ...


2

You can create temporary file name with :h tempname(): let tempname = tempname() call writefile([ "hello world" ], tempname) " do something with tempname file " ... call delete(tempname)


2

There is no such event. There is TextChanged event that is generally called when text was changed in normal mode (including x I guess). I am not sure this what you need though... Why not remap x key to delete a character and call your function? func! MyFunc() echo printf("You have just deleted '%s'", getreg(v:register)) endfunc noremap x x:call MyFunc(...


2

So the whole point is that if &filetype is of the form x.y then Vim automatically loads indents and syntaxes from both x.vim and y.vim. Then the code in syntax/y.vim must take this into account and keep the previous value of b:current_syntax. So instead of usual: if exists('b:current_syntax') | finish | endif, or unlet b:current_syntax it should start ...


2

There is contains=CONTAINED you can define for regions. See :h syn-contains. contains=CONTAINED If the first item in the contains list is "CONTAINED", then all groups will be accepted that have the "contained" argument. So it means that no matter if you specified contained containedin=GROUP to be contained in GROUP it would also be ...


1

You can try following: syntax region Comment start=/^\z(\s*\)##/ end=/^\z1\ze\S/ See :h /\z(\). Basically it saves whitespace indentation in \z1 and use it in end of region just before first non-whitespace. Also see :h /\ze. For Edited part of question Make it also end on empty line syntax region Comment start=/^\z(\s*\)##/ end=/\(^\z1\ze\S\)\|\(^\s*$\)...


1

There are different approaches to this problem. Assuming your Vim has('job') you can do: let temp = bufadd('noname') call setbufvar(temp, '&buftype', 'nofile') call bufload(temp) let job = job_start('luacheck', #{in_io: 'buffer', in_buf: bufnr(), \ out_io: 'buffer', out_buf: temp, \ exit_cb: {id, status -> execute(printf('cb %d | bw %d | cw 5'...


1

Perhaps I should have searched the internet more before I asked this question. I was able to accomplish what I needed using the system function. So here I needed to do: let g:coc_node_path = substitute(system('which node'), '\n', '', '') The substitute is necessary because we need to get rid of the new line at the end of the output, otherwise the path is ...


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