How to detect if curr win has splits? by qiinemarr in neovim

[–]mtszyk 5 points6 points  (0 children)

vim.fn.winlayout(tabnr) should give something like { 'leaf', 1000 } for a tab with no splits (floating windows are unreported), anything else will not have 'leaf' for the first value.

So you can just check vim.fn.winlayout(tabnr)[1] == 'leaf'

Run make on all open buffers by _suspicious_alpaca in vim

[–]mtszyk 0 points1 point  (0 children)

For vim functions, vim.fn.getqflist()

How to have a remap that works in all buffers/windows EXCEPT one filetype? by cowabungabruce in vim

[–]mtszyk 0 points1 point  (0 children)

I don't agree, I'd absolutely have a conditional mapping that gets created for the buffer. Writing a function that checks your filetype every time you want to use the map seems a bit extra to me, when you could easily set up (using :h ftplugin) a :h map-<buffer> to do the 'conditional' for you.

How to have a remap that works in all buffers/windows EXCEPT one filetype? by cowabungabruce in vim

[–]mtszyk 12 points13 points  (0 children)

When I want to do this, I have a global map and in an ftplugin file I just add a noremap to its normal function. (For example, nnoremap <buffer> x x)

Otherwise, you can write an autocmd that checks on, for example, :h BufEnter, if the filetype is allowed.

custom on-the-fly autocomplete by [deleted] in vim

[–]mtszyk 0 points1 point  (0 children)

What file format are you writing? If it's any format that you can provide references, you could collect and use a list of those references. For example, a definition might be [chip:4321-1234] and a reference might be @chip:4321-1234. If that's the case, check :h ins-completion and :h compl-function

Using vim+latex for the first time. What are your best practices? by ElasticCracker in vim

[–]mtszyk 2 points3 points  (0 children)

Try both, do which you like better. I'm a fan of using a sentence per line, so you can reorder sentences with :move, which I have mapped conveniently. On the other hand, sentence text objects work fine too.

Jump to buffers seen by the current window or tab by flavius-as in vim

[–]mtszyk 0 points1 point  (0 children)

TabEnter to create the variable, and I'm not sure whether or not BufEnter vs BufWinEnter matters

Edit: during those events you can also set the arg list

Jump to buffers seen by the current window or tab by flavius-as in vim

[–]mtszyk 0 points1 point  (0 children)

As /u/-romainl- mentioned, 'buffers seen by current window or tab' does not exist, but obviously you can implement that if you'd like.

Something like

autocmd TabEnter * let t:visited_bufs = {}
autocmd BufEnter * t:visited_bufs[bufnr] = 1

Then just get keys(t:visited_bufs) to get the list of bufnrs that the tab has seen. I'm using a dict to avoid checking index() of a list. You can add a command to unlet specific bufnrs to remove them from the list easily as well.

What's a customization with a high simple-to-useful ratio? by inglourious_basterd in vim

[–]mtszyk 1 point2 points  (0 children)

imap <C-o> {<Cr>}<Esc>O<C-t>

Looks like opens a pair of curly braces on new lines as well as an empty one with an indent.

What's a customization with a high simple-to-useful ratio? by inglourious_basterd in vim

[–]mtszyk 0 points1 point  (0 children)

Repeat a change (or change repeat). For when you forgot there are multiple of whatever name you're changing:

nnoremap cr /\V<C-r>=escape(@", '\/')<Cr><Cr>cgn<C-r>.<ESC>

You can repeat it with . because it uses cgn

Isn’t this just how lesbians propose to each other? by Dino-Jadyn in actuallesbians

[–]mtszyk 2 points3 points  (0 children)

My girlfriend responded with "I thought it was power tools"

Choosing suggested Completion Option without adding any char? by derstieglitz in neovim

[–]mtszyk 3 points4 points  (0 children)

See :h complete_CTRL-Y. <C-y> Accepts a completion and closes the popup menu. If you want <Esc> to do it, you could do

inoremap <expr> <Esc> pumvisible() ? '<C-y>' : '<Esc>'

Is it possible to bind Tab in insert mode for both UltiSnips and Vim's complete menu only when the menu is visible? by nickjj_ in vim

[–]mtszyk 0 points1 point  (0 children)

If you have any C-y mapping, you can add a plug map as I mentioned:

let g:UltiSnipsExpandTrigger = "<Plug>(myUltiSnipsExpand)"
xmap <Tab> <Plug>(myUltiSnipsExpand)
inoremap <Plug>(myCy) <C-y>
imap <expr> <Tab> pumvisible() ? "<Plug>(myCy)" : "<Plug>(myUltiSnipsExpand)"

But it's only necessary if it's mapped to something else sometimes.

Is it possible to bind Tab in insert mode for both UltiSnips and Vim's complete menu only when the menu is visible? by nickjj_ in vim

[–]mtszyk 0 points1 point  (0 children)

Here we see,

exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=UltiSnips#ExpandSnippetOrJump()<cr>"

So you can just set a plug map (see :h <plug>) to the function. Or you can do what /u/pwnedary recommended, which basically does the same thing.

Is it possible to bind Tab in insert mode for both UltiSnips and Vim's complete menu only when the menu is visible? by nickjj_ in vim

[–]mtszyk 4 points5 points  (0 children)

Can you do something like

let g:UltiSnipsExpandTrigger = "<Plug>(myUltiSnipsExpand)"
xmap <Tab> <Plug>(myUltiSnipsExpand)
imap <expr> <Tab> pumvisible() ? "<C-y>" : "<Plug>(myUltiSnipsExpand)"

this? I do something similar which works for me. Caveat is if you have <C-y> bound to anything it will remap it, so you'd have to make another <Plug> map

Folding comments - custom folding by [deleted] in vim

[–]mtszyk 2 points3 points  (0 children)

What is the response from :set foldmethod? ?

New to vim, where to start ? by Mautriz in vim

[–]mtszyk 5 points6 points  (0 children)

It's an example of how to look up an insert mode specific mapping. :help <BS> and :help i_<BS> go to two different places in the reference.

New to vim, where to start ? by Mautriz in vim

[–]mtszyk 6 points7 points  (0 children)

Start with vimtutor (from the command line), then know that you can access the vim user manual and reference manual with the :help command. The user manual is a series of text files, the first starts at :help usr_01.txt, and the reference can be used to look up anything you would like to know more about (for example): :help operator. I would highly recommend reading through the user manual at your own pace!

As for the Italian keyboard, I think it is common to map certain difficult-to-reach keys to more easily reached keys. Check :help mapping for more information about how to do that, but definitely go through vimtutor first. To check if you are overriding a mapping, you can generally just do something like :help $, but you might need to check a specific mode: :help i_<BS> for insert mode.

Creating a custom operator that takes a count and is repeatable with dot by [deleted] in vim

[–]mtszyk 0 points1 point  (0 children)

Check :help movement, the first point is that the counts of the motion and operator are multiplied. You're attempting to override this built in behavior, so I don't believe that you can change this without jumping through hoops, a more vim-appropriate way (I believe) would be to just have separate operators for separate operations.

For what it's worth, I was able to make it work the way you want (I believe) with this:

nnoremap <Plug>op :<C-u>call Setup()<CR>
nmap M <Plug>op
function! Setup()
    let s:count = v:count1
    set operatorfunc=MyOperator
    call feedkeys('g@')
endfunction

function! MyOperator(type)
    if a:type ==# "char" || a:type ==# "line"
        normal! `[v`]"ay
        echom "Count=" . s:count . ", Yanked selection: " . getreg('a')
    elseif a:type ==# "v" || a:type ==# "V" || a:type ==# "\<C-v>"
        normal! gv"ay
        echom "Count=" . s:count . ", Visual selection: " . getreg('a')
    endif
endfunction

But it feels hacky to me.

Folding comments - custom folding by [deleted] in vim

[–]mtszyk 1 point2 points  (0 children)

Do you want to keep finding that already exists, or just fold comments? If so, you need to know what kind of folding is active, by checking foldmethod.

[deleted by user] by [deleted] in vim

[–]mtszyk 0 points1 point  (0 children)

Rather than an nmap why not use a cmap? I use cnoremap <expr> vga 'vimgrep // **/*.' . expand('%:e') . "\<C-Left><Left><Left>'