diff options
Diffstat (limited to 'Common/nvim')
-rw-r--r-- | Common/nvim/after/ftplugin/vhdl.lua | 3 | ||||
-rw-r--r-- | Common/nvim/init.lua | 3 | ||||
-rw-r--r-- | Common/nvim/init.vim | 3 | ||||
-rw-r--r-- | Common/nvim/lua/basic.lua | 239 | ||||
-rw-r--r-- | Common/nvim/lua/helper_functions.lua | 72 | ||||
-rw-r--r-- | Common/nvim/lua/plugins.lua | 25 |
6 files changed, 342 insertions, 3 deletions
diff --git a/Common/nvim/after/ftplugin/vhdl.lua b/Common/nvim/after/ftplugin/vhdl.lua new file mode 100644 index 0000000..7744755 --- /dev/null +++ b/Common/nvim/after/ftplugin/vhdl.lua @@ -0,0 +1,3 @@ +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 diff --git a/Common/nvim/init.lua b/Common/nvim/init.lua new file mode 100644 index 0000000..ee75788 --- /dev/null +++ b/Common/nvim/init.lua @@ -0,0 +1,3 @@ +require("helper_functions") +require("basic") +require('plugins') diff --git a/Common/nvim/init.vim b/Common/nvim/init.vim deleted file mode 100644 index f182e5b..0000000 --- a/Common/nvim/init.vim +++ /dev/null @@ -1,3 +0,0 @@ -set runtimepath^=~/.vim runtimepath+=~/.vim/after -let &packpath = &runtimepath -source ~/.vimrc diff --git a/Common/nvim/lua/basic.lua b/Common/nvim/lua/basic.lua new file mode 100644 index 0000000..16e9a62 --- /dev/null +++ b/Common/nvim/lua/basic.lua @@ -0,0 +1,239 @@ +--[[ +General +--]] + +-- Lines of history +vim.opt.history = 500 +-- Line numbers +vim.opt.nu = true + +-- Autoread when file is changed outside vim +vim.opt.autoread = true + +-- enable filetype plugins +vim.cmd [[ + filetype plugin on + filetype indent on +]] + +-- Use a mapleader +--vim.opt.mapleader = "," +vim.g.mapleader = "," + +-- Fast saving +map('n', '<leader>w', ':w!<cr>', silentnoremap) + +-- Convenient sudo saving of file +vim.api.nvim_create_user_command( + 'W', 'w !sudo tee % > /dev/null', + {bang=true, desc='Save file using sudo'} +) + +--[[ +VIM User interface +--]] + +-- Set 7 lines to the cursor - when moving vertically using j/k +vim.opt.so = 7 + +-- set WildMenu +vim.opt.wildmenu = true + +-- Ignore compiled files +vim.opt.wildignore = '*.o,*~,*.pyc' +vim.opt.wildignore:append('*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store') + +-- Always show current position +vim.opt.ruler = true + +-- Hide buffers when they are abandoned +vim.opt.hid = true + +-- Make backspace function normally +vim.opt.backspace = 'eol,start,indent' +vim.opt.whichwrap:append('<,>,h,l') + +-- Ignore case when searching +vim.opt.ignorecase = true + +-- Be smart about cases when searching +-- If search has uppercases, then we want to respect case +vim.opt.smartcase = true + +-- Highlight search results +vim.opt.hlsearch = true + +-- Make search act like search in modern browsers +vim.opt.incsearch = true + +-- Turn on "magic" for regular expressions +vim.opt.magic = true + +-- Show matching brackets when cursor is over one +vim.opt.showmatch = true +vim.opt.mat = 2 + +-- Turn off annoying bells aon errors +--vim.opt.noerrorbells = false +--vim.opt.novisualbell = false +--vim.opt.t_vb = '' +--vim.opt.tm = 500 + +-- Add extra margin to the left (makes changing margins less annoying +vim.opt.foldcolumn = '1' + +-- Show leader commands +vim.opt.showcmd = true + +-- Show colour column +vim.opt.colorcolumn = '80,120' + +-- => Colors and Fonts + +-- Enable syntac highlighting +vim.opt.syntax = 'enable' + +-- Set utf8 as standard encoding +vim.opt.encoding = 'utf8' + +-- Use Unix as the standard file type +vim.opt.ffs = 'unix,dos,mac' + +--[[ +Files, backups and undo +--]] +vim.opt.swapfile = false + +--[[ +Text, tab and indent related +--]] + +-- Use spaces instead of tabs +vim.opt.expandtab = true + +-- Be smart when using tabs +vim.opt.smarttab = true + +-- 1 tab is 4 spaces +vim.opt.shiftwidth = 4 +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 + +-- Linebreak on 500 ch +vim.opt.lbr = true +vim.opt.tw = 500 + +-- Auto indent +vim.opt.ai = true +-- Smart indent +vim.opt.si = true +-- Wrap lines +vim.opt.wrap = true + +--[[ +Visual mode related +--]] +map('v', '<silent> *', ':<C-u>call VisualSelection("","")<CR>/<C-R>=@/<CR><CR>', silentnoremap) +map('v', '<silent> #', ':<C-u>call VisualSelection("","")<CR>?<C-R>=@/<CR><CR>', silentnoremap) + +--[[ +Moving around, tabs, windows and buffers +--]] +-- Disable highlight when <leader><cr> is pressed +map('n', '<leader><cr>', ':noh<cr>', silentnoremap) + +-- Smart way to move between windows +map('n', '<C-j>', '<C-W>j', silentnoremap) +map('n', '<C-k>', '<C-W>k', silentnoremap) +map('n', '<C-h>', '<C-W>h', silentnoremap) +map('n', '<C-l>', '<C-W>l', silentnoremap) + +-- Close current buffer +map('n', '<leader>bd', ':Bclose<cr>:tabclose<cr>gT', silentnoremap) +-- Close all buffers +map('n', '<leader>ba', ':bufdo bd<cr>', silentnoremap) +-- Navigate buffers +map('n', '<leader>l', ':bnext<cr>', silentnoremap) +map('n', '<leader>h', ':bprevious<cr>', silentnoremap) + +-- Tab commands +map('n', '<leader>tn', ':tabnew<cr>', silentnoremap) +map('n', '<leader>to', ':tabonly<cr>', silentnoremap) +map('n', '<leader>tc', ':tabclose<cr>', silentnoremap) +map('n', '<leader>tm', ':tabmove', silentnoremap) +map('n', '<leader>t<leader>', ':tabnext', silentnoremap) + +-- Switch CWD to directory of the open buffer +map('n', '<leader>cd', ':cd %:p:h<cr>:pwd<cr', silentnoremap) + +-- Behaviour when switching between buffers +vim.opt.switchbuf = 'useopen,usetab,newtab' + +-- Always show tabbar +vim.opt.stal = 2 + +-- Return to last edit position when opening files (You want this!) +vim.cmd [[ + au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif +]] + +-- Make mouse work nice with tmux +vim.opt.mouse = 'a' + +--[[ +Status Line +--]] + +-- Always show status line +vim.opt.laststatus = 2 + +--[[ +Mappings +--]] + +-- Move a line of text using ALT+[jk] +map('n', '<M-j>', 'mz:m+<cr>`z', silentnoremap) +map('n', '<M-k>', 'mz:m-2<cr>`z', silentnoremap) +map('v', '<M-j>', ":m'>+<cr>`<my`>mzgv`yo`z", silentnoremap) +map('v', '<M-k>', ":m'<-2<cr>`>my`<mzgv`yo`z", silentnoremap) + +-- Move line using Command+[jk] on mac +if vim.fn.has("mac") or vim.fn.has("macunix") then + map('n', '<D-j>', '<M-j>', silentnoremap) + map('n', '<D-k>', '<M-k>', silentnoremap) + map('v', '<D-j>', '<M-j>', silentnoremap) + map('v', '<D-k>', '<M-k>', silentnoremap) +end + +-- Delete trailing whitespace on save +vim.api.nvim_create_autocmd("BufWritePre", { + pattern = { "*" }, + command = [[%s/\s\+$//e]] +}) + +--[[ +Misc +--]] + +-- Scribble buffer +map('n', '<leader>q', ':e ~/buffer<cr>', silentnoremap) + +-- Toggle paste mode +map('n', '<leader>pp', ':setlocal paste!<cr>', silentnoremap) + +-- Send file-title to tmux +vim.opt.titlestring = [[%f %h%m%r%w%{v:progname} (%{tabpagenr()} of %{tabpagenr('$')}})]] +vim.opt.title = true + +-- Toggle displaying special characters +vim.keymap.set('n', '<leader><tab>', ToggleListChars, silentnoremap) + +-- Load and save session +map('n', '<leader>sm', ':mksession! vim_session.vim<cr>', silentnoremap) +map('n', '<leader>sl', ':source vim_session.vim<cr>', silentnoremap) + +-- Dont't close window when deleting buffer +--vim.api.nvim_create_user_command("Bclose", +-- "<SID>BufcloseCloseIt()", +-- {bang = true} +--) diff --git a/Common/nvim/lua/helper_functions.lua b/Common/nvim/lua/helper_functions.lua new file mode 100644 index 0000000..cac6c00 --- /dev/null +++ b/Common/nvim/lua/helper_functions.lua @@ -0,0 +1,72 @@ +-- opts that replicate the nore part of noremap +silentnoremap = { noremap = true, silent = true } + +-- Just to make the map function "shorter" +function map(kind, lhs, rhs, opts) + vim.api.nvim_set_keymap(kind, lhs, rhs, opts) +end + +-- True if Paste Mode is enabled +function HasPaste() + return vim.opt.paste:get() and 'PASTE MODE ' or '' +end +vim.api.nvim_create_user_command('HasPaste', HasPaste, {bang=true, desc='Returns a string with PASTE MODE if paste is on.'}) + +-- Toggles wether special characters are visible +list_chars_enabled = false +list_chars_when_enabled = "tab:→ ,space:·,nbsp:␣,trail:•,eol:¶,precedes:«,extends:»" +function ToggleListChars() + list_chars_enabled = not list_chars_enabled + vim.opt.list = list_chars_enabled + vim.opt.listchars = list_chars_enabled and list_chars_when_enabled or 'eol:$' +end + +-- Close buffer without closing window +--[[ +vim.cmd [[ + function! <SID>BufcloseCloseIt() + let l:currentBufNum = bufnr("%") + let l:alternateBufNum = bufnr("#") + + if buflisted(l:alternateBufNum) + buffer # + else + bnext + endif + + if bufnr("%") == l:currentBufNum + new + endif + + if buflisted(l:currentBufNum) + execute("bdelete! ".l:currentBufNum) + endif + endfunction +]] +--]] + +vim.cmd [[ + function! CmdLine(str) + exe "menu Foo.Bar :" . a:str + emenu Foo.Bar + unmenu Foo + endfunction + + + function! VisualSelection(direction, extra_filter) range + let l:saved_reg = @" + execute "normal! vgvy" + + let l:pattern = escape(@", "\\/.*'$^~[]") + let l:pattern = substitute(l:pattern, "\n$", "", "") + + if a:direction == 'gv' + call CmdLine("Ack '" . l:pattern . "' " ) + elseif a:direction == 'replace' + call CmdLine("%s" . '/'. l:pattern . '/') + endif + + let @/ = l:pattern + let @" = l:saved_reg + endfunction +]] diff --git a/Common/nvim/lua/plugins.lua b/Common/nvim/lua/plugins.lua new file mode 100644 index 0000000..43f63a7 --- /dev/null +++ b/Common/nvim/lua/plugins.lua @@ -0,0 +1,25 @@ +-- Autoinstall packer +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 + packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path}) +end + +-- Autocompile packer +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source <afile> | PackerCompile + augroup end +]]) + +return require('packer').startup(function(use) + use 'neovim/nvim-lspconfig' -- Easy LSP configuration + use 'kabouzeid/nvim-lspinstall' -- Install LSP servers on demand with :LSPInstall <name_of_language> + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if packer_bootstrap then + require('packer').sync() + end +end) |