14

I don't think it's quite that simple but you can look at the Ruby code yourself here: https://github.com/igrigorik/vimgolf/tree/master/lib/vimgolf I see a class for keylogging, for one. Here's the command that is used to launch vim in lib/vimgolf/cli.rb: vimcmd = GOLFVIM.shellsplit + %W{-Z -n --noplugin --nofork -i NONE +0 -u #{challenge.vimrc_path}...


9

They probably use the built-in parameter -w, see :h -w: -w {scriptout} All the characters that you type are recorded in the file "scriptout", until you exit Vim. This is useful if you want to create a script file to be used with "vim -s" or ":source!". When the "scriptout" file already exists, new characters are appended. ...


9

Making a command for this means: Recording the time and number of words in the buffer at the start; you can use the wordcount() function to get the word count, and the reltime() function to get the time. Subtracting the current time and number of words from the values we had at the start. Profit! Here is a basic function which does exactly that: fun! s:...


8

Thanks to VanLaser comment, here is a little function to achieve what I wanted: function! GetNChar() let l:number = 3 let l:string = "" while l:number > 0 let l:string .= nr2char(getchar()) let l:number -= 1 endwhile echo l:string endfunction nnoremap gs :call GetNChar()<CR> Here I append the chars into a string and display it,...


7

The simple way is if get(g:, 'myplugin_enable_feature', defaultvalue) do whatever you want endif Now when I need to check a setting in more than one place, I usually prefer to have a dedicated getter in my plugin to be sure I have the same default value everywhere function! s:enable_feature() abort return get(g:, 'myplugin_enable_feature', ...


4

I'll give an answer, but not the one you are looking for. Hopefully, you will find it even better. Note that it does rely on you installing a plugin. First, what you are trying to do is to simplify the process of creating a new theorem environment. You want to apply a template and to fill out some parts automatically. You are in luck, because this is the ...


4

Usually it suffices to use get() function. Like that if get(g:, 'myplugin_enable_feature') " do something endif If the feature should be enabled by default you can change it to get(g:, 'myplugin_enable_feature', 1).


3

Maybe this is what you're aiming for? nnoremap gc :execute '!git commit -m "'.input('Enter message: ').'"'<cr> The only parts of your script that would do anything useful is the first line and the nmap line. The rest of it would either do nothing or not run at all. Since you're starting to learn VimL, here's a tip: Test simple ideas in the command ...


3

Unfortunately you can't; this format is "hardcoded" (in msg_show_console_dialog()). But you can re-create a function which mostly behaves the same with getchar(): fun! Confirm(msg) echo a:msg . ' ' let l:answer = nr2char(getchar()) if l:answer ==? 'y' return 1 elseif l:answer ==? 'n' return 0 else echo 'Please ...


3

Try this: :call feedkeys(':e ' . expand('%')) See :help feedkeys() for more details.


1

Patch 8.0.1445 introduced :h CmdlineChanged , you can use it together with :h input() to get what you want. Here is a simple example i wrote to update last line of current buffer to cmdline while typing in cmdline. function! s:on_input_change() call setline('$', getcmdline()) redraw endfunction function! s:dynamic_input() augroup input_test au! ...


1

I looked at the source and I don't see any user-facing way to disable the bell limit. You'd have to build your own version as you mentioned. Think twice about that, though... Rather than being a killjoy "feature" this apparently was implemented for the sake of Vim stability. I saw a couple comments indicating that rapid bell sequences can hang Vim. Here's ...


1

1) This should work for you, though it isn't perfect: function! GetKeyUnder200ms() let l:start = reltimefloat(reltime()) let l:char = getchar() if reltimefloat(reltime()) - l:start < 0.200 echo l:char else echo "Too slow!" endif endfunction The only downside to this approach is that you'll have to press a button regardless of whether ...


1

So this seems to work pretty well: augroup misc autocmd! autocmd BufEnter * nmap <buffer> gc :call GetCommMsg()<CR> augroup END function! GetCommMsg() let curline = getline('.') call inputsave() let msg = input('Enter commit message: ') call inputrestore() call system("git commit -m '" . msg . "'") endfunction Not sure if there ...


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