summaryrefslogtreecommitdiffstats
path: root/.config/nvim/lua/mappings.lua
blob: 234f051a94fd6fb906946958cf2b57df27f2d153 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
-- ┌────────────────────────┐
-- │             ▗          │
-- │▛▚▀▖▝▀▖▛▀▖▛▀▖▄ ▛▀▖▞▀▌▞▀▘│
-- │▌▐ ▌▞▀▌▙▄▘▙▄▘▐ ▌ ▌▚▄▌▝▀▖│
-- │▘▝ ▘▝▀▘▌  ▌  ▀▘▘ ▘▗▄▘▀▀ │
-- └────────────────────────┘

-- map helper
local function map(mode, lhs, rhs, opts)
  local options = {noremap = true, silent = true}
  if opts then options = vim.tbl_extend('force', options, opts) end
  vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

local cmd = vim.cmd
local M = {}

-- edit vimrc \ev
map('n', '<leader>ev', ':tabnew<CR>:e ~/.config/nvim/init.lua<CR>')

-- brute force deasciify everything
map('n', '<Leader>tc', 'TurkishDeasciifyForce()', {expr = true})
map('x', '<Leader>tc', 'TurkishDeasciifyForce()', {expr = true})
map('n', '<Leader>tctc', "TurkishDeasciifyForce() .. '_'", {expr = true})

-- use turkish-mode to selectively deasciify
map('n', '<Leader>tr', 'TurkishDeasciify()', {expr = true})
map('x', '<Leader>tr', 'TurkishDeasciify()', {expr = true})
map('n', '<Leader>trtr', "TurkishDeasciify() .. '_'", {expr = true})

-- ascii everything
map('n', '<Leader>rt', 'TurkishAsciify()', {expr = true})
map('x', '<Leader>rt', 'TurkishAsciify()', {expr = true})
map('n', '<Leader>rtrt', "TurkishAsciify() .. '_'", {expr = true})

-- https://stackoverflow.com/questions/4256697/vim-search-and-highlight-but-do-not-jump
-- search & highlight but do not jump
map('n', '*', ':keepjumps normal! mi*`i<CR>')
map('n', '#', ':keepjumps normal! mi#`i<CR> ')

-- save file as sudo on files that require root permission
map('c', 'w!!', 'execute "silent! write !sudo tee % >/dev/null" <bar> edit!')

-- replace ex mode with gq (format lines)
map('n', 'Q', 'gq')

-- set formatprg to sentences, for prose
map('n', '<Leader>fp', ":set formatprg=~/.local/bin/sentences<CR>")

-- replace all is aliased to S.
map('n', 'S', ':%s//g<Left><Left>')

-- if you like "Y" to work from the cursor to the end of line (which is more
-- logical, but not Vi-compatible)
map('n', 'Y', 'y$')

-- jump to buffer
map('n', '<Leader>b', ':ls<cr>:b<space>')

-- up and down are more logical with g..
map('n', 'k', 'gk')
map('n', 'j', 'gj')
map('i', '<Up>', '<Esc>gka')
map('i', '<Down>', '<Esc>gja')

-- disable highlight when <leader><cr> is pressed
map('n', '<Leader><Cr>', ':noh<Cr>')
-- space used to toggle folds, now it's x (because x is d)
map('n', '<Space>', '"_x')

-- separate cut and delete
map('n', 'x', 'd')
map('x', 'x', 'd')
map('n', 'xx', 'dd')
map('n', 'X', 'D')

-- change into pwd of current directory
map('n', '<Leader>cd', ':lcd %:p:h<CR>:pwd<CR>')

-- press \g and start writing prose
map('n', '<Leader>g', ':Goyo<CR>')

-- call CreatePaper on word below cursor
map('n', '<leader>np', 'gewi[[/papers/<ESC>Ea]]<ESC>bb:call CreatePaper(expand("<cword>"))<CR>')

-- link paper
map('n', '<leader>lp', 'gewi[[/papers/<ESC>Ea]]<ESC>')

-- call CreateReference on word below cursor
map('n', '<leader>nr', ':call CreateReference(expand("<cword>"))<CR>')

-- create a new note
map('n', '<leader>nn', ':call CreateNote()<CR>')

vim.cmd("cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'")

-- plug mappings {{{ --

-- <Plug> mappings should not be noremap
-- https://www.reddit.com/r/vim/comments/78izt4/please_help_understand_how_to_use_plug_mapping/
local function plugmap(mode, lhs, rhs, opts)
  local options = {noremap = false, silent = true}
  if opts then options = vim.tbl_extend('force', options, opts) end
  vim.api.nvim_set_keymap(mode, lhs, rhs, options)
end

-- open the TagBar Plugin
plugmap('n', '<F3>', ':TagbarToggle<CR>')

-- sneak using grave, s is for sandwich
plugmap('n', '`', '<Plug>Sneak_s')
plugmap('n', '`', '<Plug>Sneak_s')
plugmap('n', '<Leader>`', '<Plug>Sneak_S')
plugmap('n', "'", '`')

-- use the special yoink paste that rotates
plugmap('n', 'p', '<Plug>(YoinkPaste_p)')
plugmap('n', 'P', '<Plug>(YoinkPaste_P)')

-- substitute from yank
plugmap('n', '<Leader>ys', '<plug>(SubversiveSubstitute)')
plugmap('n', '<Leader>yss', '<plug>(SubversiveSubstituteLine)')
plugmap('n', '<Leader>yS', '<plug>(SubversiveSubstituteToEndOfLine)')

-- substitute over range
plugmap('n', '<Leader>s', '<plug>(SubversiveSubstituteRange)')
plugmap('x', '<Leader>s', '<plug>(SubversiveSubstituteRange)')
plugmap('n', '<Leader>ss', '<plug>(SubversiveSubstituteWordRange)')

-- subvert over range
plugmap('n', '<Leader><Leader>s', '<plug>(SubversiveSubvertRange)')
plugmap('x', '<Leader><Leader>s', '<plug>(SubversiveSubvertRange)')
plugmap('n', '<Leader><Leader>ss', '<plug>(SubversiveSubvertWordRange)')

-- iterate over yank list
plugmap('n', '<c-n>', '<Plug>(YoinkPostPasteSwapBack)')
plugmap('n', '<c-p>', '<Plug>(YoinkPostPasteSwapForward)')

-- checkmarks on vimwiki
plugmap('n', '<leader>v', '<Plug>VimwikiToggleListItem')
-- add/increase header level
plugmap('n', '<leader>a', '<Plug>VimwikiAddHeaderLevel')

-- vim-test bindings
map('n', 't<C-n>', ':TestNearest<CR>')
map('n', 't<C-f>', ':TestFile<CR>')
map('n', 't<C-s>', ':TestSuite<CR>')
map('n', 't<C-l>', ':TestLast<CR>')
map('n', 't<C-g>', ':TestVisit<CR>')

-- telescope bindings
map('n', '<leader>ff', "<cmd>lua require('telescope.builtin').find_files()<cr>")
map('n', '<leader>fg', "<cmd>lua require('telescope.builtin').live_grep()<cr>")
map('n', '<leader>fb', "<cmd>lua require('telescope.builtin').buffers()<cr>")
map('n', '<leader>fh', "<cmd>lua require('telescope.builtin').help_tags()<cr>")

-- vista
map('n', '<F3>', ":Vista focus<cr>")
map('n', '<F4>', ":Vista finder<cr>")

-- dashboard
map('n', '<Leader>fh', ':DashboardFindHistory<CR>')
map('n', '<Leader>ff', ':DashboardFindFile<CR>')
map('n', '<Leader>fa', ':DashboardFindWord<CR>')
map('n', '<Leader>fb', ':DashboardJumpMark<CR>')
map('n', '<Leader>cn', ':DashboardNewFile<CR>')

-- toggle rose pine theme
map('n', 'cz', [[<cmd>lua require('rose-pine.functions').toggle_variant({'dawn', 'base'})<cr>]], { noremap = true, silent = true })

map('n', 'vt', ':NvimTreeToggle<CR>')
map('n', 'vr', ':NvimTreeRefresh<CR>')
map('n', 'vs', ':NvimTreeFindFile<CR>')

-- }}} plug mappings --