Skip to content

Instantly share code, notes, and snippets.

@neanias
Created September 30, 2021 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neanias/704267874732f053664c9a3eb9eba201 to your computer and use it in GitHub Desktop.
Save neanias/704267874732f053664c9a3eb9eba201 to your computer and use it in GitHub Desktop.
Partial work laptop nvim config
set nocompatible " be iMproved, required
lua << EOF
local execute = vim.api.nvim_command
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path})
execute 'packadd packer.nvim'
end
vim.cmd [[packadd packer.nvim]]
require("packer").startup({function(use)
-- Let packer manage itself
use "wbthomason/packer.nvim"
use {
"windwp/nvim-autopairs",
after = "nvim-cmp",
config = function()
local remap = vim.api.nvim_set_keymap
local npairs = require("nvim-autopairs")
npairs.setup({
check_ts = true,
})
npairs.add_rules(require('nvim-autopairs.rules.endwise-lua'))
npairs.add_rules(require('nvim-autopairs.rules.endwise-ruby'))
-- you need setup cmp first put this after cmp.setup()
require("nvim-autopairs.completion.cmp").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true, -- it will auto insert `(` (map_char) after select function or method item
auto_select = true, -- automatically select the first item
insert = false, -- use insert confirm behavior instead of replace
map_char = { -- modifies the function or method delimiter by filetypes
all = '(',
tex = '{'
}
})
end
}
-- { Neovim 0.5.0 plugins
-- Treesitter
use {
"nvim-treesitter/nvim-treesitter",
branch = "0.5-compat",
run = ':TSUpdate',
config = function()
require('nvim-treesitter.configs').setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = {}, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = {}, -- list of language that will be disabled
},
indent = {
enable = true,
},
refactor = {
smart_rename = {
enable = true,
keymaps = {
smart_rename = "grr",
},
},
navigation = {
enable = true,
keymaps = {
goto_definition = "gnd",
list_definitions = "gnD",
list_definitions_toc = "gO",
goto_next_usage = "<a-*>",
goto_previous_usage = "<a-#>",
},
},
},
rainbow = {
enable = true,
extended_mode = true,
}
}
end
} -- We recommend updating the parsers on update
use "nvim-treesitter/nvim-treesitter-refactor"
use {
"romgrk/nvim-treesitter-context",
config = function()
require('treesitter-context.config').setup { enable = true, }
end
}
use {
"nvim-treesitter/nvim-treesitter-textobjects",
branch = "0.5-compat",
config = function()
require('nvim-treesitter.configs').setup {
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
["ar"] = "@block.outer",
["ir"] = "@block.inner",
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
lsp_interop = {
enable = true,
border = 'none',
peek_definition_code = {
["df"] = "@function.outer",
["dF"] = "@class.outer",
},
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
}
end
}
-- To keep track of bindings
use {
"folke/which-key.nvim",
event = "VimEnter",
config = function()
require("which-key").setup()
end
}
use {
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
config = function()
require("todo-comments").setup {}
end
}
use {
"folke/trouble.nvim",
requires = "kyazdani42/nvim-web-devicons",
config = function()
require("trouble").setup({
auto_preview = false,
auto_fold = true
})
end
}
-- Finders
use {
"nvim-telescope/telescope.nvim",
requires = {{"nvim-lua/popup.nvim"}, {"nvim-lua/plenary.nvim"}},
config = function()
local trouble = require("trouble.providers.telescope")
local telescope = require("telescope")
telescope.setup {
defaults = {
mappings = {
i = { ["<C-t>"] = trouble.open_with_trouble },
n = { ["<C-t>"] = trouble.open_with_trouble },
},
},
pickers = {
buffers = {
sort_lastused = true,
mappings = {
i = {
["<c-d>"] = require("telescope.actions").delete_buffer,
},
n = {
["<c-d>"] = require("telescope.actions").delete_buffer,
},
}
}
}
}
end
}
use {
"neovim/nvim-lspconfig",
config = function()
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
--Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<comma>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<comma>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<comma>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<comma>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<comma>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<comma>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'grf', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<comma>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<comma>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<comma>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { "solargraph" }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
end
}
use {
"hrsh7th/nvim-cmp",
-- event = "InsertEnter",
-- wants = "luasnip",
requires = {
-- "hrsh7th/cmp-nvim-lsp",
-- "hrsh7th/cmp-buffer",
-- {
-- "L3MON4D3/LuaSnip",
-- wants = "friendly-snippets",
-- event = "InsertCharPre",
-- config = function()
-- require("luasnip").config.set_config({
-- history = true,
-- })
-- require("luasnip/loaders/from_vscode").lazy_load()
-- end
-- },
-- "saadparwaiz1/cmp_luasnip",
-- {
-- "rafamadriz/friendly-snippets",
-- event = "InsertCharPre"
-- }
},
-- config = function()
-- local has_words_before = function()
-- if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
-- return false
-- end
-- local line, col = unpack(vim.api.nvim_win_get_cursor(0))
-- return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
-- end
-- local feedkey = function(key)
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true)
-- end
-- local luasnip = require("luasnip")
-- local cmp = require("cmp")
-- cmp.setup({
-- snippet = {
-- expand = function(args)
-- -- For `luasnip` user.
-- require('luasnip').lsp_expand(args.body)
-- end,
-- },
-- mapping = {
-- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
-- -- ['<C-Space>'] = cmp.mapping.complete(),
-- ['<C-e>'] = cmp.mapping.close(),
-- -- ['<CR>'] = cmp.mapping.confirm({ select = true }),
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if vim.fn.pumvisible() == 1 then
-- feedkey("<C-n>")
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
-- elseif has_words_before() then
-- cmp.complete()
-- else
-- fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
-- end
-- end, { "i", "s" }),
-- ["<S-Tab>"] = cmp.mapping(function(fallback)
-- if vim.fn.pumvisible() == 1 then
-- feedkey("<C-p>")
-- elseif luasnip.jumpable(-1) then
-- luasnip.jump(-1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
-- },
-- sources = {
-- { name = 'nvim_lsp' },
-- -- For luasnip user.
-- { name = 'luasnip' },
-- { name = 'buffer' },
-- }
-- })
-- -- Setup lspconfig.
-- require("lspconfig")["solargraph"].setup {
-- capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- }
-- end
}
use {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
}
use {
"L3MON4D3/LuaSnip",
wants = "friendly-snippets",
-- event = "InsertCharPre",
config = function()
require("luasnip").config.set_config({
history = true,
})
require("luasnip/loaders/from_vscode").lazy_load()
end
}
use {
"saadparwaiz1/cmp_luasnip",
-- after = "nvim_cmp"
}
use {
"rafamadriz/friendly-snippets",
-- event = "InsertCharPre"
}
use {
"hoob3rt/lualine.nvim",
requires = {"kyazdani42/nvim-web-devicons", opt = true},
as = "lualine",
config = function()
local background = vim.opt.background:get()
require('lualine').setup { options = { theme = 'solarized_'..background } }
end
}
-- }
-- TPope time
use {
"tpope/vim-abolish",
"tpope/vim-eunuch",
"tpope/vim-fugitive",
"tpope/vim-obsession",
"tpope/vim-projectionist",
"tpope/vim-repeat",
"tpope/vim-surround",
"tpope/vim-unimpaired",
}
use { "tpope/vim-rails", ft = { "ruby", "eruby", "haml", "slim", "coffee" } }
use { "tpope/vim-rake", ft = "ruby" }
-- Better commenting
use "preservim/nerdcommenter"
-- Nice file browsing
use {
"kyazdani42/nvim-tree.lua",
requires = "kyazdani42/nvim-web-devicons",
cmd = { "NvimTreeToggle", "NvimTreeFindFile" }
}
use {
"mbbill/undotree",
cmd = "UndotreeToggle"
}
-- Check that it actually has ctags before kick-off
use {
"preservim/tagbar",
cond = function()
return vim.call("executable", "ctags") == 1
end,
cmd = "TagbarToggle"
}
use {
"AckslD/nvim-neoclip.lua",
config = function()
require('neoclip').setup()
end,
}
-- Snippets
use "honza/vim-snippets"
-- Syntax & languages
-- Do I still need ALE?
use {
"dense-analysis/ale",
ft = {"typescript", "rust", "ruby"},
cmd = "ALEEnable",
config = "vim.cmd[[ALEEnable]]"
}
use "sheerun/vim-polyglot"
use { "jmcantrell/vim-virtualenv", ft = "python" }
use { "slashmili/alchemist.vim", ft = "elixir" }
-- use { "neoclide/coc.nvim", branch = "release" }
-- use {
-- "neoclide/coc-solargraph",
-- run = "yarn install --frozen-lockfile",
-- cond = function() return vim.call("executable", "solargraph") == 1 end
-- }
-- use {
-- "ms-jpq/coq_nvim",
-- branch = "coq",
-- }
-- use {
-- "ms-jpq/coq.artifacts",
-- branch = "artifacts",
-- requires = "ms-jpq/coq_nvim"
-- }
-- EditorConfig
use "editorconfig/editorconfig-vim"
-- Pretty colours
use "ishan9299/nvim-solarized-lua"
use "p00f/nvim-ts-rainbow"
-- Other stuff
use { 'junegunn/vim-easy-align', cmd = "EasyAlign" }
use { 'AndrewRadev/splitjoin.vim', branch = 'main' }
use 'AndrewRadev/switch.vim'
use { 'ck3g/vim-change-hash-syntax', ft = { "ruby", "eruby" } }
use 'nathanaelkane/vim-indent-guides'
use {
"nelstrom/vim-textobj-rubyblock",
requires = {
{"lucapette/vim-textobj-underscore"}, {"kana/vim-textobj-user"}
}
}
use 'airblade/vim-gitgutter'
use 'vim-scripts/YankRing.vim'
-- Test runner
use {
"rcarriga/vim-ultest",
requires = {"vim-test/vim-test"},
run = ":UpdateRemotePlugins",
cmd = { "Ultest", "UltestNearest" }
}
-- Better search
use "henrik/vim-indexed-search"
use "haya14busa/incsearch.vim"
-- Vim motions on speed
use {
"phaazon/hop.nvim",
as = "hop",
cmd = { "HopWord", "HopChar1" },
config = function()
require("hop").setup {}
end
}
-- FZF
use {
"junegunn/fzf.vim",
requires = { "junegunn/fzf", run = function() vim.fn["fzf#install()"](0) end }
}
end,
config = {
display = {
open_fn = require("packer.util").float,
},
},
})
local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local feedkey = function(key)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true)
end
local luasnip = require("luasnip")
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
-- For `luasnip` user.
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
-- ['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
-- ['<CR>'] = cmp.mapping.confirm({ select = true }),
["<Tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
feedkey("<C-n>")
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
feedkey("<C-p>")
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
},
sources = {
{ name = 'nvim_lsp' },
-- For luasnip user.
{ name = 'luasnip' },
{ name = 'buffer' },
}
})
-- Setup lspconfig.
require("lspconfig")["solargraph"].setup {
capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
}
EOF
filetype plugin indent on " required
set number
set ruler
set autoindent
set smartindent
set expandtab
set smarttab
set showmode
set showcmd
set tabstop=4
set shiftwidth=2
set autoread
runtime macros/matchit.vim
" Needed for solarized
set termguicolors
syntax enable
set hlsearch
set ignorecase
set smartcase
set lazyredraw
set magic
set hidden
set showmatch
set mat=2
set noswapfile
let mapleader=","
set so=8
set wildignore=*.o,*~,*.pyc
set cmdheight=1
set ffs=unix,dos,mac
" Fix backspace not working
set backspace=indent,eol,start
set nowrap
set spelllang=en_gb
if has('nvim') " NeoVim terminal:
tnoremap <ESC> <C-\><C-n>
tnoremap <Leader><ESC> <C-\><C-n>
" 100k lines of scrollback in terminal buffer:
set scrollback=-1
" autocmd BufEnter * if &buftype == 'terminal' | :startinsert | endif
autocmd TermOpen term://* startinsert
endif
" Strip trailing whitespace in Python and Ruby files
autocmd BufWritePre *.py,*.rb :StripTrailingWhitespaces
" Set the syntax for .rbapi files to be Ruby
au BufNewFile,BufRead,BufReadPost *.rbapi set syntax=ruby
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
let g:python3_host_prog = '/Users/williammathewson/.pyenv/versions/neovim3/bin/python'
" Telescope
" Using lua functions
nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
nnoremap <leader>fp <cmd>lua require('telescope').extensions.neoclip.default()<cr>
nnoremap <leader>fs <cmd>lua require('telescope.builtin').search_history()<cr>
nnoremap <leader>ft <cmd>lua require('telescope.builtin').treesitter()<cr>
" ==== NvimTree
" Open the project tree and expose current file in the nerdtree with Ctrl-\
nnoremap <silent> <C-\> :NvimTreeFindFile<CR>
" ==== NERD commenter
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Use Q to intelligently close a window
" (if there are multiple windows into the same buffer)
" or kill the buffer entirely if it's the last window looking into that buffer
function! CloseWindowOrKillBuffer()
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
" We should never bdelete a nerd tree
if matchstr(expand("%"), 'Nvim') == 'Nvim'
wincmd c
return
endif
if number_of_windows_to_this_buffer > 1
wincmd c
else
bdelete
endif
endfunction
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<CR>
" Vim Ultest
" Custom RSpec extensions:
" - match `it { is_expected.to ... }`
" - allow `context` blocks to act as namespaces too
let g:ultest_custom_patterns = {
\ 'ruby#rspec': {
\ 'test': [
\ '\v^\s*it%(\(| )%("|'')(.*)%("|'')',
\ '\v^\s*it\s*%(\{)\s*(.*?)\s*\}',
\ ],
\ 'namespace': [
\ '\v^\s*%(describe|context)%(\(| )%("|'')(.*)%("|'')',
\ '\v^\s*%(describe|context)%(\(| )(\S+)',
\ ]
\ }
\}
" RSpec results can't be parsed out of a bigger run, so have to be run
" separately. Doing this sequentially avoids DB contention for now.
let g:ultest_max_threads = 1
" ALE
let g:ale_linters = {
\ 'typescript': ['tslint', 'tsserver', 'typecheck'],
\ 'rust': ['cargo', 'rls'],
\ 'ruby': ['rubocop', 'ruby', 'brakeman']
\}
let g:ale_ruby_rubocop_executable = 'bundle'
let g:ale_rust_rls_toolchain = 'stable'
let g:ale_python_auto_pipenv = 1
" coc.nvim
" inoremap <silent><expr> <TAB>
" \ pumvisible() ? coc#_select_confirm() :
" \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
" function! s:check_back_space() abort
" let col = col('.') - 1
" return !col || getline('.')[col - 1] =~# '\s'
" endfunction
" let g:coc_snippet_next = "<tab>"
" Use K to show documentation in preview window.
" nnoremap <silent> K :call <SID>show_documentation()<CR>
" function! s:show_documentation()
" if (index(['vim','help'], &filetype) >= 0)
" execute 'h '.expand('<cword>')
" elseif (coc#rpc#ready())
" call CocActionAsync('doHover')
" else
" execute '!' . &keywordprg . " " . expand('<cword>')
" endif
" endfunction
" Vim Markdown
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter = 1
" Tagbar
"open the taglist (method browser) using ,t
nnoremap <silent> ,T :TagbarToggle<CR>
let g:tagbar_type_ruby = {
\ 'kinds' : [
\ 'm:modules',
\ 'c:classes',
\ 'd:describes',
\ 'C:contexts',
\ 'f:methods',
\ 'F:singleton methods'
\ ]
\ }
let g:tagbar_type_snippets = {
\ 'ctagstype' : 'snippets',
\ 'kinds' : [
\ 's:snippets',
\ ]
\ }
" Indent guides
let g:indent_guides_auto_colors = 1
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
" Handy key bindings for surrounding things
" ,# Surround a word with #{ruby interpolation}
map ,# ysiw#
vmap ,# c#{<C-R>"}<ESC>
" ," Surround a word with "quotes"
map ," ysiw"
vmap ," c"<C-R>""<ESC>
" ,' Surround a word with 'single quotes'
map ,' ysiw'
vmap ,' c'<C-R>"'<ESC>
" ,) or ,( Surround a word with (parens)
" The difference is in whether a space is put in
map ,( ysiw(
map ,) ysiw)
vmap ,( c( <C-R>" )<ESC>
vmap ,) c(<C-R>")<ESC>
" ,[ Surround a word with [brackets]
map ,] ysiw]
map ,[ ysiw[
vmap ,[ c[ <C-R>" ]<ESC>
vmap ,] c[<C-R>"]<ESC>
" ,{ Surround a word with {braces}
map ,} ysiw}
map ,{ ysiw{
vmap ,} c{ <C-R>" }<ESC>
vmap ,{ c{<C-R>"}<ESC>
map ,` ysiw`
" Hop configuration
nmap <leader><leader>w <cmd>HopWord<cr>
nmap <leader><leader>b <cmd>HopWord<cr>
nmap <leader><leader>f <cmd>HopChar1<cr>
" nmap ,<ESC> ,,w
" nmap ,<S-ESC> ,,b
" ================ Persistent Undo ==================
" Keep undo history across sessions, by storing in file.
" Only works all the time.
if has('persistent_undo')
silent !mkdir ~/.config/nvim/backups > /dev/null 2>&1
set undodir=~/.config/nvim/backups
set undofile
endif
" Undotree
nnoremap <leader>u :UndotreeToggle<CR>
let g:undotree_WindowLayout = 3
" Create window splits easier. The default
" way is Ctrl-w,v and Ctrl-w,s. I remap
" this to vv and ss
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
" Smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" SplitJoin plugin
nmap sj :SplitjoinSplit<cr>
nmap sk :SplitjoinJoin<cr>
" Disable highlight when // is pressed
map <silent> // :noh<CR>
" Remap VIM 0 to first non-blank character
map 0 ^
" --- Easy Align ---
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Pretty self-explanatory (function def further down)
command! StripTrailingWhitespaces call <SID>StripTrailingWhitespaces()
nmap ,w :StripTrailingWhitespaces<CR>
" Incsearch.vim
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
" :h g:incsearch#auto_nohlsearch
set hlsearch
let g:incsearch#auto_nohlsearch = 1
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
map # <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" => Helper functions
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
" via: http://rails-bestpractices.com/posts/60-remove-trailing-whitespace
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" Colourful
if has('gui_running') || has('nvim')
" set background=dark
colorscheme solarized
endif
vim.cmd [[packadd packer.nvim]]
return require("packer").startup({function(use)
-- Let packer manage itself
use "wbthomason/packer.nvim"
use {
"windwp/nvim-autopairs",
config = function()
local remap = vim.api.nvim_set_keymap
local npairs = require("nvim-autopairs")
npairs.setup({
check_ts = true,
})
-- you need setup cmp first put this after cmp.setup()
require("nvim-autopairs.completion.cmp").setup({
map_cr = true, -- map <CR> on insert mode
map_complete = true, -- it will auto insert `(` (map_char) after select function or method item
auto_select = true, -- automatically select the first item
insert = false, -- use insert confirm behavior instead of replace
map_char = { -- modifies the function or method delimiter by filetypes
all = '(',
tex = '{'
}
})
end
}
-- { Neovim 0.5.0 plugins
-- Treesitter
use {
"nvim-treesitter/nvim-treesitter",
branch = "0.5-compat",
run = ':TSUpdate',
config = function()
require('nvim-treesitter.configs').setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = {}, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = {}, -- list of language that will be disabled
},
indent = {
enable = true,
},
refactor = {
smart_rename = {
enable = true,
keymaps = {
smart_rename = "grr",
},
},
navigation = {
enable = true,
keymaps = {
goto_definition = "gnd",
list_definitions = "gnD",
list_definitions_toc = "gO",
goto_next_usage = "<a-*>",
goto_previous_usage = "<a-#>",
},
},
},
rainbow = {
enable = true,
extended_mode = true,
}
}
end
} -- We recommend updating the parsers on update
use "nvim-treesitter/nvim-treesitter-refactor"
use {
"romgrk/nvim-treesitter-context",
config = function()
require('treesitter-context.config').setup { enable = true, }
end
}
use {
"nvim-treesitter/nvim-treesitter-textobjects",
branch = "0.5-compat",
config = function()
require('nvim-treesitter.configs').setup {
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
["ar"] = "@block.outer",
["ir"] = "@block.inner",
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
lsp_interop = {
enable = true,
border = 'none',
peek_definition_code = {
["df"] = "@function.outer",
["dF"] = "@class.outer",
},
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
}
end
}
-- To keep track of bindings
use {
"folke/which-key.nvim",
event = "VimEnter",
config = function()
require("which-key").setup()
end
}
use {
"folke/todo-comments.nvim",
requires = "nvim-lua/plenary.nvim",
config = function()
require("todo-comments").setup {}
end
}
use {
"folke/trouble.nvim",
requires = "kyazdani42/nvim-web-devicons",
config = function()
require("trouble").setup({
auto_preview = false,
auto_fold = true
})
end
}
-- Finders
use {
"nvim-telescope/telescope.nvim",
requires = {{"nvim-lua/popup.nvim"}, {"nvim-lua/plenary.nvim"}},
config = function()
local trouble = require("trouble.providers.telescope")
local telescope = require("telescope")
telescope.setup {
defaults = {
mappings = {
i = { ["<C-t>"] = trouble.open_with_trouble },
n = { ["<C-t>"] = trouble.open_with_trouble },
},
},
pickers = {
buffers = {
sort_lastused = true,
mappings = {
i = {
["<c-d>"] = require("telescope.actions").delete_buffer,
},
n = {
["<c-d>"] = require("telescope.actions").delete_buffer,
},
}
}
}
}
end
}
use {
"neovim/nvim-lspconfig",
config = function()
local nvim_lsp = require('lspconfig')
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
--Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
-- buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<comma>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<comma>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<comma>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<comma>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<comma>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<comma>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'grf', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<comma>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<comma>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap('n', '<comma>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { "solargraph" }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
end
}
use {
"hrsh7th/nvim-cmp",
event = "InsertEnter",
wants = "luasnip",
requires = {
-- "hrsh7th/cmp-nvim-lsp",
-- "hrsh7th/cmp-buffer",
-- {
-- "L3MON4D3/LuaSnip",
-- wants = "friendly-snippets",
-- event = "InsertCharPre",
-- config = function()
-- require("luasnip").config.set_config({
-- history = true,
-- })
-- require("luasnip/loaders/from_vscode").lazy_load()
-- end
-- },
-- "saadparwaiz1/cmp_luasnip",
-- {
-- "rafamadriz/friendly-snippets",
-- event = "InsertCharPre"
-- }
},
-- config = function()
-- local has_words_before = function()
-- if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
-- return false
-- end
-- local line, col = unpack(vim.api.nvim_win_get_cursor(0))
-- return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
-- end
-- local feedkey = function(key)
-- vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), "n", true)
-- end
-- local luasnip = require("luasnip")
-- local cmp = require("cmp")
-- cmp.setup({
-- snippet = {
-- expand = function(args)
-- -- For `luasnip` user.
-- require('luasnip').lsp_expand(args.body)
-- end,
-- },
-- mapping = {
-- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
-- -- ['<C-Space>'] = cmp.mapping.complete(),
-- ['<C-e>'] = cmp.mapping.close(),
-- -- ['<CR>'] = cmp.mapping.confirm({ select = true }),
-- ["<Tab>"] = cmp.mapping(function(fallback)
-- if vim.fn.pumvisible() == 1 then
-- feedkey("<C-n>")
-- elseif luasnip.expand_or_jumpable() then
-- luasnip.expand_or_jump()
-- elseif has_words_before() then
-- cmp.complete()
-- else
-- fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
-- end
-- end, { "i", "s" }),
-- ["<S-Tab>"] = cmp.mapping(function(fallback)
-- if vim.fn.pumvisible() == 1 then
-- feedkey("<C-p>")
-- elseif luasnip.jumpable(-1) then
-- luasnip.jump(-1)
-- else
-- fallback()
-- end
-- end, { "i", "s" }),
-- },
-- sources = {
-- { name = 'nvim_lsp' },
-- -- For luasnip user.
-- { name = 'luasnip' },
-- { name = 'buffer' },
-- }
-- })
-- -- Setup lspconfig.
-- require("lspconfig")["solargraph"].setup {
-- capabilities = require("cmp_nvim_lsp").update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- }
-- end
}
use {
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
}
use {
"L3MON4D3/LuaSnip",
wants = "friendly-snippets",
event = "InsertCharPre",
config = function()
require("luasnip").config.set_config({
history = true,
})
require("luasnip/loaders/from_vscode").lazy_load()
end
}
use {
"saadparwaiz1/cmp_luasnip",
after = "nvim_cmp"
}
use {
"rafamadriz/friendly-snippets",
event = "InsertCharPre"
}
use {
"hoob3rt/lualine.nvim",
requires = {"kyazdani42/nvim-web-devicons", opt = true},
as = "lualine",
config = function()
local background = vim.opt.background:get()
require('lualine').setup { options = { theme = 'solarized_'..background } }
end
}
-- }
-- TPope time
use {
"tpope/vim-abolish",
"tpope/vim-endwise",
"tpope/vim-eunuch",
"tpope/vim-fugitive",
"tpope/vim-obsession",
"tpope/vim-projectionist",
"tpope/vim-repeat",
"tpope/vim-surround",
"tpope/vim-unimpaired",
}
use { "tpope/vim-rails", ft = { "ruby", "eruby", "haml", "slim", "coffee" } }
use { "tpope/vim-rake", ft = "ruby" }
-- Better commenting
use "preservim/nerdcommenter"
-- Nice file browsing
use {
"kyazdani42/nvim-tree.lua",
requires = "kyazdani42/nvim-web-devicons",
cmd = { "NvimTreeToggle", "NvimTreeFindFile" }
}
use {
"mbbill/undotree",
cmd = "UndotreeToggle"
}
-- Check that it actually has ctags before kick-off
use {
"preservim/tagbar",
cond = function()
return vim.call("executable", "ctags") == 1
end,
cmd = "TagbarToggle"
}
-- Snippets
use "honza/vim-snippets"
-- Syntax & languages
-- Do I still need ALE?
use {
"dense-analysis/ale",
ft = {"typescript", "rust", "ruby"},
cmd = "ALEEnable",
config = "vim.cmd[[ALEEnable]]"
}
use "sheerun/vim-polyglot"
use { "jmcantrell/vim-virtualenv", ft = "python" }
use { "slashmili/alchemist.vim", ft = "elixir" }
-- use { "neoclide/coc.nvim", branch = "release" }
-- use {
-- "neoclide/coc-solargraph",
-- run = "yarn install --frozen-lockfile",
-- cond = function() return vim.call("executable", "solargraph") == 1 end
-- }
-- use {
-- "ms-jpq/coq_nvim",
-- branch = "coq",
-- }
-- use {
-- "ms-jpq/coq.artifacts",
-- branch = "artifacts",
-- requires = "ms-jpq/coq_nvim"
-- }
-- EditorConfig
use "editorconfig/editorconfig-vim"
-- Pretty colours
use "ishan9299/nvim-solarized-lua"
use "p00f/nvim-ts-rainbow"
-- Other stuff
use { 'junegunn/vim-easy-align', cmd = "EasyAlign" }
use { 'AndrewRadev/splitjoin.vim', branch = 'main' }
use 'AndrewRadev/switch.vim'
use { 'ck3g/vim-change-hash-syntax', ft = { "ruby", "eruby" } }
use 'nathanaelkane/vim-indent-guides'
use {
"nelstrom/vim-textobj-rubyblock",
requires = {
{"lucapette/vim-textobj-underscore"}, {"kana/vim-textobj-user"}
}
}
use 'airblade/vim-gitgutter'
use 'vim-scripts/YankRing.vim'
-- Test runner
use {
"rcarriga/vim-ultest",
requires = {"vim-test/vim-test"},
run = ":UpdateRemotePlugins",
cmd = { "Ultest", "UltestNearest" }
}
-- Better search
use "henrik/vim-indexed-search"
use "haya14busa/incsearch.vim"
-- Vim motions on speed
use {
"phaazon/hop.nvim",
as = "hop",
cmd = { "HopWord", "HopChar1" },
config = function()
require("hop").setup {}
end
}
-- FZF
use {
"junegunn/fzf.vim",
requires = { "junegunn/fzf", run = function() vim.fn["fzf#install()"](0) end }
}
end,
config = {
display = {
open_fn = require("packer.util").float,
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment