Skip to content

Instantly share code, notes, and snippets.

@wamoyo
Last active August 19, 2024 15:26
Show Gist options
  • Save wamoyo/34405c4672c89dbfded62ea34134003b to your computer and use it in GitHub Desktop.
Save wamoyo/34405c4672c89dbfded62ea34134003b to your computer and use it in GitHub Desktop.
nvimrc
filetype plugin indent on
" Setting up vim plug
call plug#begin('~/.config/nvim/plugged')
Plug 'MarcWeber/vim-addon-mw-utils'
Plug 'tomtom/tlib_vim'
Plug 'scrooloose/nerdtree'
Plug 'garbas/vim-snipmate'
Plug 'tpope/vim-surround'
Plug 'vim-scripts/matchit.zip'
Plug 'ervandew/supertab'
Plug 'vim-scripts/ctrlp.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'benknoble/vim-synstax'
" Plug 'pangloss/vim-javascript'
Plug 'digitaltoad/vim-pug'
Plug 'wuelnerdotexe/vim-astro'
Plug 'wavded/vim-stylus'
Plug 'sheerun/vim-polyglot'
" Getting Gen.vim working
Plug 'David-Kunz/gen.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'MunifTanjim/nui.nvim'
" Plug 'olimorris/codecompanion.nvim'
" Plug 'nvim-lua/plenary.nvim'
" Plug 'MunifTanjim/nui.nvim'
" Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
" Plug 'posva/vim-vue'
" Plug 'maxmellon/vim-jsx-pretty'
" Plug 'github/copilot.vim'
" Plug 'timakro/vim-searchant'
" Plug 'othree/eregex.vim'
" Plug 'itchyny/lightline.vim'
" Plug 'AutoClose'
" Plug 'mattn/emmet-vim'
call plug#end()
" Basic Settings
set termguicolors
colorscheme xoria256
set nofoldenable
set foldmethod=manual
augroup remember_folds
autocmd!
" autocmd BufWinLeave * mkview
" autocmd BufWinEnter * silent! loadview
augroup END
set relativenumber
set number
autocmd TermOpen * setlocal nonumber norelativenumber
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent
set hidden
set nowrap
set linebreak
set virtualedit=all
set listchars=tab:>>,trail:~,extends:…,precedes:…
set list
set wildmenu
set laststatus=0
set completeopt=
set iskeyword+=-
set confirm
set undofile
set title
set titlestring=%F
" Open vimrc
nnoremap <F12> :edit ~/.config/nvim/init.vim <Enter>
" Open snippets
let g:snipMate = { 'snippet_version' : 1 }
nnoremap <F7> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/astro.snippets <Enter> ~/.config/nvim/plugged/vim-snipmate/snippets/html.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/css.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/javascript.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/json.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/jade.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/stylus.snippets <Enter> :edit ~/.config/nvim/plugged/vim-snipmate/snippets/svg.snippets <Enter>
" ctrlP key combo
let g:ctrlp_map = 'gl'
" NERDTree key combo
nmap gf :NERDTreeToggle<cr>
autocmd FileType nerdtree nmap <buffer> o go
autocmd FileType nerdtree nmap <buffer> go o
" Wrap Toggle
function! ToggleWrap()
if g:wrapped
set nowrap
set list
set nobreakindent
nnoremap j j
nnoremap k k
let g:wrapped = 0
else
set wrap
set nolist
set breakindent
vnoremap j gj
vnoremap k gk
nnoremap j gj
nnoremap k gk
let g:wrapped = 1
endif
endfunction
let g:wrapped = 0
nnoremap gw :call ToggleWrap() <Enter>
" Remapping Keys
nnoremap t g;zz
vnoremap t g;zz
nnoremap T g,zz
vnoremap T g,zz
"onoremap 0 ^
"nnoremap 0 ^
"vnoremap 0 ^
onoremap - $
nnoremap - $
vnoremap - $
nnoremap m <C-o>
vnoremap m <C-o>
nnoremap M <C-i>
vnoremap M <C-i>
nnoremap ; :
vnoremap ; :
nnoremap e el
vnoremap e el
"nnoremap <C-y> "+y
vnoremap <C-y> "+y
nnoremap <C-p> "+gP
vnoremap <C-p> "+gP
nnoremap P "0P
vnoremap P "0P
nnoremap p P
vnoremap p P
nnoremap o O
nnoremap o O
vnoremap O o
vnoremap O o
nnoremap U <C-r>
nnoremap <silent> <esc> :noh<cr>
inoremap jj <Esc>l
inoremap kk <Esc>l
nnoremap J <C-e>
vnoremap J <C-e>
nnoremap K <C-y>
vnoremap K <C-y>
nnoremap S :wa <CR>
nnoremap s :w <CR>
nnoremap gb :bn <Enter>
nnoremap gB :bp <Enter>
nnoremap <C-w> :w <Enter> :bw <Enter>
nnoremap <C-q> :wa <Enter> :q <Enter>
nmap <silent> <A-Up> :wincmd k<CR>
nmap <silent> <A-Down> :wincmd j<CR>
nmap <silent> <A-Left> :wincmd h<CR>
nmap <silent> <A-h> :wincmd h<CR>
nmap <silent> <A-Right> :wincmd l<CR>
nmap <silent> <A-l> :wincmd l<CR>
tnoremap <Esc> <C-\><C-n>
" Searchant settings
" let g:searchant_map_stop=0
" nmap <Esc> <Plug>SearchantStop
" commentary.vim plugin
" Visual mode
xmap <tab> <Plug>Commentary
" Normal mode
nmap <tab> <Plug>Commentary
" Normal mode, current line
nmap <tab><tab> <Plug>CommentaryLine
" Operator pending mode (this lets you do e.g. `dgc` to delete a block of comments)
omap \ <Plug>Commentary
" Special case cgc (you can skip this one, but then `cgc` will also delete an extra blank line)
" nmap cgc <Plug>ChangeCommentary
" some more settings
let g:astro_typescript = 'enable'
let g:astro_stylus = 'enable'
let g:terminal_scrollback_buffer_size = 100000
" let html_no_rendering=1
" let g:javascript_plugin_jsdoc = 1
" let g:vim_json_syntax_conceal = 0
" autocmd BufNewFile,BufRead *.json set filetype=json
autocmd BufNewFile,BufRead *.pug set filetype=pug
autocmd BufNewFile,BufRead *.styl set filetype=stylus
" autocmd BufNewFile,BufRead *.js set filetype=jsx
autocmd BufEnter * setlocal formatoptions-=cro
syntax on
" Avoid E173 (n more file(s) to edit) " This doesn't work with the mkview and loadview above
if argc() > 1
silent blast
silent bfirst
endif
" Set the leader key to ','
let mapleader=","
" Configure Gen.vim
lua << EOF
require("gen").setup({
model = "llama3.1", -- The default model to use.
quit_map = "q", -- set keymap for close the response window
retry_map = "<c-r>", -- set keymap to re-send the current prompt
accept_map = "<c-cr>", -- set keymap to replace the previous selection with the last result
host = "localhost", -- The host running the Ollama service.
port = "11434", -- The port on which the Ollama service is listening.
display_mode = "float", -- The display mode. Can be "float" or "split" or "horizontal-split".
show_prompt = false, -- Shows the prompt submitted to Ollama.
show_model = false, -- Displays which model you are using at the beginning of your chat session.
no_auto_close = false, -- Never closes the window automatically.
hidden = false, -- Hide the generation window (if true, will implicitly set `prompt.replace = true`), requires Neovim >= 0.10
init = function(options) pcall(io.popen, "ollama serve > /dev/null 2>&1 &") end,
-- Function to initialize Ollama
command = function(options)
local body = {model = options.model, stream = true}
return "curl --silent --no-buffer -X POST http://" .. options.host .. ":" .. options.port .. "/api/chat -d $body"
end,
-- The command for the Ollama service. You can use placeholders $prompt, $model and $body (shellescaped).
-- This can also be a command string.
-- The executed command must return a JSON object with { response, context }
-- (context property is optional).
-- list_models = '<omitted lua function>', -- Retrieves a list of model names
debug = false -- Prints errors and the command which is run.
})
-- Map ',' to trigger the basic prompt
vim.keymap.set({ 'n', 'v' }, '<leader>', ':Gen<CR>', { noremap = true, silent = true })
-- Define the custom prompt for changing code
require('gen').prompts['Change_Code_Custom'] = {
prompt = function()
local input = vim.fn.input("Enter your prompt: ")
return "Change the following code based on this instruction:\n" .. input .. "\n$text\nOnly respond with the code to replace the selected text. NOTHING ELSE."
end,
replace = true
}
-- Map ',' + 'c' to trigger the custom Change_Code_Custom prompt in visual mode
vim.keymap.set('v', ',c', function()
vim.cmd('Gen Change_Code_Custom')
end, { noremap = true, silent = true })
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment