From 3189c372859c6c807dc86aa8782bacaa3c2826c1 Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Mon, 4 Aug 2025 01:32:04 +0200 Subject: Engage! --- LICENSE | 24 +++++++++++++++++ README.md | 23 ++++++++++++++++ autoload/sniper.vim | 43 ++++++++++++++++++++++++++++++ doc/sniper.txt | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++ plugin/sniper.vim | 13 +++++++++ 5 files changed, 179 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100644 autoload/sniper.vim create mode 100644 doc/sniper.txt create mode 100644 plugin/sniper.vim diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..23f05ad --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +BSD 2-Clause License + +Copyright (c) 2025, Mitja Felicijan + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c036492 --- /dev/null +++ b/README.md @@ -0,0 +1,23 @@ +# Simple Vim Buffer Bookmark Manager + +Quickly store and recall buffers with F1-F4 keys. + +## Installation + +Using vim-plug: + +```vim +Plug 'mitjafelicijan/sniper.vim' +``` + +## Usage + +- `Shift-F1` to store current buffer in slot 1 +- `Shift-F2` to store current buffer in slot 2 +- `Shift-F3` to store current buffer in slot 3 +- `Shift-F4` to store current buffer in slot 4 +- `F1` to recall buffer from slot 1 +- `F2` to recall buffer from slot 2 +- `F3` to recall buffer from slot 3 +- `F4` to recall buffer from slot 4 +- `F5` or `:SniperList` to view all stored buffers diff --git a/autoload/sniper.vim b/autoload/sniper.vim new file mode 100644 index 0000000..6d364d6 --- /dev/null +++ b/autoload/sniper.vim @@ -0,0 +1,43 @@ +let s:buffer_store = ['', '', '', ''] + +function! sniper#StoreBuffer(pos) abort + if a:pos < 1 || a:pos > 4 + echoerr "Position must be between 1-4" + return + endif + let s:buffer_store[a:pos - 1] = bufnr('%') + echo "Stored buffer" bufnr('%') "in position" a:pos +endfunction + +function! sniper#RecallBuffer(pos) abort + if a:pos < 1 || a:pos > 4 + echoerr "Position must be between 1-4" + return + endif + + let target_buf = s:buffer_store[a:pos - 1] + if empty(target_buf) || !bufexists(target_buf) + echo "No buffer stored in position" a:pos + return + endif + + execute "buffer" target_buf +endfunction + +function! sniper#ListBuffers() abort + let output = ["Buffer list:", ""] + for i in range(4) + let bufnum = s:buffer_store[i] + if !empty(bufnum) && bufexists(bufnum) + let status = printf("[F%d] %s (%s) - %s", + \ i+1, + \ bufname(bufnum), + \ bufnum, + \ buflisted(bufnum) ? "LOADED" : "UNLOADED") + else + let status = printf("[F%d] ", i+1) + endif + call add(output, status) + endfor + echo join(output, "\n") +endfunction diff --git a/doc/sniper.txt b/doc/sniper.txt new file mode 100644 index 0000000..f686551 --- /dev/null +++ b/doc/sniper.txt @@ -0,0 +1,76 @@ +*sniper.txt* Sniper Plugin + +============================================================================== +CONTENTS *sniper-contents* + +1. Introduction |sniper-intro| +2. Commands |sniper-commands| +3. Mappings |sniper-mappings| +4. Functions |sniper-functions| +5. License |sniper-license| + +============================================================================== +1. INTRODUCTION *sniper-intro* + +The sniper plugin provides quick buffer storage and recall using F1-F4 keys. +It maintains 4 slots for fast buffer switching. + +============================================================================== +2. COMMANDS *sniper-commands* + +:SniperList List all stored buffers with their status + Shows: [Slot] BufferName (ID) - STATUS + +============================================================================== +3. MAPPINGS *sniper-mappings* + +Normal mode mappings: + Store current buffer in slot 1 + Store current buffer in slot 2 + Store current buffer in slot 3 + Store current buffer in slot 4 + + Recall buffer from slot 1 + Recall buffer from slot 2 + Recall buffer from slot 3 + Recall buffer from slot 4 + + Lists all buffer slots + +============================================================================== +4. FUNCTIONS *sniper-functions* + +sniper#StoreBuffer(pos) Store current buffer in specified position (1-4) +sniper#RecallBuffer(pos) Recall buffer from specified position (1-4) +sniper#ListBuffers() Display all stored buffers + +============================================================================== +5. LICENSE *sniper-license* + +BSD 2-Clause License +Copyright (c) 2025 Mitja Felicijan + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +============================================================================== +vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/sniper.vim b/plugin/sniper.vim new file mode 100644 index 0000000..50e5f96 --- /dev/null +++ b/plugin/sniper.vim @@ -0,0 +1,13 @@ +nnoremap :call sniper#StoreBuffer(1) +nnoremap :call sniper#StoreBuffer(2) +nnoremap :call sniper#StoreBuffer(3) +nnoremap :call sniper#StoreBuffer(4) + +nnoremap :call sniper#RecallBuffer(1) +nnoremap :call sniper#RecallBuffer(2) +nnoremap :call sniper#RecallBuffer(3) +nnoremap :call sniper#RecallBuffer(4) + +nnoremap :call sniper#ListBuffers() + +command! SniperList call sniper#ListBuffers() -- cgit v1.2.3