Skip to content

Instantly share code, notes, and snippets.

@jimnanney
Created February 9, 2022 22:20
Show Gist options
  • Select an option

  • Save jimnanney/f5c5b3bff3b215160816fc1e8b761479 to your computer and use it in GitHub Desktop.

Select an option

Save jimnanney/f5c5b3bff3b215160816fc1e8b761479 to your computer and use it in GitHub Desktop.
local cmd = vim.cmd
local function nvim_create_augroups(definitions)
for group_name, definition in pairs(definitions) do
-- api.nvim_command('augroup '..group_name)
-- api.nvim_command('autocmd!')
for _, def in ipairs(definition) do
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
print(command)
-- api.nvim_command(command)
end
-- kapi.nvim_command('augroup END')
end
end
FILETYPEHOOKS = {
ruby = function()
vim.bo.autoindent = true
vim.bo.bomb = false
vim.bo.expandtab = true
vim.bo.shiftwidth = 2
vim.bo.softtabstop = 2
end;
javascript = function()
vim.bo.autoindent = true
vim.bo.bomb = false
vim.bo.expandtab = true
vim.bo.shiftwidth = 2
vim.bo.softtabstop = 2
end;
}
local autocmds = {
javascript = {
{ 'FileType', 'javascript', 'lua FILETYPE_HOOKS.javascript()' };
{ 'FileType', 'javascript.jsx', 'lua FILETYPE_HOOKS.javascript()' };
{ 'BufRead,BufNewFile', '*.ts', 'setl ft=typescript' };
{ 'BufRead,BufNewFile', '*.tsx', 'setl ft=typescript.jsx' };
};
ruby = {
{ 'FileType', 'ruby,haml,eruby,yaml,html,sass,cucumber', 'lua FILETYPE_HOOKS.ruby()' };
{ 'BufRead,BufNewFile', '{Guardfile,Gemfile,RakeFile}', 'setl ft=ruby' };
{ 'BufRead,BufNewFile', '*.sass', 'setl ft=sass' };
};
vimrc = {
{'BufReadPost', '*', [[
if line("'\"") > 0 && line("'\"") <= line("$") |
exe "normal g`\"" |
endif
]]};
{'BufWritePost', '$MYVIMRC', 'source $MYVIMRC' };
};
}
set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
"source ~/.vimrc
call plug#begin(stdpath('config') . '/plugged')
Plug 'nvim-treesitter/nvim-treesitter', {'do': 'TSUpdate'}
Plug 'nvim-treesitter/playground'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'kyazdani42/nvim-web-devicons'
Plug 'rktjmp/lush.nvim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'christoomey/vim-tmux-runner'
Plug 'vim-airline/vim-airline'
Plug 'editorconfig/editorconfig'
Plug 'mattn/emmet-vim'
Plug 'altercation/vim-colors-solarized'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'flazz/vim-colorschemes'
Plug 'elixir-editors/vim-elixir'
Plug 'tpope/vim-dispatch'
Plug 'vim-ruby/vim-ruby'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()
lua << EOF
require('settings')
require('autocmds')
require 'lspconfig'.solargraph.setup{}
EOF
lua << EOF
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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>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', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap("n", "<space>f", "<cmd>lu 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
EOF
lua <<EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = { "javascript" }, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = { "c", "rust" }, -- list of language that will be disabled
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
}
EOF
lua <<EOF
require'nvim-treesitter.configs'.setup {
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
}
EOF
lua <<EOF
require'nvim-treesitter.configs'.setup {
indent = {
enable = true
}
}
EOF
lua <<EOF
require'nvim-web-devicons'.setup {
-- your personnal icons can go here (to override)
-- DevIcon will be appended to `name`
override = {
zsh = {
icon = "",
color = "#428850",
name = "Zsh"
}
};
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true;
}
EOF
set foldmethod=expr
set foldexpr=nvim_treesitter#foldexpr()
set foldlevelstart=20
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fg <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>fb <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
nnoremap <leader>fm <cmd>lua require('telescope.builtin').find_files({cwd = "app/models")<cr>
nnoremap <leader>fd <cmd>lua require('telescope.builtin').find_files({cwd = "spec/factories")<cr>
nnoremap <leader>fs <cmd>lua require('telescope.builtin').find_files({cwd = "spec/")<cr>
nnoremap <leader>fv <cmd>lua require('telescope.builtin').find_files({cwd = "app/views")<cr>
nnoremap <leader>fc <cmd>lua require('telescope.builtin').find_files({cwd = "app/controllers")<cr>
nnoremap <leader>fj <cmd>lua require('telescope.builtin').find_files({cwd = "app/javascript")<cr>
local opt = vim.opt
local o = vim.o
vim.cmd [[
syntax enable
filetype plugin indent on
]]
-- disable auto indent in typescript files
vim.g.typescript_indent_disable = '1'
-- set all emojis as full width unicode
o.emoji = true
-- search for tag definitions in .gemtags as well
opt.tags:append('.gemtags')
opt.tags:append('.git/tags')
-- set the unnamed register to yank to the "* register for system clipboard
o.clipboard = 'unnamed'
-- use line numbers in the gutter on the left side
o.number = true
-- allow unsaved background buffers and remember marks/undo for them
o.hidden = true
-- remember more commands and search history
o.history = 10000
-- expand tabs to spaces
o.expandtab = true
-- set tabs stops to 2 characters
o.tabstop = 2
-- overide defaults tabwidwiths when typing to 2 characters
o.shiftwidth = 2
o.softtabstop = 2
-- use autoindent
o.autoindent = true
-- always display a status line
o.laststatus = 2
-- show matching braces, brackets, and parens
o.showmatch = true
-- show the matches as you type the search pattern
o.incsearch = true
-- highlight the search pattern
o.hlsearch = true
-- make searches case-sensitive only if they contain upper-case characters
o.ignorecase = true
o.smartcase = true
-- highlight current line
o.cursorline = true
-- make the command mode : 2 lines high
o.cmdheight = 2
-- when switching buffers use the window with the buffer open if it exists
o.switchbuf = 'useopen'
-- use 5 cols for the line numbers in the gutter
o.numberwidth = 5
-- always show the tab page line (top)
o.showtabline = 2
-- sets the cols for a window to use, steals from other windows if this one is
-- smaller
o.winwidth = 79
-- Prevent Vim from clobbering the scrollback buffer. See
-- http://www.shallowsky.com/linux/noaltscreen.html
-- o.t_ti = nil
-- o.t_te = nil
-- keep more context when scrolling off the end of a buffer
o.scrolloff = 3
-- Store temporary files in a central spot
o.backup = true
o.backupdir = '~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp'
o.directory = '~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp'
-- allow backspacing over everything in insert mode
o.backspace = 'indent,eol,start'
-- display incomplete commands
o.showcmd = true
-- use emacs-style tab completion when selecting files, etc
o.wildmode = 'longest,list'
-- make tab completion for files/buffers act like bash
o.wildmenu = true
o.undodir = '$HOME/.vim/undo'
o.undolevels = 1000
o.undoreload = 10000
-- don't use two spaces after sentence end when joining lines
o.joinspaces = false
-- this fixes the O insert taking so long
o.timeout = true
o.timeoutlen = 1000
o.ttimeoutlen = 100
-- use modelines in files if found
o.modeline = true
-- check 3 lines for modelines
o.modelines = 3
-- ignore the patterns when expanding file globs
o.wildignore = 'tmp/*,*.swp,*.zip,*.exe,*.class,*.jar,*.ear,*.war,*\\node_modules\\**'
-- set the root search directory to first anscestor with a .git or if not found, the
-- current directory
vim.g.ctrlp_working_path_mode = 'ra'
-- when indexing, ignore these patterns of files / directories
vim.g.ctrlp_custom_ignore = [[
{
'dir': '\.git$\|\.hg$\|\.svn$\|classes$\|node_modules\|npm-packages-offline-cache\|tmp$\|pack\|pack-test$',
'file': '\.exe$\|\.so$\|\.dll$\|\.class$\|\.jar$\|\.ear$\|.\war$',
'link': 'SOME_BAD_SYMBOLIC_LINKS',
}
]]
-- don't try to index more that 100,000 files
vim.g.ctrlp_max_files = 100000
-- don't index deeper than 100 directories
vim.g.ctrlp_max_depth = 100
-- if indexing takes too long, you can use the git repo ls-files to get the
-- list of files to index
-- let g:ctrlp_user_command = ['.git/', 'git --git-dir=%s/.git ls-files -oc --exclude-standard']
vim.g.ctrlp_user_command = nil
o.grepprg = 'git grep -nI'
vim.cmd('colorscheme railscasts')
vim.cmd('hi Special guifg=#2a71dc ctermfg=32')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment