The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

5

Can it be written? Yup. command! -nargs=* -complete=command KeepCursor \ let [s:view, s:win] = [winsaveview(), win_getid()] | \ try | \ execute <q-args> | \ finally | \ if win_id2win(s:win) | \ call win_gotoid(s:win) | \ endif | \ keepjumps call winrestview(s:view) | \ endtry Can it ...


5

Does something like this exist? In Vim this is called an autocommand. The relevant help topic can be found by typing :h autocommand (sic!) An example code to put into vimrc: augroup typescript_save | au! autocmd BufWritePost *.ts execute '!tsc' expand("<afile>:p:S") augroup end


4

it doesn't seem to pass in the argument Because you haven't passed it. The right syntax is: command! -nargs=1 Vres vertical resize <args> Simply read :help :command until the very end to know all the options.


3

Can it be written? Possibly, but it might be a lot harder than expected. Because, what do you do with commands that close the current window? Or commands, that add lines above the current cursor position? One problem you are running into is described unter :h function-search-undo. The last used search pattern and the redo command "." will not be changed ...


3

I’d recommend an <expr> mapping—make the following changes: nnoremap <expr> <Leader>b BuildSystemTask() And then in your function: if inProject() return ':make! ' else return '' An alternative would be to use the feedkeys() function


2

You must add -nargs=1 to your command: :command -nargs=1 FooCommand :call Foo(<q-args>) This tells Vim not to treat white space as separator. Only white space between the command name and the first non-white space character is removed from the argument passed to Foo(). All other spaces and tabs, even trailing ones, are included in the argument.


2

Can simply use exec and . to build the command: let PathToPluginsFolder = ~/.vim/plugins command! PS silent! exec ':w | PlugSnapshot! ' . PathToPluginsFolder . '/plugins.lock'


1

It's faster as :buf won't reload the file from disk, whereas :edit will, which is different behaviour. This is why it's slightly slower in some cases. For most purposes, this is not a huge issue, although it can be over NFS connections, or with larger files. The performance should be identical when opening files that are not yet loaded by Vim. You can test/...


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