New answers tagged

0

You can try to improve my naive attempt: "" if you want real list " let g:mru_buffers = [] "" or just a string with newlines let g:mru_buffers = "" func! RecordMRU(file) if a:file != '' " here you can add another check if buffer/file is in mru and either do nothing or move it in the list/string to top " call insert(g:mru_buffers, a:file) ...


1

Yes, but it doesn't come for free in the form of a ready-to-use option; some assembly required: If you define activity as changes done to the buffer, you can periodically sample b:changedtick, and record (in a buffer-local variable) a timestamp (:help localtime()) when it changes. If activity includes movements, you can do the same with the cursor position (...


4

First, your function can be simplified into let bufnr = term_start(&shell, {"hidden": 1}) Second, it's not a problem to have buftype ==# 'terminal' and set nobuflisted together, as these are two different options. So if bufnr call setbufvar(bufnr, "buflisted", 0) endif is very much okay. However, the real question is: why you create a terminal at ...


2

NERDTree does a great many things that are... unvim-like... in order to give the IDE “project drawer” experience. I consider most of them hacks, and I’m wary of a plugin which has to hack around default behaviors and usages to do something I don’t need (see Oil and Vinegar). All of that said, one of its hacks is actually quite normal—it’s an unlisted ...


2

I guess your motivation of clearing the undo information on writes is to avoid going beyond the saved buffer state when undoing many steps (uuuu...). I personally use a different approach: I've tweaked the u command to stop and beep once when reaching the saved buffer state. I need to u once more to go beyond. My customization integrates with the repeat.vim ...


3

As you're expressly using :edit in order to reset the undo information, you could follow :help clear-undo to do this without :edit. I would define a custom :Write command that combines both: command! -bar Write \ write | \ let old_undolevels = &undolevels | \ set undolevels=-1 | \ exe "normal a \<BS>\<Esc>" | \ let &undolevels = ...


1

I'll let @IngoKarkat write the answer that solves your real problem. However, for the benefit of future readers, you can also achieve what was originally requested by saving the view before executing :edit and then restoring it afterwards: :let v = winsaveview() :edit :call winrestview(v)


0

Old question, but since this comes up at the top in google search, I'll leave this here for future searches. As Bruno suggested, a fuzzy finder that supports buffer lists is the way to go. I personally use and recommend fzf-vim. It provides the command :FZFBuffers, that looks something like this: Buffer numbers are displayed to the left in case you need ...


1

As far as I know, this isn’t possible. However, I found this neat mini-plugin in Paul Irish’s vimrc which does something close to what you’re looking for. As it stands, it highlights occurrences of the current word but I’m sure it could be updated to highlight a given string. Just add it to your vimrc and hit 1-6 to highlight the word under cursor in various ...


1

You can have all buffer names that haven't been unloaded (or wiped out?) with: let files = filter(map(range(1,bufnr('$')), 'bufname(v:val)'), '!empty(v:val)') You can save it with call writefile(files, '/path/to/filename.txt')


1

Try using redir command (:h redir) For example: func! MyRedir() abort redir! > ~/test.txt :ls redir END endfunc augroup save_files | au! au VimLeave * call MyRedir() augroup end


0

My setup, for someone who may want to improve NERDTree behavior. autocmd FileType nerdtree let t:nerdtree_winnr = bufwinnr('%') autocmd BufWinEnter * call PreventBuffersInNERDTree() function! PreventBuffersInNERDTree() if bufname('#') =~ 'NERD_tree' && bufname('%') !~ 'NERD_tree' \ && exists('t:nerdtree_winnr') && bufwinnr('%')...


1

:help viminfo-% gives you some hints on how to achieve this: Quickfix ('buftype'), unlisted ('buflisted'), unnamed and buffers on removable media (|viminfo-r|) are not saved. I would simply make those files unlisted; as Vim is invoked from the version control system for the commit message, and usually no other files are edited within that session, the ...


2

Make a buffer active by its number You can combine win_gotoid() & win_findbuf() to accomplish this: :call win_gotoid(get(win_findbuf(g:tn), 0)) But we can do better for terminal like things by improving a few things: Automatically set our variable on TerminalOpen autocmd Provide methods to send text to the terminal Provide a command to jump to the ...


2

So the top buffer became "a mirror" of the terminal buffer with the number 2. Your problem is that you confuse "buffer" and "window". Those "rectangles" you see are called "windows", while their contents are called "buffers". So the command :b 2 says "I want a buffer number two to be shown in the current window". And that's not what you really wanted. ...


2

The usual solution is set hidden This allows a buffer to be made « hidden », i.e., not physically shown in a window, while still unsaved. Without 'hidden' on, vim’s default behavior is to not allow closing a modified buffer without being forced (via !s on commands). 'hidden' allows a third state between open and closed. Do note that 'confirm' may be ...


1

One way to achieve this is to :set autwriteall This will save the file before switching to another and also save it before quitting Vim. Gleaned from :help autowrite and :help autowriteall: Write the contents of the file, if it has been modified, on each next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, make, CTRL-] and CTRL-^ ...


4

The only problems I see with :substitute are: it messes a few registers we may have to be wary of the separator character used that'll need to be escaped its behaviour depends on 'magic' option (as well as substitute()'s one) If you really want to operate on the whole buffer without :s, you could also use the following oneliner (that'll be more efficient ...


0

One way could be using regular for loop: let idx = 1 for line in getbufline(bufnr('%'), 1, "$") call setline(idx, substitute(line, 'A', 'B', 'g')) let idx += 1 endfor or for line in range(0, line('$')) call setline(line, substitute(getline(line), 'A', 'B', 'g')) endfor which is pretty obvious. Another one could be: let buflines = getbufline(...


2

since this is documented best-practice in scripts Documented where? In vimscript (in which plugins are written), every "statement" is an Ex command, you can do function MyFunc() abort %substitute/pattern/repl/g endfunction or whatever it is you're trying to do. This is in fact the simplest mechanism. You can add modifiers (keepjumps, etc.) to the ...


4

Macros are stored in the same registers as you use for yanking, deleting, and putting, so any of "ap :put a Etc


Top 50 recent answers are included