New answers tagged

1

There is :h 'formatprg' you can use to format a portion of the text with gq. For you case this might work (added to .vim/after/ftplugin/sql.vim): setlocal formatprg=sqlformat\ --reindent\ --indent_width\ 4\ --keywords\ upper\ --identifiers\ lower\ - NOTE: I didn't test it as I use sql-formatter implemented in node: " npm i -g sql-formatter if ...


0

I put my self-answer here since I've dived into my problem and solved it before I saw the answer post here. This is a workaround, in Lua: local raw_path = 'foo/bar/baz/bee' vim.cmd('cd '..raw_path..'/../') local result = vim.fn.getcwd() -- normalized. vim.cmd('cd -') -- restore.


2

This is fnamemodify(var, ':h').


0

This NOTE makes me spend some time searching for a wonderful solution NOTE: Use ! wisely. If used without care it can cause an existing function to be replaced unexpectedly, which is hard to debug. I do not use func! in my init.vim. But after saving my init.vim twice, I get E122. In many places, we can find advice like this: from ...


1

Perhaps the WinClosed event can help (merged in Vim 8.2.3591 and Neovim 0.5).


0

Check out some related questions: https://vi.stackexchange.com/search?q=%5Bfiletype-c%2B%2B%5D+g%2B%2B, https://vi.stackexchange.com/search?q=%5Bfiletype-c%2B%2B%5D+compile A short answer: prefer to use :make to build and probably :terminal or :! to run the program, all of which you can bind maps to. But if you insist on this particular setup: :help cmdline-...


1

:h expand() your string with environment variable, concatenate it the rest and use :h :execute to source it: :execute "source " . expand(prefix) . "/whatever.vim"


1

I took Luc Hermitte's helpful answer and improved it somewhat. It was returning unlisted (previously deleted) buffers, which isn't what I wanted. It now filters on buflisted(v:val), rather than on !empty(v:val). I've added two commands: Lssave: saves the unsorted buffer list as-is LSsave: saves a sorted version of the buffer list mkdir the output file's ...


0

See the function term_start(); it creates a terminal window, which you can then :hide. I suppose :terminal followed by :hide also works. :vsplit should not be necessary, as :terminal and term_start() both create their own windows. If you want to avoid messing with the layout of the current tab, :tab terminal followed by :tabclose might be cleaner.


2

Just use the tabpagenr() function, which returns the number of the current tab page when called without any arguments, or the last tab page number when called with a '$'. The following expression should tell you whether you're on the last tab: tabpagenr() == tabpagenr('$')


2

Buffer is called "hidden" if it's Loaded Not shown in any window :echo bufloaded(N) && win_findbuf(N)->empty() or :echo bufexists(N) && getbufinfo(N)[0].hidden


2

an API to return all (loaded) buffers :h getbufinfo() loop through each of them :h filter() if the buffer is a No Name-buffer :echo empty(bufname(N)) :echo empty(getbufinfo(N)[0].name) an API to edit that buffer on the current window (split) by that buffer number :h :buffer


0

I can work around this problem like this. vsplit | term | close


3

In no particular order. Readability Any sequence of normals, except a very short one, is nearly impossible to read and understand. Vimgolf can't lie. Clobbering registers etc. Quite often there is more things to change than one can even remember of. For example, your code sets at least four(!) registers and six(!) marks. Plus :h changelist and :h jumplist. ...


0

I just have this in my .vimrc to source anything that I have yanked to the unnamed buffer: " source any yanked block of text nnoremap <silent> <LEADER>sy :@"<CR>


1

Not an answer, but I think you'll appreciate it. let saved_pos = getcurpos() call search('mysearch') normal! 0c$better call setpos('.', saved_pos) I used "better" functions ("better" - maybe not. Up to you). And mixed/matched normals with scripts. What do you think? Read this: Master Wq and the Markdown acolyte from https://blog.sanctum....


2

To run normal mode commands as ex command use :normal! as in normal! gv Note, exclamation mark is for running non-mapped "built-in" functionality: :nnoremap l :echo "hello"<CR> " this would echo hello :normal l " this would move cursor right :normal! l


1

I see now the :normal command will exit the visual selection mode temporarily, so if you wanted to get the visual selection, you have to reselect it in the command by using gv, as in :execute "normal gv\"ay". This would require the command be used when there's a visual selection active; if you used it with the default range, it would select ...


0

say you have a line in a file like: echo "hello world" you would make a visual selection of that text then type: :'<,'>w! /tmp/x.vim | so /tmp/x.vim and it will run it. you can also give yourself a mapping, for example in gx, so you would select some text and then type gx and it will run it. like this: vmap gx :w! /tmp/x.vim<CR>:so /...


1

Here's a way that doesn't use :windo :echo tabpagebuflist()->filter({_, v -> getbufvar(v, '&buftype') isnot# 'nofile' })->len() (My original solution used map() to get the buftype and then filter() on that list; the advantage of combining them is that, if you were interested in other things than len(), you would still have the buffer numbers ...


1

I just found that NeoVim provides some functions to do so easily: local cur_win = vim.api.nvim_get_current_win() -- do your windo, for example: vim.cmd("windo if &buftype != 'nofile' | let g:non_float_total += 1 | endif") vim.api.nvim_set_current_win(cur_win) And since my problem was originally asked in context of Vim before edit(yeah, it's ...


1

There may be a more efficient way to do it but this should work: " initialize count variable let g:cnt = 0 " run test for each window incrementing count when appropriate windo if &buftype !=# 'nofile' | let g:cnt += 1 | endif " then, for example, we could display the count echo g:cnt


1

Start with: echo tabpagewinnr(tabpagenr(), '$') tabpagenr() gives you the number of the current tab page. Use '$' as the second param to tabpagewinnr() and that function will return the number of windows contained in the specified tab page. So you can test for single window (no splits) with something like: if tabpagewinnr(tabpagenr(), '$') == 1 " ...


0

We use a command just by writing it When we use a string as a command, put execute before the string These 2 lines get the same output :echo 'hi_1' :execute "echo 'hi_1'" NOTE : indicates a ex command, instead of an option, motion or other things in vim (try :help :bar vs :help bar ) (Thank @filbranden for reminding me of my mistakes. And ...


0

While the guide is not explicit about it, those configuration snippets are meant to be added to the main NeoVim configuration file, at ~/.config/nvim/init.vim, and not in a per-filetype file for Rust. In particular, vim-plug configuration (the Plug statements) only work in init.vim (or the .vimrc file for Vim), since plug-ins are loaded in startup right ...


Top 50 recent answers are included