diff --git a/src/main.cc b/src/main.cc index 047c6aa4..c9c2f900 100644 --- a/src/main.cc +++ b/src/main.cc @@ -4,6 +4,7 @@ #include "regex_selector.hh" #include "command_manager.hh" #include "buffer_manager.hh" +#include "register_manager.hh" #include "selectors.hh" #include "assert.hh" @@ -352,6 +353,16 @@ void do_search(Window& window) catch (prompt_aborted&) {} } +void do_yank(Window& window, int count) +{ + RegisterManager::instance()['"'] = window.selection_content(); +} + +void do_paste(Window& window, int count) +{ + window.append(RegisterManager::instance()['"']); +} + std::unordered_map> keymap = { { 'h', [](Window& window, int count) { window.move_cursor(WindowCoord(0, -std::max(count,1))); window.empty_selections(); } }, @@ -379,6 +390,9 @@ std::unordered_map> keymap { 'g', do_go }, + { 'y', do_yank }, + { 'p', do_paste }, + { ':', [](Window& window, int count) { do_command(); } }, { ' ', [](Window& window, int count) { window.empty_selections(); } }, { 'w', [](Window& window, int count) { do { window.select(false, select_to_next_word); } while(--count > 0); } }, @@ -401,6 +415,7 @@ int main(int argc, char* argv[]) CommandManager command_manager; BufferManager buffer_manager; + RegisterManager register_manager; command_manager.register_command(std::vector{ "e", "edit" }, edit, PerArgumentCommandCompleter{ complete_filename }); diff --git a/src/register_manager.hh b/src/register_manager.hh new file mode 100644 index 00000000..46bcfc06 --- /dev/null +++ b/src/register_manager.hh @@ -0,0 +1,20 @@ +#ifndef register_manager_hh_INCLUDED +#define register_manager_hh_INCLUDED + +#include "utils.hh" + +namespace Kakoune +{ + +class RegisterManager : public Singleton +{ +public: + std::string& operator[](char reg) { return m_registers[reg]; } + +protected: + std::unordered_map m_registers; +}; + +} + +#endif // register_manager_hh_INCLUDED